blob: 68842192c89666cd8e44d9410ce08bdd7712aed9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
module BranchValue = Merkle.StringKey (* FIXME *)
type branch = string
module Make (S : Abstract.Storage.STORAGE) = struct
module I = Merkle.Interface (S) (Merkle.StringKey) (BranchValue)
module SI = Storage.Make (S)
type manager = { storage: S.connection; head: I.node Atomic.t }
let initialize storage addr =
let open Utilities.Result in
SI.with_transaction storage (fun tx ->
let* head = I.find tx addr in
Ok { storage; head = Option.value head ~default:I.empty |> Atomic.make })
let fetch { storage; head } branch_name =
SI.with_transaction storage (fun tx ->
let head = Atomic.get head in
I.lookup tx branch_name head)
let update ({ storage; head } as manager) branch_name f =
let open Utilities.Result in
SI.with_transaction storage (fun tx ->
let* new_head = Utilities.Atomic.mswap head (fun head ->
let* branch = I.lookup tx branch_name head in
f branch) in
Ok { manager with head = new_head })
end
|