package pfff

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file generic_vcs.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
(* 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.
 *)
open Common

module VC = 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 *)
(*****************************************************************************)

class type vcs = object
method basedir: string

method grep: string -> Common.filename list
method show: Common.filename -> Lib_vcs.versionid -> Common.filename
method files_involved_in_diff: Lib_vcs.versionid -> 
  (Lib_vcs.file_commit_status * Common.filename) list
end 

(*****************************************************************************)
(* Instances *)
(*****************************************************************************)

(* could define also classes instead of immediate objects *)
let git ~basedir = 
 (object 
   method basedir = basedir
   method grep s =
     Git.grep ~basedir s
   method show file commitid = 
     Git.show ~basedir file commitid
   method files_involved_in_diff commitid = 
     Git.files_involved_in_diff ~basedir commitid
  end : vcs)

let hg ~basedir =
 (object 
   method basedir = basedir
   method grep s =
     Mercurial.grep ~basedir s
   method show file commitid = 
     Mercurial.show ~basedir file commitid
   method files_involved_in_diff commitid = 
     Mercurial.files_involved_in_diff ~basedir commitid
  end : vcs)

(*****************************************************************************)
(* Builder *)
(*****************************************************************************)

(* infer from basedir *)
let mk_vcs ~basedir =
  match Version_control.detect_vcs_source_tree basedir with
  | Some VC.Git -> git ~basedir
  | Some VC.Mercurial -> hg ~basedir
  | Some x -> 
    failwith (spf "generic vcs interface not supported for %s"
                (VC.string_of_vcs_kind x))
  | None -> 
    failwith (spf "could not detect any VCS in directory %s" basedir)

OCaml

Innovation. Community. Security.