12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182(* Yoann Padioleau
*
* Copyright (C) 2013 Facebook
*
* 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.
*)openCommonmoduleVC=Version_control(*****************************************************************************)(* Prelude *)(*****************************************************************************)(*
* Generic interface on top of Git and Mercurial.
* Could also use first class module or just plain records, but classes
* seems a good fit for this.
*)(*****************************************************************************)(* Types *)(*****************************************************************************)classtypevcs=objectmethodbasedir:stringmethodgrep:string->Common.filenamelistmethodshow:Common.filename->Lib_vcs.versionid->Common.filenamemethodfiles_involved_in_diff:Lib_vcs.versionid->(Lib_vcs.file_commit_status*Common.filename)listend(*****************************************************************************)(* Instances *)(*****************************************************************************)(* could define also classes instead of immediate objects *)letgit~basedir=(objectmethodbasedir=basedirmethodgreps=Git.grep~basedirsmethodshowfilecommitid=Git.show~basedirfilecommitidmethodfiles_involved_in_diffcommitid=Git.files_involved_in_diff~basedircommitidend:vcs)lethg~basedir=(objectmethodbasedir=basedirmethodgreps=Mercurial.grep~basedirsmethodshowfilecommitid=Mercurial.show~basedirfilecommitidmethodfiles_involved_in_diffcommitid=Mercurial.files_involved_in_diff~basedircommitidend:vcs)(*****************************************************************************)(* Builder *)(*****************************************************************************)(* infer from basedir *)letmk_vcs~basedir=matchVersion_control.detect_vcs_source_treebasedirwith|SomeVC.Git->git~basedir|SomeVC.Mercurial->hg~basedir|Somex->failwith(spf"generic vcs interface not supported for %s"(VC.string_of_vcs_kindx))|None->failwith(spf"could not detect any VCS in directory %s"basedir)