Add copy to the storage

This commit is contained in:
Pierre Chambart 2018-02-20 19:12:02 +01:00 committed by Grégoire Henry
parent 9c6d0bd684
commit 1a94bfd0e9
7 changed files with 20 additions and 0 deletions

View File

@ -25,6 +25,9 @@ val get: t -> key -> value option Lwt.t
val set: t -> key -> value -> t Lwt.t val set: t -> key -> value -> t Lwt.t
(** [copy] returns None if the [from] key is not bound *)
val copy: t -> from:key -> to_:key -> t option Lwt.t
val del: t -> key -> t Lwt.t val del: t -> key -> t Lwt.t
val remove_rec: t -> key -> t Lwt.t val remove_rec: t -> key -> t Lwt.t

View File

@ -17,6 +17,7 @@ module type CONTEXT = sig
val dir_mem: t -> key -> bool Lwt.t val dir_mem: t -> key -> bool Lwt.t
val get: t -> key -> value option Lwt.t val get: t -> key -> value option Lwt.t
val set: t -> key -> value -> t Lwt.t val set: t -> key -> value -> t Lwt.t
val copy: t -> from:key -> to_:key -> t option Lwt.t
val del: t -> key -> t Lwt.t val del: t -> key -> t Lwt.t
val remove_rec: t -> key -> t Lwt.t val remove_rec: t -> key -> t Lwt.t
val fold: val fold:

View File

@ -10,6 +10,7 @@ module type CONTEXT = sig
val dir_mem: t -> key -> bool Lwt.t val dir_mem: t -> key -> bool Lwt.t
val get: t -> key -> value option Lwt.t val get: t -> key -> value option Lwt.t
val set: t -> key -> value -> t Lwt.t val set: t -> key -> value -> t Lwt.t
val copy: t -> from:key -> to_:key -> t option Lwt.t
val del: t -> key -> t Lwt.t val del: t -> key -> t Lwt.t
val remove_rec: t -> key -> t Lwt.t val remove_rec: t -> key -> t Lwt.t
val fold: val fold:

View File

@ -16,6 +16,7 @@ module Context = struct
let dir_mem _ _ = assert false let dir_mem _ _ = assert false
let get _ _ = assert false let get _ _ = assert false
let set _ _ _ = assert false let set _ _ _ = assert false
let copy _ ~from:_ ~to_:_ = assert false
let del _ _ = assert false let del _ _ = assert false
let remove_rec _ _ = assert false let remove_rec _ _ = assert false
let fold _ _ ~init:_ ~f:_ = assert false let fold _ _ ~init:_ ~f:_ = assert false

View File

@ -86,6 +86,10 @@ module Context = struct
match raw_set m k None with match raw_set m k None with
| None -> Lwt.return m | None -> Lwt.return m
| Some m -> Lwt.return m | Some m -> Lwt.return m
let copy m ~from ~to_ =
match raw_get m from with
| None -> Lwt.return_none
| Some v -> Lwt.return (raw_set m to_ (Some v))
let fold m k ~init ~f = let fold m k ~init ~f =
match raw_get m k with match raw_get m k with

View File

@ -157,6 +157,13 @@ let remove_rec ctxt key =
GitStore.Tree.remove ctxt.tree (data_key key) >>= fun tree -> GitStore.Tree.remove ctxt.tree (data_key key) >>= fun tree ->
Lwt.return { ctxt with tree } Lwt.return { ctxt with tree }
let copy ctxt ~from ~to_ =
GitStore.Tree.find_tree ctxt.tree (data_key from) >>= function
| None -> Lwt.return_none
| Some sub_tree ->
GitStore.Tree.add_tree ctxt.tree (data_key to_) sub_tree >>= fun tree ->
Lwt.return_some { ctxt with tree }
let fold ctxt key ~init ~f = let fold ctxt key ~init ~f =
GitStore.Tree.list ctxt.tree (data_key key) >>= fun keys -> GitStore.Tree.list ctxt.tree (data_key key) >>= fun keys ->
Lwt_list.fold_left_s Lwt_list.fold_left_s

View File

@ -45,6 +45,9 @@ val set: context -> key -> value -> t Lwt.t
val del: context -> key -> t Lwt.t val del: context -> key -> t Lwt.t
val remove_rec: context -> key -> t Lwt.t val remove_rec: context -> key -> t Lwt.t
(** [copy] returns None if the [from] key is not bound *)
val copy: context -> from:key -> to_:key -> context option Lwt.t
val fold: val fold:
context -> key -> init:'a -> context -> key -> init:'a ->
f:([ `Key of key | `Dir of key ] -> 'a -> 'a Lwt.t) -> f:([ `Key of key | `Dir of key ] -> 'a -> 'a Lwt.t) ->