Add copy to the storage
This commit is contained in:
parent
9c6d0bd684
commit
1a94bfd0e9
@ -25,6 +25,9 @@ val get: t -> key -> value option 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 remove_rec: t -> key -> t Lwt.t
|
||||
|
||||
|
@ -17,6 +17,7 @@ module type CONTEXT = sig
|
||||
val dir_mem: t -> key -> bool Lwt.t
|
||||
val get: t -> key -> value option 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 remove_rec: t -> key -> t Lwt.t
|
||||
val fold:
|
||||
|
@ -10,6 +10,7 @@ module type CONTEXT = sig
|
||||
val dir_mem: t -> key -> bool Lwt.t
|
||||
val get: t -> key -> value option 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 remove_rec: t -> key -> t Lwt.t
|
||||
val fold:
|
||||
|
@ -16,6 +16,7 @@ module Context = struct
|
||||
let dir_mem _ _ = assert false
|
||||
let get _ _ = assert false
|
||||
let set _ _ _ = assert false
|
||||
let copy _ ~from:_ ~to_:_ = assert false
|
||||
let del _ _ = assert false
|
||||
let remove_rec _ _ = assert false
|
||||
let fold _ _ ~init:_ ~f:_ = assert false
|
||||
|
@ -86,6 +86,10 @@ module Context = struct
|
||||
match raw_set m k None with
|
||||
| None -> 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 =
|
||||
match raw_get m k with
|
||||
|
@ -157,6 +157,13 @@ let remove_rec ctxt key =
|
||||
GitStore.Tree.remove ctxt.tree (data_key key) >>= fun 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 =
|
||||
GitStore.Tree.list ctxt.tree (data_key key) >>= fun keys ->
|
||||
Lwt_list.fold_left_s
|
||||
|
@ -45,6 +45,9 @@ val set: context -> key -> value -> t Lwt.t
|
||||
val del: 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:
|
||||
context -> key -> init:'a ->
|
||||
f:([ `Key of key | `Dir of key ] -> 'a -> 'a Lwt.t) ->
|
||||
|
Loading…
Reference in New Issue
Block a user