123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138(* 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.
*)openCommonmoduleDate=Common2(*****************************************************************************)(* Types *)(*****************************************************************************)typeversionid=VersionIdofstring(* a SHA1 code in hexa, or RCS version *)typeauthor=Authorofstring(* could also add author *)typeline_annotation=versionid*author*Common2.date_dmytypecommit_patch=(stringlist)(* header *)*Patch.patchinfo(* see man git-diff and the "diff-filter section" *)typefile_commit_status=|Added|Copied|Deleted|Modified|Renamedofint(* probability of rename *)*Common.filename(* original filename *)|FileTypeChanged|Unmerged|Unknown|Broken(*****************************************************************************)(* Helpers *)(*****************************************************************************)letgoto_dirbasedir=ifbasedir=""then""elsespf"cd \"%s\"; "basedirletdummy_annotation=VersionId"dummy",Author"dummy",(Date.DMY(Date.Day1,Date.Jan,Date.Year1977))lets_of_versionid(VersionIds)=sletparse_commit_patchxs=trylet(before,x,after)=Common2.split_when(funl->l=~"^diff.*")xsinbefore,(Patch.parse_patch(x::after))withNot_found->(* for merge commit, have this:
* ["commit 6d27fd0f1eb56184011683530c224f90490f45c7";
* "Merge: 6677406... a9e8879...";
* "Author: pad <pad@facebook.com>"; "Date: 6 weeks ago"; "";
* " Merge branch 'master' of /home/pad/release/pfff-git"; ""]
*)ifxs|>List.exists(funs->s=~".*Merge.*")thenxs,[]elsefailwith("wrong commit:"^List.hdxs)letspecial_vcs_dirs=[".git";".svn";".hg";"CVS";"_darcs"]letfilter_vcs_dir2dir=(* dont care about VCS files *)letlast=Filename.basenamedirinnot(List.memlastspecial_vcs_dirs)letfilter_vcs_dirx=Common.profile_code"Lib_vcs.filter_dir"(fun()->filter_vcs_dir2x)(* See man git-diff and the "diff-filter section".
* Could be in git.ml, but this look quite generic.
*)letparse_file_statuss=matchswith|_whens=~"\\([MADCTUXBR]\\)[ \t]+\\([^ \t]+\\)"->let(status,name)=Common.matched2sin(* coupling: if you add case below, don't forget to update the regexp
* above accordingly.
*)(matchstatuswith(* git and mercurial *)|"A"->Added|"M"->Modified(* git only *)|"D"->Deleted|"C"->Copied|"T"->FileTypeChanged|"U"->Unmerged|"X"->Unknown|"B"->Broken(* mercurial *)|"R"->Deleted(* todo: mercurial has also those flags but they should not appear
* when one look for the status of a change (e.g. hg status --change .)
* '?': Mercurial doesn't know about this file, and has not been
* configured to ignore it
* '!': Mercurial is tracking this file, but it's missing - perhaps
* you've deleted it without telling Mercurial to stop tracking it.
*)|_->failwith(spf"unknown file commit status: %s"status)),name|_whens=~"R\\([0-9]+\\)[ \t]+\\([^ \t]+\\)[ \t]+\\([^ \t]+\\)"->let(proba,src,target)=Common.matched3sinRenamed(int_of_stringproba,src),target|_whens=~"MM[ \t]+\\([^ \t]+\\)"->letname=Common.matched1sin(* todo? really that? look 61be1edbf71adbbb6bd07fe451b7639df72c004b in
* facebook repo. Seems to be when modified in a merge-branch commit.
*)Modified,name|_->failwith(spf"wrong format in file commit status: %s"s)