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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
open! Import
module Type = Repr
module Diff = Diff
module Content_addressable = Store.Content_addressable
module Contents = Contents
module Merge = Merge
module Branch = Branch
module Info = Info
module Dot = Dot.Make
module Hash = Hash
module Path = Path
module Perms = Perms
exception Closed
module CA_check_closed (CA : S.CONTENT_ADDRESSABLE_STORE_MAKER) :
S.CONTENT_ADDRESSABLE_STORE_MAKER =
functor
(K : Hash.S)
(V : Type.S)
->
struct
module S = CA (K) (V)
type 'a t = { closed : bool ref; t : 'a S.t }
type key = S.key
type value = S.value
let check_not_closed t = if !(t.closed) then raise Closed
let mem t k =
check_not_closed t;
S.mem t.t k
let find t k =
check_not_closed t;
S.find t.t k
let add t v =
check_not_closed t;
S.add t.t v
let unsafe_add t k v =
check_not_closed t;
S.unsafe_add t.t k v
let batch t f =
check_not_closed t;
S.batch t.t (fun w -> f { t = w; closed = t.closed })
let v conf =
let+ t = S.v conf in
{ closed = ref false; t }
let close t =
if !(t.closed) then Lwt.return_unit
else (
t.closed := true;
S.close t.t)
let clear t =
check_not_closed t;
S.clear t.t
end
module AW_check_closed (AW : S.ATOMIC_WRITE_STORE_MAKER) :
S.ATOMIC_WRITE_STORE_MAKER =
functor
(K : Type.S)
(V : Type.S)
->
struct
module S = AW (K) (V)
type t = { closed : bool ref; t : S.t }
type key = S.key
type value = S.value
let check_not_closed t = if !(t.closed) then raise Closed
let mem t k =
check_not_closed t;
S.mem t.t k
let find t k =
check_not_closed t;
S.find t.t k
let set t k v =
check_not_closed t;
S.set t.t k v
let test_and_set t k ~test ~set =
check_not_closed t;
S.test_and_set t.t k ~test ~set
let remove t k =
check_not_closed t;
S.remove t.t k
let list t =
check_not_closed t;
S.list t.t
type watch = S.watch
let watch t ?init f =
check_not_closed t;
S.watch t.t ?init f
let watch_key t k ?init f =
check_not_closed t;
S.watch_key t.t k ?init f
let unwatch t w =
check_not_closed t;
S.unwatch t.t w
let v conf =
let+ t = S.v conf in
{ closed = ref false; t }
let close t =
if !(t.closed) then Lwt.return_unit
else (
t.closed := true;
S.close t.t)
let clear t =
check_not_closed t;
S.clear t.t
end
module Maker_ext
(CA : S.CONTENT_ADDRESSABLE_STORE_MAKER)
(AW : S.ATOMIC_WRITE_STORE_MAKER)
(N : Node.Maker)
(CT : Commit.Maker) =
struct
type endpoint = unit
module Make
(M : S.METADATA)
(C : Contents.S)
(P : Path.S)
(B : Branch.S)
(H : Hash.S) =
struct
module CA = CA_check_closed (CA)
module AW = AW_check_closed (AW)
module X = struct
module Hash = H
module Contents = struct
module CA = struct
module Key = Hash
module Val = C
include CA (Key) (Val)
end
include Contents.Store (CA)
end
module Node = struct
module CA = struct
module Key = Hash
module Val = N (H) (P) (M)
include CA (Key) (Val)
end
include Node.Store (Contents) (P) (M) (CA)
end
module Commit = struct
module CA = struct
module Key = Hash
module Val = CT (H)
include CA (Key) (Val)
end
include Commit.Store (Node) (CA)
end
module Branch = struct
module Key = B
module Val = H
include AW (Key) (Val)
end
module Slice = Slice.Make (Contents) (Node) (Commit)
module Sync = Sync.None (H) (B)
module Repo = struct
type t = {
config : Conf.t;
contents : read Contents.t;
nodes : read Node.t;
commits : read Commit.t;
branch : Branch.t;
}
let contents_t t = t.contents
let node_t t = t.nodes
let commit_t t = t.commits
let branch_t t = t.branch
let batch t f =
Contents.CA.batch t.contents @@ fun c ->
Node.CA.batch (snd t.nodes) @@ fun n ->
Commit.CA.batch (snd t.commits) @@ fun ct ->
let contents_t = c in
let node_t = (contents_t, n) in
let commit_t = (node_t, ct) in
f contents_t node_t commit_t
let v config =
let* contents = Contents.CA.v config in
let* nodes = Node.CA.v config in
let* commits = Commit.CA.v config in
let nodes = (contents, nodes) in
let commits = (nodes, commits) in
let+ branch = Branch.v config in
{ contents; nodes; commits; branch; config }
let close t =
Contents.CA.close t.contents >>= fun () ->
Node.CA.close (snd t.nodes) >>= fun () ->
Commit.CA.close (snd t.commits) >>= fun () -> Branch.close t.branch
end
end
include Store.Make (X)
end
end
module Make_ext
(CA : S.CONTENT_ADDRESSABLE_STORE_MAKER)
(AW : S.ATOMIC_WRITE_STORE_MAKER)
(M : S.METADATA)
(C : Contents.S)
(P : Path.S)
(B : Branch.S)
(H : Hash.S)
(N : Node.S
with type metadata = M.t
and type hash = H.t
and type step = P.step)
(CT : Commit.S with type hash = H.t) =
struct
module CA = CA_check_closed (CA)
module AW = AW_check_closed (AW)
module X = struct
module Hash = H
module Contents = struct
module CA = struct
module Key = Hash
module Val = C
include CA (Key) (Val)
end
include Contents.Store (CA)
end
module Node = struct
module CA = struct
module Key = Hash
module Val = N
include CA (Key) (Val)
end
include Node.Store (Contents) (P) (M) (CA)
end
module Commit = struct
module CA = struct
module Key = Hash
module Val = CT
include CA (Key) (Val)
end
include Commit.Store (Node) (CA)
end
module Branch = struct
module Key = B
module Val = H
include AW (Key) (Val)
end
module Slice = Slice.Make (Contents) (Node) (Commit)
module Sync = Sync.None (H) (B)
module Repo = struct
type t = {
config : Conf.t;
contents : read Contents.t;
nodes : read Node.t;
commits : read Commit.t;
branch : Branch.t;
}
let contents_t t = t.contents
let node_t t = t.nodes
let commit_t t = t.commits
let branch_t t = t.branch
let batch t f =
Contents.CA.batch t.contents @@ fun c ->
Node.CA.batch (snd t.nodes) @@ fun n ->
Commit.CA.batch (snd t.commits) @@ fun ct ->
let contents_t = c in
let node_t = (contents_t, n) in
let commit_t = (node_t, ct) in
f contents_t node_t commit_t
let v config =
let* contents = Contents.CA.v config in
let* nodes = Node.CA.v config in
let* commits = Commit.CA.v config in
let nodes = (contents, nodes) in
let commits = (nodes, commits) in
let+ branch = Branch.v config in
{ contents; nodes; commits; branch; config }
let close t =
Contents.CA.close t.contents >>= fun () ->
Node.CA.close (snd t.nodes) >>= fun () ->
Commit.CA.close (snd t.commits) >>= fun () -> Branch.close t.branch
end
end
include Store.Make (X)
end
module Make
(CA : S.CONTENT_ADDRESSABLE_STORE_MAKER)
(AW : S.ATOMIC_WRITE_STORE_MAKER)
(M : S.METADATA)
(C : Contents.S)
(P : Path.S)
(B : Branch.S)
(H : Hash.S) =
struct
module N = Node.Make (H) (P) (M)
module CT = Commit.Make (H)
include Make_ext (CA) (AW) (M) (C) (P) (B) (H) (N) (CT)
end
module Of_private = Store.Make
module type CONTENT_ADDRESSABLE_STORE = S.CONTENT_ADDRESSABLE_STORE
module type APPEND_ONLY_STORE = S.APPEND_ONLY_STORE
module type ATOMIC_WRITE_STORE = S.ATOMIC_WRITE_STORE
module type TREE = Tree.S
module type S = Store.S
type config = Conf.t
type 'a diff = 'a Diff.t
module type CONTENT_ADDRESSABLE_STORE_MAKER = S.CONTENT_ADDRESSABLE_STORE_MAKER
module type APPEND_ONLY_STORE_MAKER = S.APPEND_ONLY_STORE_MAKER
module type ATOMIC_WRITE_STORE_MAKER = S.ATOMIC_WRITE_STORE_MAKER
module type S_MAKER = Store.MAKER
module type KV =
S with type key = string list and type step = string and type branch = string
module type KV_MAKER = functor (C : Contents.S) -> KV with type contents = C.t
module Private = struct
module Conf = Conf
module Node = Node
module Commit = Commit
module Slice = Slice
module Sync = Sync
module Sigs = S
module type S = Private.S
module Watch = Watch
module Lock = Lock
module Lru = Lru
end
let version = Version.current
module type SYNC = Sync_ext.SYNC_STORE
module Sync = Sync_ext.Make
type remote = S.remote = ..
let remote_store (type t) (module M : S with type t = t) (t : t) =
let module X : Store.S with type t = t = M in
Sync_ext.remote_store (module X) t
module Metadata = struct
module type S = S.METADATA
module None = Node.No_metadata
end
module Json_tree = Store.Json_tree
module Export_for_backends = Export_for_backends