diff --git a/README.md b/README.md index 490850f..ad529e9 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ let _ = The user can manipulate the repository as an [RW][mirage-kv-rw] repository. Any change to the repository requires a new commit. These changes will be sent to -the remote repository. The user can _fold_ any changes into one commit if he/she -wants. +the remote repository. The user can _fold_ any changes into one commit if +he/she wants. ```ocaml module Store = Git_kv.Make (Pclock) @@ -58,13 +58,13 @@ let new_file t = remote repository. *) ... -let new_files_batched t = - Store.batch t @@ fun t -> +let new_files t = + Store.change_and_push t @@ fun t -> Store.set t Mirage_kv.Key.(empty / "foo" "foo") >>= fun () -> Store.set t Mirage_kv.Key.(empty / "bar" "bar") (* XXX(dinosaure): multiple files are added into the local repository but they are committed only at the end of the given function - to [batch]. That's say, only one commit was made and sended to the + to [change_and_push]. That's say, only one commit was made and sended to the remote Git repository. *) ``` diff --git a/app/mgit.ml b/app/mgit.ml index 8d4412f..2400edd 100644 --- a/app/mgit.ml +++ b/app/mgit.ml @@ -139,8 +139,8 @@ let repl store fd_in = if is_a_tty then Fmt.pr "\n%!" ; pull ~quiet:false store0 >|= ignore >>= fun () -> go store0 | [ "quit"; ] -> Lwt.return () - | [ "batch"; ] -> - Store.batch store0 (fun store1 -> go store1) + | [ "fold"; ] -> + Store.change_and_push store0 (fun store1 -> go store1) >>= fun () -> go store0 | [ "save"; filename ] -> save store0 filename >|= ignore diff --git a/src/git_kv.ml b/src/git_kv.ml index e3a3bec..c2656db 100644 --- a/src/git_kv.ml +++ b/src/git_kv.ml @@ -613,7 +613,9 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct remove t source >>= fun () -> set t dest contents - let batch t ?retries:_ f = + let batch t ?retries:_ f = f t + + let change_and_push t f = let open Lwt.Infix in if t.in_closure then Fmt.invalid_arg "Nested change_and_push" ; (* XXX(dinosaure): serialize [batch]. If we do [Lwt.both (batch ..) (batch ..)], they diff --git a/src/git_kv.mli b/src/git_kv.mli index f481c64..3e8e2ad 100644 --- a/src/git_kv.mli +++ b/src/git_kv.mli @@ -19,7 +19,7 @@ change produces a commit and after each change we try to transfer them to the remote Git repository. If you want to make multiple changes but contain them in a single commit and only transfer those changes once, you should - use the {!val:Make.batch} function. + use the {!val:Make.change_and_push} function. {2: Serialization of the Git repository.} @@ -66,4 +66,6 @@ module Make (Pclock : Mirage_clock.PCLOCK) : sig | `Hash_not_found of Digestif.SHA1.t | `Reference_not_found of Git.Reference.t | Mirage_kv.write_error ] + + val change_and_push : t -> (t -> 'a Lwt.t) -> 'a Lwt.t end diff --git a/test/dune b/test/dune index feabbdc..26ad0c9 100644 --- a/test/dune +++ b/test/dune @@ -6,6 +6,6 @@ (cram (package git-kv) - (applies_to batch) + (applies_to fold) (locks p9418) (deps %{bin:mgit})) diff --git a/test/batch.t b/test/fold.t similarity index 98% rename from test/batch.t rename to test/fold.t index 499e2dd..73cee83 100644 --- a/test/batch.t +++ b/test/fold.t @@ -5,7 +5,7 @@ Batch operation $ cd .. $ git daemon --base-path=. --export-all --enable=receive-pack --reuseaddr --pid-file=pid --detach $ mgit git://localhost/simple#main < batch + > fold > set /bar "Git rocks!" > set /foo "Hello World!" > exists /bar