123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225(* Yoann Padioleau
*
* Copyright (C) 2009 Yoann Padioleau
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation, with the
* special exception on linking described in file license.txt.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
* license.txt for more details.
*)openCommon(*****************************************************************************)(* Commands *)(*****************************************************************************)(* ex:
1.3 (pjd 30-Dec-05): extern u_int vm_memguard_divisor;
*)letannotate_regexp="^\\([0-9]+\\(\\.[0-9]+\\)+\\)"^"[ \t]+"^"(\\([^ \t]+\\)"^"[ \t]+"^"\\([0-9]+\\)"^"-"^"\\([A-Za-z]+\\)"^"-"^"\\([0-9]+\\)"^"):"^".*$"(* the rest is line of code *)(*
let _ = assert ("1.208 (imp 07-Jan-05): /*-" =~ annotate_regexp)
*)letannotate2?(basedir="")filename=lettoday=Common2.today()inletdmy=today|>Common2.floattime_to_unixtime|>Common2.unixtime_to_dmyinlet(Common2.DMY(_,_,Common2.Yearthis_year))=dmyin(* TODO????: compute it from file directly ? *)(* ??? let date = "-D \"12 Feb\"" in *)letdate="-D \"1 Sep\""inCommon.pr2_once("using Date for CVS:"^date);(* bugfix: for eclipse files can have space and $ in filename *)letcmd=spf"%s cvs annotate %s '%s' 2>&1"(Lib_vcs.goto_dirbasedir)datefilenamein(* pr2 cmd; *)letxs=Common.cmd_to_listcmdin(* have to get rid of header
Annotations for memguard.h
***************
*)(*let ys = Common.cat (Common.filename_of_db (basedir,filename)) in*)letannots=xs|>Common.map_filter(funs->match()with|()whens=~annotate_regexp->let(rcsid,_,author,day,month_str,year)=Common.matched6sin(* 05 -> 2005 or 93 -> 1993 *)letiyear=s_to_iyearinletiyear=ifiyear<60theniyear+2000elseiyear+1900inassert(iyear<=this_year);Some(Lib_vcs.VersionIdrcsid,Lib_vcs.Authorauthor,Common2.mk_date_dmy(s_to_iday)(Common2.int_of_month(Common2.month_of_stringmonth_str))iyear)(* header *)|()whens="***************"->None|()whens=~"^Annotations for.*"->None|_->pr2("cvs annotate wrong line: "^s);None)in(* files lines are 1_based, so add this dummy 0 entry *)Array.of_list(Lib_vcs.dummy_annotation::annots)letannotate?basedira=Common.profile_code"Cvs.annotate"(fun()->annotate2?basedira)(* ------------------------------------------------------------------------ *)letannotate_raw?(basedir="")filename=letdate="-D \"12 Feb\""inletcmd=spf"%s cvs annotate %s '%s' 2>&1"(Lib_vcs.goto_dirbasedir)datefilenamein(* pr2 cmd; *)letxs=Common.cmd_to_listcmdin(* have to get rid of header
Annotations for memguard.h
***************
*)(*let ys = Common.cat (Common.filename_of_db (basedir,filename)) in*)letannots=xs|>Common.map_filter(funs->ifs=~annotate_regexpthenSomeselsebegin(* pr2 ("cvs annotate wrong line: " ^ s); *)Noneend)in(* files lines are 1_based, so add this dummy 0 entry *)Array.of_list(""::annots)(* ------------------------------------------------------------------------ *)(* ex:
date: 2005/01/21 18:09:17; author: bmilekic; state: Exp;
*)letdate_regexp="date: "^"\\([0-9]+\\)"^"/"^(* year *)"\\([0-9]+\\)"^"/"^(* month *)"\\([0-9]+\\)"^" "^(* day *)".*"(* eclipse have this format, wierd cos both use cvs *)letdate_regexp2="date: "^"\\([0-9]+\\)"^"-"^(* year *)"\\([0-9]+\\)"^"-"^(* month *)"\\([0-9]+\\)"^" "^(* day *)".*"letfind_all_datecmd=letxs=Common.cmd_to_listcmdin(*todo: use find_some *)letxs'=xs|>Common.map_filter(funs->ifs=~date_regexpthenlet(year,month,day)=matched3sinSome(Common2.mk_date_dmy(s_to_iday)(s_to_imonth)(s_to_iyear))elseifs=~date_regexp2thenlet(year,month,day)=matched3sinSome(Common2.mk_date_dmy(s_to_iday)(s_to_imonth)(s_to_iyear))elseNone)inxs'letfind_datecmd=letxs'=find_all_datecmdinmatchxs'with|x::_xs->Somex|[]->Noneletfind_date_mincmd=letxs'=find_all_datecmdinmatchxs'with|x::xs->Some(Common2.minimum_dmy(x::xs))|[]->Noneletdate_file_creation2?(basedir="")file=letcmd=spf"%s cvs log -r1.1 '%s' 2>&1"(Lib_vcs.goto_dirbasedir)fileinletcmd2=spf"%s cvs log -r1.2 '%s' 2>&1"(Lib_vcs.goto_dirbasedir)fileinletcmd_alt=spf"%s cvs log '%s' 2>&1"(Lib_vcs.goto_dirbasedir)fileinmatchfind_datecmdwith|Somex->x|None->pr2("wierd: cvs cant find date revision 1.1");(matchfind_datecmd2with|Somex->x|None->pr2("PB: cvs cant find date revision 1.1 or 1.2");(matchfind_date_mincmd_altwith|Somex->x|None->failwith("PB: cvs cant find any file date ");))letdate_file_creation?basedira=Common.profile_code"cvs.date_file"(fun()->date_file_creation2?basedira)(*****************************************************************************)