diff --git a/examples/deploy.ml b/examples/deploy.ml index b46af23c84e..24b55104e78 100644 --- a/examples/deploy.ml +++ b/examples/deploy.ml @@ -2,7 +2,7 @@ open Lwt.Infix module Store = Irmin_unix.Git.FS.KV (Irmin.Contents.String) let config = - let head = Store.Git.Reference.of_string "refs/heads/upstream" in + let head = Git.Reference.v "refs/heads/upstream" in Irmin_git.config ~head ~bare:false Config.root let info ~user msg () = diff --git a/examples/process.ml b/examples/process.ml index 4387d11668c..246f9d23495 100644 --- a/examples/process.ml +++ b/examples/process.ml @@ -88,7 +88,7 @@ let images = [| (*ubuntu; *) wordpress; mysql |] module Store = Irmin_unix.Git.FS.KV (Irmin.Contents.String) -let head = Store.Git.Reference.of_string ("refs/heads/" ^ branch images.(0)) +let head = Git.Reference.v ("refs/heads/" ^ branch images.(0)) let config = Irmin_git.config ~bare:true ~head Config.root diff --git a/irmin-git.opam b/irmin-git.opam index 5631e97d994..0a12d043ca3 100644 --- a/irmin-git.opam +++ b/irmin-git.opam @@ -18,7 +18,7 @@ depends: [ "dune" {>= "2.7.0"} "irmin" {= version} "ppx_irmin" {= version} - "git" {>= "2.1.1"} + "git" "digestif" {>= "0.9.0"} "cstruct" "fmt" @@ -29,7 +29,7 @@ depends: [ "uri" "irmin-test" {with-test & = version} "irmin-mem" {with-test & = version} - "git-unix" {with-test & >= "2.1.1"} + "git-unix" {with-test} "mtime" {with-test & >= "1.0.0"} "alcotest" {with-test} ] @@ -39,3 +39,17 @@ description: """ `Irmin_git` expose a bi-directional bridge between Git repositories and Irmin stores. """ + +pin-depends: [ + [ "git.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-nss.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-cohttp.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-cohttp-unix.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-unix.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton-git.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton-lwt.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "mimic.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "awa.dev" "git+https://github.com/mirage/awa-ssh.git#c337fbac71e3699ba4bcefe9382c9842354b3bee" ] + [ "awa-mirage.dev" "git+https://github.com/mirage/awa-ssh.git#c337fbac71e3699ba4bcefe9382c9842354b3bee" ] +] diff --git a/irmin-graphql.opam b/irmin-graphql.opam index d54a2955494..f4d9b905490 100644 --- a/irmin-graphql.opam +++ b/irmin-graphql.opam @@ -25,6 +25,7 @@ depends: [ "cohttp" "fmt" "lwt" + "mimic" "irmin-mem" {with-test & = version} "alcotest-lwt" {with-test & >= "1.1.0"} "yojson" {with-test} diff --git a/irmin-http.opam b/irmin-http.opam index dcc69633102..9391d9ad585 100644 --- a/irmin-http.opam +++ b/irmin-http.opam @@ -28,11 +28,26 @@ depends: [ "logs" "lwt" "uri" + "conduit" {>= "2.1.0"} "irmin-git" {with-test & = version} "irmin-mem" {with-test & = version} "irmin-test" {with-test & = version} - "git-unix" {with-test} + "git-unix" "digestif" {with-test & >= "0.9.0"} ] synopsis: "HTTP client and server for Irmin" + +pin-depends: [ + [ "git.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-nss.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-cohttp.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-cohttp-unix.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-unix.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton-git.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton-lwt.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "mimic.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "awa.dev" "git+https://github.com/mirage/awa-ssh.git#c337fbac71e3699ba4bcefe9382c9842354b3bee" ] + [ "awa-mirage.dev" "git+https://github.com/mirage/awa-ssh.git#c337fbac71e3699ba4bcefe9382c9842354b3bee" ] +] diff --git a/irmin-mirage-git.opam b/irmin-mirage-git.opam index 155720e13a7..579a5749782 100644 --- a/irmin-mirage-git.opam +++ b/irmin-mirage-git.opam @@ -16,11 +16,11 @@ depends: [ "dune" {>= "2.7.0"} "irmin-mirage" {= version} "irmin-git" {= version} - "git-mirage" {>= "2.1.2"} "mirage-kv" {>= "3.0.0"} "cohttp" "conduit-lwt" "conduit-mirage" + "git-cohttp-mirage" "fmt" "git" "lwt" @@ -29,3 +29,13 @@ depends: [ ] synopsis: "MirageOS-compatible Irmin stores" + +pin-depends: [ + [ "git.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-nss.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-cohttp-mirage.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton-git.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton-lwt.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "mimic.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] +] diff --git a/irmin-mirage-graphql.opam b/irmin-mirage-graphql.opam index e8736caa5fe..0dfbfb207e0 100644 --- a/irmin-mirage-graphql.opam +++ b/irmin-mirage-graphql.opam @@ -16,11 +16,20 @@ depends: [ "dune" {>= "2.7.0"} "irmin-mirage" {= version} "irmin-graphql" {= version} - "git-mirage" {>= "2.1.1"} "mirage-clock" "cohttp-lwt" "lwt" "uri" + "git" ] synopsis: "MirageOS-compatible Irmin stores" + +pin-depends: [ + [ "git.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-nss.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton-git.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton-lwt.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "mimic.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] +] diff --git a/irmin-unix.opam b/irmin-unix.opam index 95dbb579169..3c8b3f04477 100644 --- a/irmin-unix.opam +++ b/irmin-unix.opam @@ -32,6 +32,7 @@ depends: [ "astring" "cohttp" "cohttp-lwt" + "cohttp-lwt-unix" "conduit" "conduit-lwt" "conduit-lwt-unix" @@ -41,6 +42,7 @@ depends: [ "cohttp-lwt-unix" "fmt" "git" + "git-cohttp-unix" "lwt" "irmin-test" {with-test & = version} "alcotest" {with-test} @@ -52,3 +54,17 @@ description: """ as a very simple CLI tool (called `irmin`) to manipulate and inspect Irmin stores. """ + +pin-depends: [ + [ "git.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-nss.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-cohttp.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-cohttp-unix.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "git-unix.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton-git.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "carton-lwt.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "mimic.dev" "git+https://github.com/mirage/ocaml-git.git#57853042cc14e4f414380c2c33a007d275307962" ] + [ "awa.dev" "git+https://github.com/mirage/awa-ssh.git#c337fbac71e3699ba4bcefe9382c9842354b3bee" ] + [ "awa-mirage.dev" "git+https://github.com/mirage/awa-ssh.git#c337fbac71e3699ba4bcefe9382c9842354b3bee" ] +] diff --git a/src/irmin-git/irmin_git.ml b/src/irmin-git/irmin_git.ml index 4cca4f1bf50..2315784ddbe 100644 --- a/src/irmin-git/irmin_git.ml +++ b/src/irmin-git/irmin_git.ml @@ -45,7 +45,7 @@ module Conf = struct let root = Irmin.Private.Conf.root let reference = - let parse str = Ok (Git.Reference.of_string str) in + let parse str = Git.Reference.of_string str in let print ppf name = Fmt.string ppf (Git.Reference.to_string name) in (parse, print) @@ -129,14 +129,14 @@ struct | false -> Lwt.return_false | true -> ( G.read t key >>= function - | Error `Not_found -> Lwt.return_false + | Error (`Reference_not_found _ | `Not_found _) -> Lwt.return_false | Error e -> Fmt.kstrf Lwt.fail_with "%a" G.pp_error e | Ok v -> Lwt.return (V.type_eq (G.Value.kind v))) let find t key = Log.debug (fun l -> l "find %a" pp_key key); G.read t key >>= function - | Error `Not_found -> Lwt.return_none + | Error (`Reference_not_found _ | `Not_found _) -> Lwt.return_none | Error e -> Fmt.kstrf Lwt.fail_with "%a" G.pp_error e | Ok v -> Lwt.return (V.of_git v) @@ -161,7 +161,7 @@ struct Lwt_mutex.with_lock reset_lock (fun () -> G.reset t) >>= handle_git_err end) - module Raw = Git.Value.Raw (G.Hash) (G.Inflate) (G.Deflate) + module Raw = Git.Value.Make (G.Hash) module XContents = struct module GitContents = struct @@ -170,7 +170,7 @@ struct let type_eq = function `Blob -> true | _ -> false let of_git = function - | G.Value.Blob b -> ( + | Git.Value.Blob b -> ( let str = G.Value.Blob.to_string b in match Irmin.Type.of_string C.t str with | Ok x -> Some x @@ -187,25 +187,19 @@ struct module Val = struct include C - let to_bin t = - let raw, etmp = (Cstruct.create 0x100, Cstruct.create 0x100) in - match Raw.to_raw ~raw ~etmp (GitContents.to_git t) with - | Error _ -> assert false - | Ok s -> s + let to_bin t = Raw.to_raw (GitContents.to_git t) let encode_bin = Irmin.Type.stage (fun (t : t) k -> k (to_bin t)) let decode_bin = Irmin.Type.stage @@ fun buf off -> Log.debug (fun l -> l "Content.decode_bin"); - let buf = Cstruct.of_string buf in - let buf = Cstruct.shift buf off in - match Raw.of_raw_with_header buf with + match Raw.of_raw_with_header ~off buf with | Ok g -> ( match GitContents.of_git g with - | Some g -> (off + Cstruct.len buf, g) + | Some g -> (String.length buf, g) | None -> failwith "wrong object kind") - | Error e -> Fmt.invalid_arg "error %a" Raw.DecoderRaw.pp_error e + | Error (`Msg _) -> failwith "wrong object" let size_of = Irmin.Type.stage (fun _ -> None) @@ -246,7 +240,7 @@ struct let list t = List.fold_left - (fun acc { G.Value.Tree.perm; name; node } -> + (fun acc { Git.Tree.perm; name; node } -> let name = to_step name in match perm with | `Dir -> (name, `Node node) :: acc @@ -259,14 +253,14 @@ struct let s = of_step s in let rec aux = function | [] -> None - | x :: xs when x.G.Value.Tree.name <> s -> aux xs - | { G.Value.Tree.perm; node; _ } :: _ -> ( + | x :: xs when x.Git.Tree.name <> s -> aux xs + | { Git.Tree.perm; node; _ } :: _ -> ( match perm with | `Dir -> Some (`Node node) | `Commit -> None (* FIXME *) | #Metadata.t as p -> Some (`Contents (node, p))) in - aux (G.Value.Tree.to_list t) + aux (Git.Tree.to_list t) let remove t step = G.Value.Tree.remove ~name:(of_step step) t @@ -276,30 +270,31 @@ struct let name = of_step name in let entry = match value with - | `Node node -> G.Value.Tree.entry name `Dir node + | `Node node -> Git.Tree.entry ~name `Dir node | `Contents (node, perm) -> - G.Value.Tree.entry name (perm :> G.Value.Tree.perm) node + Git.Tree.entry ~name (perm :> Git.Tree.perm) node in (* FIXME(samoht): issue in G.Value.Tree.add *) let entries = G.Value.Tree.to_list t in - match List.find (fun e -> e.G.Value.Tree.name = name) entries with - | exception Not_found -> G.Value.Tree.of_list (entry :: entries) + match List.find (fun e -> e.Git.Tree.name = name) entries with + | exception Not_found -> Git.Tree.of_list (entry :: entries) | e -> let equal x y = - x.G.Value.Tree.perm = y.G.Value.Tree.perm + x.Git.Tree.perm = y.Git.Tree.perm && x.name = y.name && G.Hash.equal x.node y.node in if equal e entry then t else let entries = - List.filter (fun e -> e.G.Value.Tree.name <> name) entries + List.filter (fun e -> e.Git.Tree.name <> name) entries in - G.Value.Tree.of_list (entry :: entries) + Git.Tree.of_list (entry :: entries) - let empty = G.Value.Tree.of_list [] + let empty = Git.Tree.of_list [] - let to_git perm (name, node) = G.Value.Tree.entry (of_step name) perm node + let to_git perm (name, node) = + G.Value.Tree.entry ~name:(of_step name) perm node let v alist = let alist = @@ -308,7 +303,7 @@ struct let v k = (l, k) in match x with | `Node n -> to_git `Dir (v n) - | `Contents (c, perm) -> to_git (perm :> G.Value.Tree.perm) (v c)) + | `Contents (c, perm) -> to_git (perm :> Git.Tree.perm) (v c)) alist in (* Tree.of_list will sort the list in the right order *) @@ -319,14 +314,14 @@ struct let mk_c k metadata = `Contents (k, metadata) in List.fold_left (fun acc -> function - | { G.Value.Tree.perm = `Dir; name; node } -> + | { Git.Tree.perm = `Dir; name; node } -> (to_step name, mk_n node) :: acc - | { G.Value.Tree.perm = `Commit; name; _ } -> + | { Git.Tree.perm = `Commit; name; _ } -> (* Irmin does not support Git submodules; do not follow them, just consider *) Log.warn (fun l -> l "skipping Git submodule: %s" name); acc - | { G.Value.Tree.perm = #Metadata.t as perm; name; node; _ } -> + | { Git.Tree.perm = #Metadata.t as perm; name; node; _ } -> (to_step name, mk_c node perm) :: acc) [] (G.Value.Tree.to_list t) |> List.rev @@ -337,11 +332,7 @@ struct let of_n n = v (N.list n) - let to_bin t = - let raw, etmp = (Cstruct.create 0x100, Cstruct.create 0x100) in - match Raw.to_raw ~raw ~etmp (G.Value.tree t) with - | Error _ -> assert false - | Ok s -> s + let to_bin t = Raw.to_raw (G.Value.tree t) let encode_bin = Irmin.Type.stage @@ fun (t : t) k -> @@ -351,12 +342,10 @@ struct let decode_bin = Irmin.Type.stage @@ fun buf off -> Log.debug (fun l -> l "Tree.decode_bin"); - let buf = Cstruct.of_string buf in - let buf = Cstruct.shift buf off in - match Raw.of_raw_with_header buf with - | Ok (G.Value.Tree t) -> (off + Cstruct.len buf, t) + match Raw.of_raw_with_header buf ~off with + | Ok (Git.Value.Tree t) -> (String.length buf, t) | Ok _ -> failwith "wrong object kind" - | Error e -> Fmt.invalid_arg "error %a" Raw.DecoderRaw.pp_error e + | Error _ -> failwith "wrong object" let size_of = Irmin.Type.stage (fun _ -> None) @@ -371,7 +360,7 @@ struct let to_git t = G.Value.tree t - let of_git = function G.Value.Tree t -> Some t | _ -> None + let of_git = function Git.Value.Tree t -> Some t | _ -> None end) end @@ -452,11 +441,7 @@ struct let info, node, parents = of_git t in C.v ~info ~node ~parents - let to_bin t = - let raw, etmp = (Cstruct.create 0x100, Cstruct.create 0x100) in - match Raw.to_raw ~raw ~etmp (G.Value.commit t) with - | Error _ -> assert false - | Ok s -> s + let to_bin t = Raw.to_raw (G.Value.commit t) let encode_bin = Irmin.Type.stage @@ fun (t : t) k -> @@ -466,12 +451,10 @@ struct let decode_bin = Irmin.Type.stage @@ fun buf off -> Log.debug (fun l -> l "Commit.decode_bin"); - let buf = Cstruct.of_string buf in - let buf = Cstruct.shift buf off in - match Raw.of_raw_with_header buf with - | Ok (G.Value.Commit t) -> (off + Cstruct.len buf, t) + match Raw.of_raw_with_header ~off buf with + | Ok (Git.Value.Commit t) -> (String.length buf, t) | Ok _ -> failwith "wrong object kind" - | Error e -> Fmt.invalid_arg "error %a" Raw.DecoderRaw.pp_error e + | Error _ -> failwith "wrong object kind" let size_of = Irmin.Type.stage (fun _ -> None) @@ -486,7 +469,7 @@ struct let type_eq = function `Commit -> true | _ -> false - let of_git = function G.Value.Commit c -> Some c | _ -> None + let of_git = function Git.Value.Commit c -> Some c | _ -> None let to_git c = G.Value.commit c end) @@ -553,7 +536,7 @@ functor type t = { bare : bool; dot_git : Fpath.t; - git_head : G.Reference.head_contents; + git_head : G.Hash.t Git.Reference.contents; t : G.t; w : W.t; m : Lwt_mutex.t; @@ -568,10 +551,10 @@ functor type watch = W.watch * (unit -> unit Lwt.t) let branch_of_git r = - let str = String.trim @@ G.Reference.to_string r in + let str = String.trim @@ Git.Reference.to_string r in match B.of_ref str with Ok r -> Some r | Error (`Msg _) -> None - let git_of_branch r = G.Reference.of_string (Fmt.to_to_string B.pp_ref r) + let git_of_branch r = Git.Reference.v (Fmt.to_to_string B.pp_ref r) let pp_key = Irmin.Type.pp Key.t @@ -582,7 +565,7 @@ functor let find { t; _ } r = Log.debug (fun l -> l "find %a" pp_key r); G.Ref.resolve t (git_of_branch r) >>= function - | Error `Not_found -> Lwt.return_none + | Error (`Reference_not_found _) -> Lwt.return_none | Error e -> Fmt.kstrf Lwt.fail_with "%a" G.pp_error e | Ok k -> Lwt.return_some k @@ -616,9 +599,10 @@ functor let m = match lock with None -> Lwt_mutex.create () | Some l -> l in let dot_git = G.dotgit t in let write_head head = - let head = G.Reference.Ref head in + let head = Git.Reference.Ref head in ((if G.has_global_checkout then - Lwt_mutex.with_lock m (fun () -> G.Ref.write t G.Reference.head head) + Lwt_mutex.with_lock m (fun () -> + G.Ref.write t Git.Reference.head head) else Lwt.return (Ok ())) >|= function | Error e -> Log.err (fun l -> l "Cannot create HEAD: %a" G.pp_error e) @@ -628,8 +612,9 @@ functor (match head with | Some h -> write_head h | None -> ( - G.Ref.read t G.Reference.head >>= function - | Error `Not_found -> write_head (git_of_branch B.master) + G.Ref.read t Git.Reference.head >>= function + | Error (`Reference_not_found _ | `Not_found _) -> + write_head (git_of_branch B.master) | Error e -> Fmt.kstrf Lwt.fail_with "%a" G.pp_error e | Ok r -> Lwt.return r)) >|= fun git_head -> @@ -653,11 +638,11 @@ functor let write_index t gr gk = Log.debug (fun l -> l "write_index"); if G.has_global_checkout then Log.debug (fun f -> f "write_index"); - let git_head = G.Reference.Ref gr in + let git_head = Git.Reference.Ref gr in Log.debug (fun f -> - f "write_index/if bare=%b head=%a" t.bare G.Reference.pp gr); + f "write_index/if bare=%b head=%a" t.bare Git.Reference.pp gr); if (not t.bare) && git_head = t.git_head then ( - Log.debug (fun f -> f "write cache (%a)" G.Reference.pp gr); + Log.debug (fun f -> f "write cache (%a)" Git.Reference.pp gr); (* FIXME G.write_index t.t gk *) let _ = gk in @@ -670,7 +655,7 @@ functor Log.debug (fun f -> f "set %a" pp_branch r); let gr = git_of_branch r in Lwt_mutex.with_lock t.m @@ fun () -> - G.Ref.write t.t gr (G.Reference.Hash k) >>= handle_git_err >>= fun () -> + G.Ref.write t.t gr (Git.Reference.Uid k) >>= handle_git_err >>= fun () -> W.notify t.w r (Some k) >>= fun () -> write_index t gr k let remove t r = @@ -682,7 +667,7 @@ functor let eq_head_contents_opt x y = match (x, y) with | None, None -> true - | Some x, Some y -> G.Reference.equal_head_contents x y + | Some x, Some y -> Git.Reference.equal_contents ~equal:G.Hash.equal x y | _ -> false let test_and_set t r ~test ~set = @@ -690,11 +675,11 @@ functor let pp = Fmt.option ~none:(Fmt.any "") (Irmin.Type.pp Val.t) in f "test_and_set %a: %a => %a" pp_branch r pp test pp set); let gr = git_of_branch r in - let c = function None -> None | Some h -> Some (G.Reference.Hash h) in + let c = function None -> None | Some h -> Some (Git.Reference.Uid h) in let ok r = handle_git_err r >|= fun () -> true in Lwt_mutex.with_lock t.m (fun () -> (G.Ref.read t.t gr >>= function - | Error `Not_found -> Lwt.return_none + | Error (`Reference_not_found _ | `Not_found _) -> Lwt.return_none | Ok x -> Lwt.return_some x | Error e -> Fmt.kstrf Lwt.fail_with "%a" G.pp_error e) >>= fun x -> @@ -736,9 +721,13 @@ functor module Irmin_sync_store (G : Git.S) - (S : Git.Sync.S with module Store := G) + (S : Git.Sync.S with type hash := G.hash and type store := G.t) (B : Irmin.Branch.S) = struct + let src = Logs.Src.create "irmin.git-output" ~doc:"Git output" + + module Gitlog = (val Logs.src_log src : Logs.LOG) + module H = Irmin.Hash.Make (G.Hash) type t = G.t @@ -747,70 +736,76 @@ struct type branch = B.t - type endpoint = S.Endpoint.t + type endpoint = Mimic.ctx * Smart_git.Endpoint.t - let git_of_branch_str str = G.Reference.of_string ("refs/heads/" ^ str) + let git_of_branch_str str = Git.Reference.v ("refs/heads/" ^ str) let git_of_branch r = git_of_branch_str (Irmin.Type.to_string B.t r) - let o_head_of_git = function None -> Ok None | Some k -> Ok (Some k) - - let fetch t ?depth e br = - let uri = S.Endpoint.uri e in - Log.debug (fun f -> f "fetch %a" Uri.pp_hum uri); - let _deepen = depth in - (* FIXME: need to be exposed in the Git API *) - let reference = git_of_branch br in - let result refs = - let key = - try Some (G.Reference.Map.find reference refs) with Not_found -> None - in - o_head_of_git key - in - let references = - (* remote *) - ( reference, - (* local *) - [ - G.Reference.of_string - ("refs/remotes/origin/" ^ Irmin.Type.to_string B.t br); - reference; - ] ) + (* let o_head_of_git = function None -> Ok None | Some k -> Ok (Some k) *) + + let ( >>? ) x f = + x >>= function Ok x -> f x | Error err -> Lwt.return (Error err) + + let msgf fmt = Fmt.kstrf (fun err -> `Msg err) fmt + + let reword_error f = function Ok _ as v -> v | Error err -> Error (f err) + + let fetch t ?depth (ctx, e) br = + Log.debug (fun f -> f "fetch %a" Smart_git.Endpoint.pp e); + let push_stdout msg = Gitlog.info (fun f -> f "%s" msg) + and push_stderr msg = Gitlog.warn (fun f -> f "%s" msg) + and deepen = + match depth with Some depth -> Some (`Depth depth) | None -> None + and reference = git_of_branch br + and capabilities = + [ + `Side_band_64k; + `Multi_ack_detailed; + `Ofs_delta; + `Thin_pack; + `Report_status; + ] in - S.fetch_one t e ~reference:references >|= function - | Error e -> Fmt.kstrf (fun e -> Error (`Msg e)) "%a" S.pp_error e - | Ok res -> ( - Log.debug (fun f -> f "fetch result: %a" S.pp_fetch_one res); - match res with `Sync refs -> result refs | `AlreadySync -> Ok None) - - let push t ?depth:_ e br = - let uri = S.Endpoint.uri e in - Log.debug (fun f -> f "push %a" Uri.pp_hum uri); + S.fetch ~push_stdout ~push_stderr ~capabilities ~ctx e t ?deepen + (`Some [ (reference, reference) ]) + >>= function + | Error `Not_found -> Lwt.return (Error (`Msg "not found")) + | Error (`Msg err) -> Lwt.return (Error (`Msg err)) + | Error (`Exn err) -> Lwt.return (Error (`Msg (Printexc.to_string err))) + | Error err -> + Fmt.kstrf (fun e -> Lwt.return (Error (`Msg e))) "%a" S.pp_error err + | Ok None -> Lwt.return (Ok None) + | Ok (Some (_, [ (reference, hash) ])) -> + let value = Git.Reference.uid hash in + let br = + Git.Reference.v ("refs/remotes/origin/" ^ Irmin.Type.to_string B.t br) + in + G.Ref.write t br value >|= reword_error (msgf "%a" G.pp_error) + >>? fun () -> + G.Ref.write t reference value >|= reword_error (msgf "%a" G.pp_error) + >>? fun () -> Lwt.return (Ok (Some hash)) + | _ -> assert false + + let push t ?depth:_ (ctx, e) br = + Log.debug (fun f -> f "push %a" Smart_git.Endpoint.pp e); let reference = git_of_branch br in - let result refs = - let errors = ref [] in - List.iter - (function - | Ok _ -> () - | Error (r, e) -> - errors := Fmt.strf "%a: %s" G.Reference.pp r e :: !errors) - refs; - if !errors = [] then Ok () - else - Fmt.kstrf - (fun e -> Error (`Msg e)) - "%a" - Fmt.(list ~sep:(unit "@.") string) - !errors - in - let references = - G.Reference.Map.singleton (* local *) reference (* remote *) [ reference ] + let capabilities = + [ + `Side_band_64k; + `Multi_ack_detailed; + `Ofs_delta; + `Thin_pack; + `Report_status; + ] in - S.update_and_create t ~references e >|= function - | Error e -> Fmt.kstrf (fun e -> Error (`Msg e)) "%a" S.pp_error e - | Ok r -> - Log.debug (fun f -> f "push result: %a" S.pp_update_and_create r); - result r + S.push ~capabilities ~ctx e t [ `Update (reference, reference) ] + >|= function + | Error (`Msg err) -> Error (`Msg err) + | Error (`Exn exn) -> Error (`Msg (Printexc.to_string exn)) + | Error `Not_found -> Error (`Msg "not found") + | Error err -> Error (`Msg (Fmt.strf "%a" S.pp_error err)) + | Ok () -> Ok () end type reference = @@ -868,12 +863,7 @@ end module type G = sig include Git.S - val v : - ?dotgit:Fpath.t -> - ?compression:int -> - ?buffers:buffer Lwt_pool.t -> - Fpath.t -> - (t, error) result Lwt.t + val v : ?dotgit:Fpath.t -> Fpath.t -> (t, error) result Lwt.t end module AW_check_closed (AW : ATOMIC_WRITE_STORE) : ATOMIC_WRITE_STORE = @@ -949,7 +939,7 @@ functor module Make_ext (G : G) - (S : Git.Sync.S with module Store := G) + (S : Git.Sync.S with type hash := G.hash and type store := G.t) (C : Irmin.Contents.S) (P : Irmin.Path.S) (B : BRANCH) = @@ -1010,16 +1000,10 @@ struct let fopt f = function None -> None | Some x -> Some (f x) let v conf = - let { root; dot_git; level; head; bare; buffers } = config conf in + let { root; dot_git; head; bare; _ } = config conf in let dotgit = fopt Fpath.v dot_git in let root = Fpath.v root in - let buffers = - fopt - (fun n -> Lwt_pool.create n (fun () -> Lwt.return (G.buffer ()))) - buffers - in - G.v ?dotgit ?compression:level ?buffers root >>= handle_git_err - >>= fun g -> + G.v ?dotgit root >>= handle_git_err >>= fun g -> R.v ~head ~bare g >|= fun b -> { g; b; closed = ref false; config = conf } @@ -1028,20 +1012,18 @@ struct end include Irmin.Of_private (P) - module Git = G - let git_commit (repo : Repo.t) (h : commit) : Git.Value.Commit.t option Lwt.t - = + let git_commit (repo : Repo.t) (h : commit) : G.Value.Commit.t option Lwt.t = let h = Commit.hash h in - Git.read repo.g h >|= function - | Ok (Git.Value.Commit c) -> Some c - | _ -> None + G.read repo.g h >|= function Ok (Git.Value.Commit c) -> Some c | _ -> None let git_of_repo r = r.g let repo_of_git ?head ?(bare = true) ?lock g = R.v ?lock ~head ~bare g >|= fun b -> { config = Irmin.Private.Conf.empty; closed = ref false; g; b } + + module Git = G end module Mem = struct @@ -1055,74 +1037,48 @@ module Mem = struct Hashtbl.replace confs c t; t - let v' ?dotgit ?compression ?buffers root = - let buffer = - match buffers with None -> None | Some p -> Some (Lwt_pool.use p) - in - v ?dotgit ?compression ?buffer root + let v' ?dotgit root = v ?dotgit root - let v ?dotgit ?compression ?buffers root = - let conf = (root, dotgit, compression, buffers) in + let v ?dotgit root = + let conf = (dotgit, root) in match find_conf conf with | Some x -> Lwt.return x - | None -> v' ?dotgit ?compression ?buffers root >|= add_conf conf + | None -> v' ?dotgit root >|= add_conf conf end module Make (G : G) - (S : Git.Sync.S with module Store := G) + (S : Git.Sync.S with type hash = G.hash and type store = G.t) (C : Irmin.Contents.S) (P : Irmin.Path.S) (B : Irmin.Branch.S) = Make_ext (G) (S) (C) (P) (Branch (B)) module No_sync (G : Git.S) = struct - (* XXX(samoht): so much boilerplate... *) - module Store = G + type hash = G.hash - module Endpoint = struct - type t = unit + type store = G.t - let uri _ = assert false - end + (* XXX(samoht): so much boilerplate... *) + (* XXX(dinosaure): not anymore. *) - type error = unit + type error = + [ `Not_found | `Msg of string | `Exn of exn | `Cycle | `Invalid_flow ] let pp_error _ _ = assert false - type command = - [ `Create of Store.Hash.t * Store.Reference.t - | `Delete of Store.Hash.t * Store.Reference.t - | `Update of Store.Hash.t * Store.Hash.t * Store.Reference.t ] - - let pp_command _ _ = assert false - - let pp_fetch_one _ _ = assert false - - let pp_update_and_create _ _ = assert false - - let push _ = assert false - - let ls _ = assert false + let fetch ?push_stdout:_ ?push_stderr:_ ~ctx:_ ?verify:_ _ _ ?version:_ + ?capabilities:_ ?deepen:_ _ = + assert false - let fetch _ = assert false - - let fetch_one _ = assert false - - let fetch_some _ = assert false - - let fetch_all _ = assert false - - let clone _ = assert false - - let update_and_create _ = assert false + let push ~ctx:_ ?verify:_ _ _ ?version:_ ?capabilities:_ _ = assert false end module Content_addressable (G : Git.S) (V : Irmin.Type.S) = struct module G = struct include G - let v ?dotgit:_ ?compression:_ ?buffers:_ _root = assert false + let v ?dotgit:_ _root = assert false end module V = struct @@ -1178,17 +1134,20 @@ module Atomic_write (G : Git.S) (K : Irmin.Branch.S) = struct include AW_check_closed (Irmin_branch_store) (G) (Branch (K)) end -module KV (G : G) (S : Git.Sync.S with module Store := G) (C : Irmin.Contents.S) = +module KV + (G : G) + (S : Git.Sync.S with type hash = G.hash and type store = G.t) + (C : Irmin.Contents.S) = Make (G) (S) (C) (Irmin.Path.String_list) (Irmin.Branch.String) module Ref (G : G) - (S : Git.Sync.S with module Store := G) + (S : Git.Sync.S with type hash = G.hash and type store = G.t) (C : Irmin.Contents.S) = Make_ext (G) (S) (C) (Irmin.Path.String_list) (Reference) module type S_MAKER = functor (G : G) - (S : Git.Sync.S with module Store := G) + (S : Git.Sync.S with type hash = G.hash and type store = G.t) (C : Irmin.Contents.S) (P : Irmin.Path.S) (B : Irmin.Branch.S) @@ -1200,11 +1159,11 @@ module type S_MAKER = functor and type contents = C.t and type branch = B.t and module Git = G - and type Private.Sync.endpoint = S.Endpoint.t + and type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t module type KV_MAKER = functor (G : G) - (S : Git.Sync.S with module Store := G) + (S : Git.Sync.S with type hash = G.hash and type store = G.t) (C : Irmin.Contents.S) -> S @@ -1213,11 +1172,11 @@ module type KV_MAKER = functor and type contents = C.t and type branch = string and module Git = G - and type Private.Sync.endpoint = S.Endpoint.t + and type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t module type REF_MAKER = functor (G : G) - (S : Git.Sync.S with module Store := G) + (S : Git.Sync.S with type hash = G.hash and type store = G.t) (C : Irmin.Contents.S) -> S @@ -1226,7 +1185,7 @@ module type REF_MAKER = functor and type contents = C.t and type branch = reference and module Git = G - and type Private.Sync.endpoint = S.Endpoint.t + and type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t include Conf diff --git a/src/irmin-git/irmin_git.mli b/src/irmin-git/irmin_git.mli index 651d159b31f..b6d6e6de3bd 100644 --- a/src/irmin-git/irmin_git.mli +++ b/src/irmin-git/irmin_git.mli @@ -41,25 +41,21 @@ val dot_git : string option Irmin.Private.Conf.key module Content_addressable (G : Git.S) (V : Irmin.Type.S) : Irmin.CONTENT_ADDRESSABLE_STORE with type 'a t = bool ref * G.t - and type key = G.Hash.t + and type key = G.hash and type value = V.t module Atomic_write (G : Git.S) (K : Irmin.Branch.S) : - Irmin.ATOMIC_WRITE_STORE with type key = K.t and type value = G.Hash.t + Irmin.ATOMIC_WRITE_STORE with type key = K.t and type value = G.hash module type G = sig include Git.S - val v : - ?dotgit:Fpath.t -> - ?compression:int -> - ?buffers:buffer Lwt_pool.t -> - Fpath.t -> - (t, error) result Lwt.t + val v : ?dotgit:Fpath.t -> Fpath.t -> (t, error) result Lwt.t end -module Mem : G with type Hash.t = Digestif.SHA1.t (** In-memory Git store. *) +module Mem : + G with type t = Digestif.SHA1.t Git.Mem.t and type hash = Digestif.SHA1.t module type S = sig (** The Git backend specializes a few types: @@ -70,7 +66,7 @@ module type S = sig module Git : Git.S (** Access to the underlying Git store. *) - include Irmin.S with type metadata = Metadata.t and type hash = Git.Hash.t + include Irmin.S with type metadata = Metadata.t and type hash = Git.hash val git_commit : Repo.t -> commit -> Git.Value.Commit.t option Lwt.t (** [git_commit repo h] is the commit corresponding to [h] in the repository @@ -90,7 +86,7 @@ end module type S_MAKER = functor (G : G) - (S : Git.Sync.S with module Store := G) + (S : Git.Sync.S with type hash = G.hash and type store = G.t) (C : Irmin.Contents.S) (P : Irmin.Path.S) (B : Irmin.Branch.S) @@ -102,11 +98,11 @@ module type S_MAKER = functor and type contents = C.t and type branch = B.t and module Git = G - and type Private.Sync.endpoint = S.Endpoint.t + and type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t module type KV_MAKER = functor (G : G) - (S : Git.Sync.S with module Store := G) + (S : Git.Sync.S with type hash = G.hash and type store = G.t) (C : Irmin.Contents.S) -> S @@ -115,14 +111,14 @@ module type KV_MAKER = functor and type contents = C.t and type branch = string and module Git = G - and type Private.Sync.endpoint = S.Endpoint.t + and type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t type reference = [ `Branch of string | `Remote of string | `Tag of string | `Other of string ] module type REF_MAKER = functor (G : G) - (S : Git.Sync.S with module Store := G) + (S : Git.Sync.S with type hash = G.hash and type store = G.t) (C : Irmin.Contents.S) -> S @@ -131,7 +127,7 @@ module type REF_MAKER = functor and type contents = C.t and type branch = reference and module Git = G - and type Private.Sync.endpoint = S.Endpoint.t + and type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t module Make : S_MAKER @@ -153,7 +149,7 @@ module Reference : BRANCH with type t = reference module Make_ext (G : G) - (S : Git.Sync.S with module Store := G) + (S : Git.Sync.S with type hash := G.hash and type store := G.t) (C : Irmin.Contents.S) (P : Irmin.Path.S) (B : BRANCH) : diff --git a/src/irmin-graphql/dune b/src/irmin-graphql/dune index afbc9768384..a5798f4de91 100644 --- a/src/irmin-graphql/dune +++ b/src/irmin-graphql/dune @@ -1,5 +1,5 @@ (library (name irmin_graphql) (public_name irmin-graphql) - (libraries fmt cohttp cohttp-lwt graphql-cohttp graphql graphql-lwt + (libraries mimic fmt cohttp cohttp-lwt graphql-cohttp graphql graphql-lwt graphql_parser irmin lwt)) diff --git a/src/irmin-graphql/server.ml b/src/irmin-graphql/server.ml index 808930ed10e..9d0f7ae85e7 100644 --- a/src/irmin-graphql/server.ml +++ b/src/irmin-graphql/server.ml @@ -36,7 +36,9 @@ module Result = struct end module type CONFIG = sig - val remote : (?headers:Cohttp.Header.t -> string -> Irmin.remote) option + val remote : + (?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> string -> Irmin.remote) + option val info : ?author:string -> ('a, Format.formatter, unit, Irmin.Info.f) format4 -> 'a diff --git a/src/irmin-graphql/server.mli b/src/irmin-graphql/server.mli index 96934bbd22b..90fb14b5210 100644 --- a/src/irmin-graphql/server.mli +++ b/src/irmin-graphql/server.mli @@ -25,7 +25,9 @@ end (** GraphQL server config *) module type CONFIG = sig - val remote : (?headers:Cohttp.Header.t -> string -> Irmin.remote) option + val remote : + (?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> string -> Irmin.remote) + option val info : ?author:string -> ('a, Format.formatter, unit, Irmin.Info.f) format4 -> 'a diff --git a/src/irmin-http/dune b/src/irmin-http/dune index be83ece0e59..f4f03dc9ef3 100644 --- a/src/irmin-http/dune +++ b/src/irmin-http/dune @@ -1,6 +1,7 @@ (library (name irmin_http) (public_name irmin-http) - (libraries astring cohttp cohttp-lwt fmt irmin jsonm logs lwt uri webmachine) + (libraries conduit astring cohttp cohttp-lwt fmt irmin jsonm logs lwt uri + webmachine) (preprocess (pps ppx_irmin))) diff --git a/src/irmin-mirage/git/dune b/src/irmin-mirage/git/dune index d551bcd6b7a..6b1ab7a8fd8 100644 --- a/src/irmin-mirage/git/dune +++ b/src/irmin-mirage/git/dune @@ -1,5 +1,5 @@ (library (name irmin_mirage_git) (public_name irmin-mirage-git) - (libraries fmt cohttp conduit-lwt conduit-mirage git git-mirage irmin - irmin-mirage irmin-git lwt mirage-clock mirage-kv uri)) + (libraries fmt cohttp conduit-lwt conduit-mirage git irmin irmin-mirage + irmin-git git-cohttp-mirage lwt mirage-clock mirage-kv uri)) diff --git a/src/irmin-mirage/git/irmin_mirage_git.ml b/src/irmin-mirage/git/irmin_mirage_git.ml index bdd4ee5bbbc..7597a4c503e 100644 --- a/src/irmin-mirage/git/irmin_mirage_git.ml +++ b/src/irmin-mirage/git/irmin_mirage_git.ml @@ -1,14 +1,12 @@ open Lwt.Infix module type S = sig - include Irmin_git.S with type Private.Sync.endpoint = Git_mirage.endpoint + include + Irmin_git.S + with type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t val remote : - ?conduit:Conduit_mirage.conduit -> - ?resolver:Resolver_lwt.t -> - ?headers:Cohttp.Header.t -> - string -> - Irmin.remote + ?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> string -> Irmin.remote end module type S_MAKER = functor @@ -41,39 +39,40 @@ module type REF_MAKER = functor (G : Irmin_git.G) (C : Irmin.Contents.S) -> and type branch = Irmin_git.reference and module Git = G +let remote ?(ctx = Mimic.empty) ?headers uri = + let ( ! ) f a b = f b a in + let headers = Option.map Cohttp.Header.to_list headers in + match Smart_git.Endpoint.of_string uri with + | Ok edn -> + let edn = + Option.fold ~none:edn + ~some:(!Smart_git.Endpoint.with_headers_if_http edn) + headers + in + (ctx, edn) + | Error (`Msg err) -> Fmt.invalid_arg "remote: %s" err + module Make (G : Irmin_git.G) (C : Irmin.Contents.S) (P : Irmin.Path.S) (B : Irmin.Branch.S) = struct - include Irmin_git.Make (G) (Git_mirage.Sync (G)) (C) (P) (B) + include Irmin_git.Make (G) (Git.Mem.Sync (G) (Git_cohttp_mirage)) (C) (P) (B) - let remote ?conduit ?resolver ?headers uri = - let e = - Git_mirage.endpoint ?headers ?conduit ?resolver (Uri.of_string uri) - in - E e + let remote ?ctx ?headers uri = E (remote ?ctx ?headers uri) end module Ref (G : Irmin_git.G) (C : Irmin.Contents.S) = struct - include Irmin_git.Ref (G) (Git_mirage.Sync (G)) (C) + include Irmin_git.Ref (G) (Git.Mem.Sync (G) (Git_cohttp_mirage)) (C) - let remote ?conduit ?resolver ?headers uri = - let e = - Git_mirage.endpoint ?headers ?conduit ?resolver (Uri.of_string uri) - in - E e + let remote ?ctx ?headers uri = E (remote ?ctx ?headers uri) end module KV (G : Irmin_git.G) (C : Irmin.Contents.S) = struct - include Irmin_git.KV (G) (Git_mirage.Sync (G)) (C) + include Irmin_git.KV (G) (Git.Mem.Sync (G) (Git_cohttp_mirage)) (C) - let remote ?conduit ?resolver ?headers uri = - let e = - Git_mirage.endpoint ?headers ?conduit ?resolver (Uri.of_string uri) - in - E e + let remote ?ctx ?headers uri = E (remote ?ctx ?headers uri) end module type KV_RO = sig @@ -85,8 +84,7 @@ module type KV_RO = sig ?depth:int -> ?branch:string -> ?root:key -> - ?conduit:Conduit_mirage.t -> - ?resolver:Resolver_lwt.t -> + ?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> git -> string -> @@ -101,7 +99,7 @@ module KV_RO (G : Git.S) = struct module G = struct include G - let v ?dotgit:_ ?compression:_ ?buffers:_ _root = assert false + let v ?dotgit:_ _root = assert false end module S = KV (G) (Irmin.Contents.String) @@ -173,13 +171,13 @@ module KV_RO (G : Git.S) = struct | [] -> Error (`Not_found key) | h :: _ -> Ok (0, Irmin.Info.date (S.Commit.info h)) - let connect ?(depth = 1) ?(branch = "master") ?(root = Mirage_kv.Key.empty) - ?conduit ?resolver ?headers t uri = - let remote = S.remote ?conduit ?resolver ?headers uri in - let head = G.Reference.of_string ("refs/heads/" ^ branch) in + let connect ?depth ?(branch = "master") ?(root = Mirage_kv.Key.empty) ?ctx + ?headers t uri = + let remote = S.remote ?ctx ?headers uri in + let head = Git.Reference.v ("refs/heads/" ^ branch) in S.repo_of_git ~bare:true ~head t >>= fun repo -> S.of_branch repo branch >>= fun t -> - Sync.pull_exn t ~depth remote `Set >|= fun _ -> + Sync.pull_exn t ?depth remote `Set >|= fun _ -> let root = path root in { t; root } @@ -213,8 +211,7 @@ module type KV_RW = sig ?depth:int -> ?branch:string -> ?root:key -> - ?conduit:Conduit_mirage.t -> - ?resolver:Resolver_lwt.t -> + ?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> ?author:(unit -> string) -> ?msg:([ `Set of key | `Remove of key | `Batch ] -> string) -> @@ -258,11 +255,10 @@ module KV_RW (G : Irmin_git.G) (C : Mirage_clock.PCLOCK) = struct | `Remove k -> Fmt.strf "Removing %a" Mirage_kv.Key.pp k | `Batch -> "Commmiting batch operation" - let connect ?depth ?branch ?root ?conduit ?resolver ?headers - ?(author = default_author) ?(msg = default_msg) git uri = - RO.connect ?depth ?branch ?root ?conduit ?resolver ?headers git uri - >|= fun t -> - let remote = S.remote ?conduit ?resolver ?headers uri in + let connect ?depth ?branch ?root ?ctx ?headers ?(author = default_author) + ?(msg = default_msg) git uri = + RO.connect ?depth ?branch ?root ?ctx ?headers git uri >|= fun t -> + let remote = S.remote ?ctx ?headers uri in { store = Store t; author; msg; remote } let disconnect t = diff --git a/src/irmin-mirage/git/irmin_mirage_git.mli b/src/irmin-mirage/git/irmin_mirage_git.mli index 527948cfcfd..3a37ceb72d0 100644 --- a/src/irmin-mirage/git/irmin_mirage_git.mli +++ b/src/irmin-mirage/git/irmin_mirage_git.mli @@ -1,12 +1,10 @@ module type S = sig - include Irmin_git.S with type Private.Sync.endpoint = Git_mirage.endpoint + include + Irmin_git.S + with type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t val remote : - ?conduit:Conduit_mirage.conduit -> - ?resolver:Resolver_lwt.t -> - ?headers:Cohttp.Header.t -> - string -> - Irmin.remote + ?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> string -> Irmin.remote end module type S_MAKER = functor @@ -54,8 +52,7 @@ module type KV_RO = sig ?depth:int -> ?branch:string -> ?root:key -> - ?conduit:Conduit_mirage.t -> - ?resolver:Resolver_lwt.t -> + ?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> git -> string -> @@ -79,8 +76,7 @@ module type KV_RW = sig ?depth:int -> ?branch:string -> ?root:key -> - ?conduit:Conduit_mirage.t -> - ?resolver:Resolver_lwt.t -> + ?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> ?author:(unit -> string) -> ?msg:([ `Set of key | `Remove of key | `Batch ] -> string) -> diff --git a/src/irmin-mirage/graphql/dune b/src/irmin-mirage/graphql/dune index 842a421c03c..6058adc9d11 100644 --- a/src/irmin-mirage/graphql/dune +++ b/src/irmin-mirage/graphql/dune @@ -1,5 +1,5 @@ (library (name irmin_mirage_graphql) (public_name irmin-mirage-graphql) - (libraries cohttp-lwt git-mirage irmin irmin-mirage irmin-graphql lwt - mirage-clock uri)) + (libraries cohttp-lwt git irmin irmin-mirage irmin-graphql lwt mirage-clock + uri)) diff --git a/src/irmin-mirage/graphql/irmin_mirage_graphql.ml b/src/irmin-mirage/graphql/irmin_mirage_graphql.ml index 29da354fd99..b0d0ae21252 100644 --- a/src/irmin-mirage/graphql/irmin_mirage_graphql.ml +++ b/src/irmin-mirage/graphql/irmin_mirage_graphql.ml @@ -4,14 +4,17 @@ module Server = struct module Http : Cohttp_lwt.S.Server - module Store : Irmin.S with type Private.Sync.endpoint = Git_mirage.endpoint + module Store : + Irmin.S with type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t val start : http:(Http.t -> unit Lwt.t) -> Store.repo -> unit Lwt.t end module Make (Http : Cohttp_lwt.S.Server) - (Store : Irmin.S with type Private.Sync.endpoint = Git_mirage.endpoint) + (Store : Irmin.S + with type Private.Sync.endpoint = + Mimic.ctx * Smart_git.Endpoint.t) (Pclock : Mirage_clock.PCLOCK) = struct module Store = Store @@ -26,9 +29,18 @@ module Server = struct let remote = Some - (fun ?headers uri -> - let e = Git_mirage.endpoint ?headers (Uri.of_string uri) in - Store.E e) + (fun ?(ctx = Mimic.empty) ?headers uri -> + let ( ! ) f a b = f b a in + let headers = Option.map Cohttp.Header.to_list headers in + match Smart_git.Endpoint.of_string uri with + | Ok edn -> + let edn = + Option.fold ~none:edn + ~some:(!Smart_git.Endpoint.with_headers_if_http edn) + headers + in + Store.E (ctx, edn) + | Error (`Msg err) -> Fmt.invalid_arg "invalid remote: %s" err) end in (module Irmin_graphql.Server.Make (Http) (Config) (Store) : Irmin_graphql.Server.S diff --git a/src/irmin-mirage/graphql/irmin_mirage_graphql.mli b/src/irmin-mirage/graphql/irmin_mirage_graphql.mli index 2a58ec05482..d1ba6f572b7 100644 --- a/src/irmin-mirage/graphql/irmin_mirage_graphql.mli +++ b/src/irmin-mirage/graphql/irmin_mirage_graphql.mli @@ -4,14 +4,17 @@ module Server : sig module Http : Cohttp_lwt.S.Server - module Store : Irmin.S with type Private.Sync.endpoint = Git_mirage.endpoint + module Store : + Irmin.S with type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t val start : http:(Http.t -> unit Lwt.t) -> Store.repo -> unit Lwt.t end module Make (Http : Cohttp_lwt.S.Server) - (Store : Irmin.S with type Private.Sync.endpoint = Git_mirage.endpoint) + (Store : Irmin.S + with type Private.Sync.endpoint = + Mimic.ctx * Smart_git.Endpoint.t) (Pclock : Mirage_clock.PCLOCK) : S with module Pclock = Pclock diff --git a/src/irmin-unix/cli.ml b/src/irmin-unix/cli.ml index c6465c3f0d1..e8c855abf86 100644 --- a/src/irmin-unix/cli.ml +++ b/src/irmin-unix/cli.ml @@ -316,7 +316,7 @@ let remove = let apply e f = match (e, f) with - | R (h, e), Some f -> f ?headers:h e + | R (h, e), Some f -> f ?ctx:None ?headers:h e | R _, None -> Fmt.failwith "invalid remote for that kind of store" | r, _ -> r diff --git a/src/irmin-unix/dune b/src/irmin-unix/dune index 304879b60a6..43125172c9d 100644 --- a/src/irmin-unix/dune +++ b/src/irmin-unix/dune @@ -1,7 +1,7 @@ (library (name irmin_unix) (public_name irmin-unix) - (libraries astring cmdliner cohttp cohttp-lwt cohttp-lwt-unix conduit - conduit-lwt-unix fmt.cli fmt.tty git git-unix irmin irmin-fs irmin-git - irmin-graphql irmin-http irmin-mem irmin-pack irmin-watcher logs.cli - logs.fmt lwt lwt.unix uri yaml)) + (libraries git-cohttp-unix astring cmdliner cohttp cohttp-lwt + cohttp-lwt-unix conduit conduit-lwt fmt.cli fmt.tty git git-unix irmin + irmin-fs irmin-git irmin-graphql irmin-http irmin-mem irmin-pack + irmin-watcher logs.cli logs.fmt lwt lwt.unix uri yaml)) diff --git a/src/irmin-unix/http.ml b/src/irmin-unix/http.ml index 1c37e9e3eae..b3583f17169 100644 --- a/src/irmin-unix/http.ml +++ b/src/irmin-unix/http.ml @@ -17,13 +17,7 @@ module HTTP = struct include Cohttp_lwt_unix.Client - let ctx () = - let resolver = - let h = Hashtbl.create 1 in - Hashtbl.add h "irmin" (`Unix_domain_socket "/var/run/irmin.sock"); - Resolver_lwt_unix.static h - in - Some (Cohttp_lwt_unix.Client.custom_ctx ~resolver ()) + let ctx () = Some default_ctx end module Client = Irmin_http.Client (HTTP) diff --git a/src/irmin-unix/irmin_unix.mli b/src/irmin-unix/irmin_unix.mli index a612d47a3b9..4d8e171b150 100644 --- a/src/irmin-unix/irmin_unix.mli +++ b/src/irmin-unix/irmin_unix.mli @@ -71,9 +71,12 @@ module Git : sig (** {1 Git Store} *) module type S = sig - include Irmin_git.S with type Private.Sync.endpoint = Git_unix.endpoint + include + Irmin_git.S + with type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t - val remote : ?headers:Cohttp.Header.t -> string -> Irmin.remote + val remote : + ?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> string -> Irmin.remote end module Make diff --git a/src/irmin-unix/resolver.ml b/src/irmin-unix/resolver.ml index 8ccc294cda4..4e3e2303a87 100644 --- a/src/irmin-unix/resolver.ml +++ b/src/irmin-unix/resolver.ml @@ -246,7 +246,8 @@ type hash = Hash.t (* Store *) module Store = struct - type remote_fn = ?headers:Cohttp.Header.t -> string -> Irmin.remote + type remote_fn = + ?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> string -> Irmin.remote type t = T : (module Irmin.S) * remote_fn option -> t @@ -428,7 +429,7 @@ let from_config_file_with_defaults path (store, hash, contents) config branch : | None -> Irmin.Private.Conf.default Irmin_git.bare | Some b -> b in - let head = assoc "head" (fun x -> Git.Reference.of_string x) in + let head = assoc "head" (fun x -> Git.Reference.v x) in let uri = assoc "uri" Uri.of_string in let add k v config = Irmin.Private.Conf.add config k v in Irmin.Private.Conf.empty diff --git a/src/irmin-unix/resolver.mli b/src/irmin-unix/resolver.mli index 992cb96a4bf..98b247c3896 100644 --- a/src/irmin-unix/resolver.mli +++ b/src/irmin-unix/resolver.mli @@ -59,7 +59,8 @@ module Store : sig | Fixed_hash of (contents -> t) | Variable_hash of (hash -> contents -> t) - type remote_fn = ?headers:Cohttp.Header.t -> string -> Irmin.remote + type remote_fn = + ?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> string -> Irmin.remote val v : ?remote:remote_fn -> (module Irmin.S) -> t diff --git a/src/irmin-unix/xgit.ml b/src/irmin-unix/xgit.ml index e470c221a1b..faf2e5ca492 100644 --- a/src/irmin-unix/xgit.ml +++ b/src/irmin-unix/xgit.ml @@ -19,9 +19,12 @@ let src = Logs.Src.create "git.unix" ~doc:"logs git's unix events" module Log = (val Logs.src_log src : Logs.LOG) module type S = sig - include Irmin_git.S with type Private.Sync.endpoint = Git_unix.endpoint + include + Irmin_git.S + with type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t - val remote : ?headers:Cohttp.Header.t -> string -> Irmin.remote + val remote : + ?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> string -> Irmin.remote end module type S_MAKER = functor @@ -54,46 +57,45 @@ module type REF_MAKER = functor (G : Irmin_git.G) (C : Irmin.Contents.S) -> and type branch = Irmin_git.reference and module Git = G +let remote ?(ctx = Mimic.empty) ?headers uri = + let ( ! ) f a b = f b a in + let headers = Option.map Cohttp.Header.to_list headers in + match Smart_git.Endpoint.of_string uri with + | Ok edn -> + let edn = + Option.fold ~none:edn + ~some:(!Smart_git.Endpoint.with_headers_if_http edn) + headers + in + (ctx, edn) + | Error (`Msg err) -> Fmt.invalid_arg "remote: %s" err + module Make (G : Irmin_git.G) (C : Irmin.Contents.S) (P : Irmin.Path.S) (B : Irmin.Branch.S) = struct - include Irmin_git.Make (G) (Git_unix.Sync (G)) (C) (P) (B) + include Irmin_git.Make (G) (Git_unix.Sync (G) (Git_cohttp_unix)) (C) (P) (B) - let remote ?headers uri = - let e = Git_unix.endpoint ?headers (Uri.of_string uri) in - E e + let remote ?ctx ?headers uri = E (remote ?ctx ?headers uri) end module KV (G : Irmin_git.G) (C : Irmin.Contents.S) = struct - include Irmin_git.KV (G) (Git_unix.Sync (G)) (C) + include Irmin_git.KV (G) (Git_unix.Sync (G) (Git_cohttp_unix)) (C) - let remote ?headers uri = - let e = Git_unix.endpoint ?headers (Uri.of_string uri) in - E e + let remote ?ctx ?headers uri = E (remote ?ctx ?headers uri) end module Ref (G : Irmin_git.G) (C : Irmin.Contents.S) = struct - include Irmin_git.Ref (G) (Git_unix.Sync (G)) (C) + include Irmin_git.Ref (G) (Git_unix.Sync (G) (Git_cohttp_unix)) (C) - let remote ?headers uri = - let e = Git_unix.endpoint ?headers (Uri.of_string uri) in - E e + let remote ?ctx ?headers uri = E (remote ?ctx ?headers uri) end module FS = struct - module G = struct - include Git_unix.Store - - let v ?dotgit ?compression ?buffers root = - let buffer = - match buffers with None -> None | Some p -> Some (Lwt_pool.use p) - in - v ?dotgit ?compression ?buffer root - end - + module G = Git_unix.Store + module S = Git_unix.Sync (G) (Git_cohttp_unix) module Make = Make (G) module Ref = Ref (G) module KV = KV (G) @@ -101,6 +103,7 @@ end module Mem = struct module G = Irmin_git.Mem + module S = Git.Mem.Sync (G) (Git_cohttp_unix) module Content_addressable = Irmin_git.Content_addressable (G) module Atomic_write = Irmin_git.Atomic_write (G) module Make = Make (G) diff --git a/src/irmin-unix/xgit.mli b/src/irmin-unix/xgit.mli index 10e6273e56f..fb23e48bb4f 100644 --- a/src/irmin-unix/xgit.mli +++ b/src/irmin-unix/xgit.mli @@ -15,9 +15,12 @@ *) module type S = sig - include Irmin_git.S with type Private.Sync.endpoint = Git_unix.endpoint + include + Irmin_git.S + with type Private.Sync.endpoint = Mimic.ctx * Smart_git.Endpoint.t - val remote : ?headers:Cohttp.Header.t -> string -> Irmin.remote + val remote : + ?ctx:Mimic.ctx -> ?headers:Cohttp.Header.t -> string -> Irmin.remote end module type S_MAKER = functor diff --git a/test/irmin-git/dune b/test/irmin-git/dune index 093d72e8e6a..dfb27e4f4c9 100644 --- a/test/irmin-git/dune +++ b/test/irmin-git/dune @@ -2,7 +2,7 @@ (name test_git) (modules test_git) (libraries alcotest fmt fpath irmin irmin-test irmin-mem irmin-git git - git-unix lwt lwt.unix) + git-unix git-cohttp-unix lwt lwt.unix) (preprocess (pps ppx_irmin))) diff --git a/test/irmin-git/test_git.ml b/test/irmin-git/test_git.ml index 52f00e96311..d5a83082fa5 100644 --- a/test/irmin-git/test_git.ml +++ b/test/irmin-git/test_git.ml @@ -19,11 +19,9 @@ open Lwt.Infix let test_db = Filename.concat "_build" "test-db-git" let config = - let head = Git.Reference.of_string "refs/heads/test" in + let head = Git.Reference.v "refs/heads/test" in Irmin_git.config ~head ~bare:true test_db -module Net = Git_unix.Net - module type S = sig include Irmin_test.S @@ -51,7 +49,7 @@ module type X = module Mem (C : Irmin.Contents.S) = struct module G = Irmin_git.Mem - module S = Irmin_git.KV (G) (Git_unix.Sync (G)) (C) + module S = Irmin_git.KV (G) (Git_unix.Sync (G) (Git_cohttp_unix)) (C) include S let init () = @@ -147,7 +145,10 @@ let test_sort_order (module S : S) = Lwt.return_unit module Ref (S : Irmin_git.G) = - Irmin_git.Ref (S) (Git_unix.Sync (S)) (Irmin.Contents.String) + Irmin_git.Ref + (S) + (Git_unix.Sync (S) (Git_cohttp_unix)) + (Irmin.Contents.String) let pp_reference ppf = function | `Branch s -> Fmt.pf ppf "branch: %s" s diff --git a/test/irmin-unix/test_unix.ml b/test/irmin-unix/test_unix.ml index db167ad91a9..9ff71308e77 100644 --- a/test/irmin-unix/test_unix.ml +++ b/test/irmin-unix/test_unix.ml @@ -84,7 +84,7 @@ module Git = struct Lwt.return_unit let config = - let head = Git.Reference.of_string "refs/heads/test" in + let head = Git.Reference.v "refs/heads/test" in Irmin_git.config ~head ~bare:true test_db let suite =