Anonymous avatar Anonymous committed 0a1bf04 Draft

respecting mercurial -r/-b for caching purposes

Comments (0)

Files changed (1)

src/pre_template.ml

         lst
   end
 
+
+type rev_spec = [ `Tip | `Branch of string | `Rev of string ]
+
 module Source
  :
   sig
     val none : source
-    val hg : ?rev:string -> string -> source
+
+    val hg : ?rev:rev_spec -> string -> source
+
     val local_tar_gz : string -> source
     val local_tar_bz2 : string -> source
     val local_dir : string -> source
         post
 
 
-    let hg ?(rev="tip") repo =
+    let hg ?(rev=`Tip) repo =
+      let rev_txt =
+        match rev with
+        | `Tip -> "tip"
+        | `Branch n -> Printf.sprintf "branch %S" n
+        | `Rev n -> Printf.sprintf "revision %S" n
+      in
       let clone ~workcopy ~src ~dest =
            let argv = Array.of_list
-             ( [ "hg" ; "clone" ; "-r" ; rev ]
+             ( [ "hg" ; "clone" ]
+             @ (match rev with
+                | `Tip -> []
+                | `Branch n -> [ "-b" ; n ]
+                | `Rev n -> [ "-r" ; n ]
+               )
              @ (if workcopy
                 then []
                 else [ "--noupdate" ]
                )
              in
                dest
-           else failwith "can't clone mercurial repository with command %s"
-                  (Reb_sys.dump_argv argv)
+           else
+             failwith "can't clone mercurial repository with command %s"
+               (Reb_sys.dump_argv argv)
       in
       { s_download =
          (if is_local repo
                    { rr_pull =
                        (fun () ->
                           0 = Reb_sys.run ~show:true
-                            [| "hg" ; "pull" |]
-                            (* todo: add rev/branch *)
+                            (Array.of_list
+                               ( [ "hg" ; "pull" ]
+                               @ (match rev with
+                                  | `Tip -> []
+                                  | `Rev n -> [ "-r" ; n ]
+                                  | `Branch n -> [ "-b" ; n ]
+                                 )
+                               )
+                            )
                        )
                    }
                 )
               ,
                 (fun ~dl_dest ->
-                   let () = dbg "Source.hg: download: cloning %S (rev %S) \
+                   let () = dbg "Source.hg: download: cloning %S (%S) \
                                  to %S without workcopy"
-                     repo rev dl_dest
+                     repo rev_txt dl_dest
                    in
                    clone ~src:repo ~dest:dl_dest ~workcopy:false
                 )
              then
                Reb_sys.with_chdir dest
                  (fun () ->
-                    ( dbg "Source.hg: extract: updating to revision %S \
+                    ( dbg "Source.hg: extract: updating to %S \
                            inplace (pwd = %S)"
-                          rev (Sys.getcwd ())
+                          rev_txt (Sys.getcwd ())
                     ; Reb_sys.run_ok ~show:true [| "hg" ; "update" |]
                     ; dest
                     )
                  )
              else
-               ( dbg "Source.hg: extract: fair cloning %S (rev %S) to %S"
-                   path rev dest
+               ( dbg "Source.hg: extract: fair cloning %S (%S) to %S"
+                   path rev_txt dest
                ; clone ~src:path ~dest ~workcopy:true
                )
           )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.