From 93bcbe576deb3bb2b1a182af82ddf292a2f0ba55 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Mon, 28 Oct 2024 21:56:53 +0100 Subject: [PATCH 1/2] only use a single commit in rename --- src/git_kv.ml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/git_kv.ml b/src/git_kv.ml index fcfeb4e..3f3f478 100644 --- a/src/git_kv.ml +++ b/src/git_kv.ml @@ -652,13 +652,6 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct let open Lwt.Infix in remove ?and_commit:t.committed t key >|= Result.map_error to_write_error - let rename t ~source ~dest = - (* TODO(dinosaure): optimize it! It was done on the naive way. *) - let open Lwt_result.Infix in - get t source >>= fun contents -> - remove t source >>= fun () -> - set t dest contents - let allocate t key ?last_modified:_ size = let open Lwt.Infix in exists t key >>= function @@ -709,4 +702,18 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct Lwt.return_ok res) >|= Result.map_error (fun err -> `Msg (Fmt.str "error pushing %a" Store.pp_error err))) + + let rename t ~source ~dest = + let open Lwt_result.Infix in + let op t = + get t source >>= fun contents -> + remove t source >>= fun () -> + set t dest contents + in + match t.committed with + | Some _ -> op t + | None -> + change_and_push t op >>! function + | Ok a -> Lwt.return a + | Error _ as e -> Lwt.return e end -- 2.47.0 From 708cd7d008cd97cdb3feb54afb7838843de67614 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Tue, 29 Oct 2024 12:25:08 +0100 Subject: [PATCH 2/2] add a comment --- src/git_kv.ml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/git_kv.ml b/src/git_kv.ml index 3f3f478..ef8d57c 100644 --- a/src/git_kv.ml +++ b/src/git_kv.ml @@ -710,6 +710,8 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct remove t source >>= fun () -> set t dest contents in + (* (hannes) we check whether we're in a change_and_push or not, since + nested change_and_push are not supported. *) match t.committed with | Some _ -> op t | None -> -- 2.47.0