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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
|
(*─────────────────────────────────────────────────────────────────────────────┐
│ SPDX-FileCopyrightText: 2025 toastal <https://toast.al/contact/> │
│ SPDX-License-Identifier: LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception │
└─────────────────────────────────────────────────────────────────────────────*)
open Name
type error = Error.lockfile_error
let filename = "lock.json"
let encode_tag = Util.Jsont.encode_tag
module File = struct
type t = {
url: URI.t;
mirrors: URI.t list;
}
[@@deriving show, eq, qcheck]
let [@inline]to_lock
~(models : Input.jg_models2)
({url; mirrors; _}: Input.File.t)
: t
=
let to_uri = Fun.compose URI.of_string (Input.Template.fill ~models) in
{
url = to_uri url;
mirrors = List.map to_uri mirrors;
}
let jsont : t Jsont.t =
let open Jsont in
Object.map
~kind: "File_lock"
(fun url mirrors -> {url; mirrors})
|> Object.mem "ur" URI.jsont ~enc: (fun i -> i.url)
|> Object.mem "ms" (list URI.jsont) ~enc: (fun i -> i.mirrors)
|> Object.finish
end
module Archive = struct
type t = {
url: URI.t;
mirrors: URI.t list;
}
[@@deriving show, eq, qcheck]
let [@inline]to_lock ~(models : Input.jg_models2) ({url; mirrors; _}: Input.Archive.t) : t =
let to_uri = Fun.compose URI.of_string (Input.Template.fill ~models) in
{
url = to_uri url;
mirrors = List.map to_uri mirrors;
}
let jsont : t Jsont.t =
let open Jsont in
Object.map
~kind: "Archive_lock"
(fun url mirrors -> {url; mirrors})
|> Object.mem "ur" URI.jsont ~enc: (fun i -> i.url)
|> Object.mem "ms" (list URI.jsont) ~enc: (fun i -> i.mirrors)
|> Object.finish
end
module Git = struct
(*
module Reference = struct
type t = Input.Git.Reference.t
[@@deriving show]
let jsont : t Jsont.t =
let open Jsont in
let enc = function
| `Branch brc -> encode_tag 0 string brc
| `Ref ref -> encode_tag 1 string ref
and dec = function
| [|tag; value|] ->
begin
match Result.bind (Json.decode' uint8 tag) (function
| 0 -> Json.decode' string value |> Result.map (fun t -> `Branch t)
| 1 -> Json.decode' string value |> Result.map (fun c -> `Ref c)
| n -> Error.msgf Meta.none "Unknown reference enum tag: %d" n
) with
| Ok v -> v
| Error (ctx, meta, kind) -> Error.raise ctx meta kind
end
| _ ->
Error.msgf Meta.none "Expected array of length 2"
in
map ~kind: "Git_reference_lock" ~enc ~dec (array json)
end
*)
type t = {
repository: URI.t;
mirrors: URI.t list;
(*reference: Reference.t;*)
datetime: string option;
submodules: bool;
lfs: bool;
latest_revision: string option;
}
[@@deriving show, eq, qcheck]
let [@inline]to_lock
~(models : Input.jg_models2)
({repository; mirrors; (*reference;*) datetime; submodules; lfs; latest_revision; _}: Input.Git.t)
: t
=
let to_uri = Fun.compose URI.of_string (Input.Template.fill ~models) in
{
repository = to_uri repository;
mirrors = List.map to_uri mirrors;
(*reference;*)
datetime;
submodules;
lfs;
latest_revision;
}
let jsont : t Jsont.t =
let open Jsont in
Object.map
~kind: "Git_lock"
(fun repository mirrors (*reference*) datetime submodules lfs latest_revision ->
{repository; mirrors; (*reference;*) datetime; submodules; lfs; latest_revision}
)
|> Object.mem "rp" URI.jsont ~enc: (fun i -> i.repository)
|> Object.mem "ms" (list URI.jsont) ~enc: (fun i -> i.mirrors)
(*|> Object.mem "rf" Reference.jsont ~enc: (fun i -> i.reference)*)
|> Object.mem "dt" (option string) ~enc: (fun i -> i.datetime)
|> Object.mem "sm" bool ~enc: (fun i -> i.submodules)
|> Object.mem "lf" bool ~enc: (fun i -> i.lfs)
|> Object.mem "lr" (option string) ~enc: (fun i -> i.latest_revision)
|> Object.finish
end
module Darcs = struct
module Reference = struct
type t = Input.Darcs.Reference.t
[@@deriving show, eq, qcheck]
let jsont : t Jsont.t =
let open Jsont in
let context_jsont =
let enc = function
| `Assumed (Some actx) -> encode_tag 0 string actx
| `Stated sctx -> encode_tag 1 string sctx
(* We can’t lock without a stable reference *)
| `Assumed None ->
Error.msgf Meta.none "Darcs context cannot be None when locking"
and dec = function
| [|tag; value|] ->
begin
match Result.bind (Json.decode' uint8 tag) (function
| 0 -> Json.decode' string value |> Result.map (fun a -> `Assumed (Some a))
| 1 -> Json.decode' string value |> Result.map (fun s -> `Stated s)
| n -> Error.msgf Meta.none "Unknown context enum tag: %d" n
) with
| Ok v -> v
| Error (ctx, meta, kind) -> Error.raise ctx meta kind
end
| _ ->
Error.msgf Meta.none "Expected array of length 2"
in
map ~kind: "Darcs_reference_context_lock" ~enc ~dec (array json)
in
let enc = function
| `Context ctx -> encode_tag 0 context_jsont ctx
| `Tag tag -> encode_tag 1 string tag
and dec = function
| [|tag; value|] ->
begin
match Result.bind (Json.decode' uint8 tag) (function
| 0 -> Json.decode' context_jsont value |> Result.map (fun c -> `Context c)
| 1 -> Json.decode' string value |> Result.map (fun t -> `Tag t)
| n -> Error.msgf Meta.none "Unknown reference enum tag: %d" n
) with
| Ok v -> v
| Error (ctx, meta, kind) -> Error.raise ctx meta kind
end
| _ ->
Error.msgf Meta.none "Expected array of length 2"
in
map ~kind: "Darcs_reference_lock" ~enc ~dec (array json)
end
type t = {
repository: URI.t;
mirrors: URI.t list;
datetime: string option;
(* Darcs isn’t like the other girls; we don’t have a simple stable reference point.
Either the tag or context can be used. *)
reference: Reference.t;
latest_weak_hash: string option;
}
[@@deriving show, eq, qcheck]
let [@inline]to_lock
~(models : Input.jg_models2)
({repository; mirrors; datetime; reference; latest_weak_hash; _}: Input.Darcs.t)
: t
=
let to_uri = Fun.compose URI.of_string (Input.Template.fill ~models) in
{
repository = to_uri repository;
mirrors = List.map to_uri mirrors;
datetime;
reference;
latest_weak_hash;
}
let jsont : t Jsont.t =
let open Jsont in
Object.map
~kind: "Darcs_lock"
(fun repository mirrors datetime reference latest_weak_hash ->
{repository; mirrors; datetime; reference; latest_weak_hash}
)
|> Object.mem "rp" URI.jsont ~enc: (fun i -> i.repository)
|> Object.mem "ms" (list URI.jsont) ~enc: (fun i -> i.mirrors)
|> Object.mem "dt" (option string) ~enc: (fun i -> i.datetime)
|> Object.mem "rf" Reference.jsont ~enc: (fun i -> i.reference)
|> Object.mem "lw" (option string) ~enc: (fun i -> i.latest_weak_hash)
|> Object.finish
end
module Pijul = struct
(*
module Reference = struct
type t = Input.Pijul.Reference.t
[@@deriving show]
let jsont : t Jsont.t =
let open Jsont in
let enc = function
| `Channel chn -> encode_tag 0 string chn
| `State stt -> encode_tag 1 string stt
| `Change chg -> encode_tag 2 string chg
and dec = function
| [|tag; value|] ->
begin
match Result.bind (Json.decode' uint8 tag) (function
| 0 -> Json.decode' string value |> Result.map (fun c -> `Channel c)
| 1 -> Json.decode' string value |> Result.map (fun c -> `State c)
| 2 -> Json.decode' string value |> Result.map (fun t -> `Change t)
| n -> Error.msgf Meta.none "Unknown reference enum tag: %d" n
) with
| Ok v -> v
| Error (ctx, meta, kind) -> Error.raise ctx meta kind
end
| _ ->
Error.msgf Meta.none "Expected array of length 2"
in
map ~kind: "Pijul_reference_lock" ~enc ~dec (array json)
end
*)
type t = {
remote: URI.t;
mirrors: URI.t list;
datetime: string option;
(*reference: Reference.t;*)
latest_state: string option;
}
[@@deriving show, eq, qcheck]
let [@inline]to_lock
~(models : Input.jg_models2)
({remote; mirrors; datetime; latest_state; _}: Input.Pijul.t)
: t
=
let to_uri = Fun.compose URI.of_string (Input.Template
|