Rename batch to change_and_push and re-instantiate batch as a noop function

This commit is contained in:
Romain Calascibetta 2022-10-28 16:38:32 +02:00
parent a1da5157f9
commit e16dcce930
3 changed files with 20 additions and 12 deletions

View file

@ -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")
```

View file

@ -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

View file

@ -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