Rename batch to change_and_push (and implement batch as noop)

This commit is contained in:
Romain Calascibetta 2022-10-31 18:13:15 +01:00
parent 32c802e176
commit 2cfcb0a714
6 changed files with 15 additions and 11 deletions

View file

@ -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. *)
```

View file

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

View file

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

View file

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

View file

@ -6,6 +6,6 @@
(cram
(package git-kv)
(applies_to batch)
(applies_to fold)
(locks p9418)
(deps %{bin:mgit}))

View file

@ -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 <<EOF
> batch
> fold
> set /bar "Git rocks!"
> set /foo "Hello World!"
> exists /bar