diff --git a/README.md b/README.md index d9c3bb1..45ae3ed 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,11 @@ 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 by default. If the user does not want to push modifications, -they can use `Git_kv.Make.Local` which provide functions without `push`. If the -user knows that they will do many changes and they don't want to change all of -them and do a `push` only at the end, they can use `Git_kv.Make.batch`. +the remote repository by default. If the user does not want to push +modifications, they can use `Git_kv.Make.Local` which provide functions without +`push`. If the user knows that they will do many changes and they don't want to +change all of them and do a `push` only at the end, they can use +`Git_kv.Make.change_and_push`. ```ocaml module Store = Git_kv.Make (Pclock) @@ -63,8 +64,8 @@ let new_file_locally t = Store.Local.set t Mirage_kv.Key.(empty / "foo") "foo" >>= fun () -> ... -let batch_operations t = - Store.batch t @@ fun t -> +let push_operations t = + Store.change_and_push t @@ fun t -> Store.set t Mirage_kv.Key.(empty / "bar") "bar" >>= fun () -> Store.remove t Mirage_kv.Key.(empty / "foo") ``` diff --git a/src/git_kv.ml b/src/git_kv.ml index 4fc0178..4d0433b 100644 --- a/src/git_kv.ml +++ b/src/git_kv.ml @@ -607,7 +607,7 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct remove ~and_push t source >>= fun () -> set ~and_push t dest contents - let batch t ?retries:_ f = + let change_and_push t f = let open Lwt.Infix in ( match t.batch with | None -> Lwt.return_unit @@ -625,6 +625,8 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct Lwt.wakeup_later wk () ; Lwt.return res + let batch t ?retries:_ f = f t + module Local = struct let set_partial t k ~offset v = set_partial ~and_push:false t k ~offset v let set t k v = set ~and_push:false t k v diff --git a/src/git_kv.mli b/src/git_kv.mli index 13837b6..2c04b6f 100644 --- a/src/git_kv.mli +++ b/src/git_kv.mli @@ -31,11 +31,11 @@ remotely, the commit-graph given by the transmission, and your last commit. In that way, our [push] is most similar to a [git push --force]! - To save I/O, the {!val:Make.batch} operation allows you to do some change - into a closure and the implementation will push only at the end of this - closure. By this way, you can {!val:Make.set}, {!val:Make.rename} or - {!val:Make.remove} without a systematic [push] on these actions. Only one - will be done at the end of your closure. + To save I/O, the {!val:Make.change_and_push} operation allows you to do + some change into a closure and the implementation will push only at the end + of this closure. By this way, you can {!val:Make.set}, {!val:Make.rename} + or {!val:Make.remove} without a systematic [push] on these actions. Only + one will be done at the end of your closure. {2: Serialization of the Git repository.} @@ -84,6 +84,11 @@ module Make (Pclock : Mirage_clock.PCLOCK) : sig | `Reference_not_found of Git.Reference.t | Mirage_kv.write_error ] + val change_and_push : t -> (t -> 'a Lwt.t) -> 'a Lwt.t + (** [change_and_push store f] lets the user to do some changes into [f] and + only push commits at the end of [f]. It saves I/O if the user wants to + do multiple changes without pushing every times. *) + module Local : sig val set : t -> key -> string -> (unit, write_error) result Lwt.t val remove : t -> key -> (unit, write_error) result Lwt.t