Skip to content

Commit 1bf981b

Browse files
balatclaude
andcommitted
Update irmin.mli examples from Lwt to direct-style
Migrate the custom_merge and sync code examples to direct-style (remove open Lwt.Infix, >>=, >|=, Lwt_main.run, Lwt_list). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7ca40df commit 1bf981b

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

src/irmin/irmin.mli

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ type 'a diff = 'a Diff.t
290290
message, using the combinator exposed by {!Irmin.Type}:
291291
292292
{[
293-
open Lwt.Infix
294293
open Astring
295294
296295
let time = ref 0L
@@ -409,47 +408,44 @@ type 'a diff = 'a Diff.t
409408
let log_file = [ "local"; "debug" ]
410409
411410
let all_logs t =
412-
Store.find t log_file >|= function None -> Log.empty | Some l -> l
411+
match Store.find t log_file with None -> Log.empty | Some l -> l
413412
414413
(** Persist a new entry in the log. Pretty inefficient as it reads/writes
415414
the whole file every time. *)
416415
let log t fmt =
417416
Printf.ksprintf
418417
(fun message ->
419-
all_logs t >>= fun logs ->
418+
let logs = all_logs t in
420419
let logs = Log.add logs (Entry.v message) in
421420
Store.set_exn t ~info:(info "Adding a new entry") log_file logs)
422421
fmt
423422
424423
let print_logs name t =
425-
all_logs t >|= fun logs ->
424+
let logs = all_logs t in
426425
Fmt.pr "-----------\n%s:\n-----------\n%a%!" name (Irmin.Type.pp Log.t)
427426
logs
428427
429428
let main () =
430429
Config.init ();
431-
Store.Repo.v config >>= fun repo ->
432-
Store.main repo >>= fun t ->
430+
let repo = Store.Repo.v config in
431+
let t = Store.main repo in
433432
(* populate the log with some random messages *)
434-
Lwt_list.iter_s
433+
List.iter
435434
(fun msg -> log t "This is my %s " msg)
436-
[ "first"; "second"; "third" ]
437-
>>= fun () ->
435+
[ "first"; "second"; "third" ];
438436
Printf.printf "%s\n\n" what;
439-
print_logs "lca" t >>= fun () ->
440-
Store.clone ~src:t ~dst:"test" >>= fun x ->
441-
log x "Adding new stuff to x" >>= fun () ->
442-
log x "Adding more stuff to x" >>= fun () ->
443-
log x "More. Stuff. To x." >>= fun () ->
444-
print_logs "branch 1" x >>= fun () ->
445-
log t "I can add stuff on t also" >>= fun () ->
446-
log t "Yes. On t!" >>= fun () ->
447-
print_logs "branch 2" t >>= fun () ->
448-
Store.merge_into ~info:(info "Merging x into t") x ~into:t >>= function
437+
print_logs "lca" t;
438+
let x = Store.clone ~src:t ~dst:"test" in
439+
log x "Adding new stuff to x";
440+
log x "Adding more stuff to x";
441+
log x "More. Stuff. To x.";
442+
print_logs "branch 1" x;
443+
log t "I can add stuff on t also";
444+
log t "Yes. On t!";
445+
print_logs "branch 2" t;
446+
match Store.merge_into ~info:(info "Merging x into t") x ~into:t with
449447
| Ok () -> print_logs "merge" t
450448
| Error _ -> failwith "conflict!"
451-
452-
let () = Lwt_main.run (main ())
453449
]} *)
454450

455451
(** {2 Synchronization} *)
@@ -476,7 +472,6 @@ module Sync = Sync
476472
The complete code for the following can be found in [examples/sync.ml].
477473
478474
{[
479-
open Lwt.Infix
480475
module S = Irmin_unix.Git.FS.KV (Irmin.Contents.String)
481476
module Sync = Irmin.Sync (S)
482477
@@ -490,11 +485,11 @@ module Sync = Sync
490485
exit 1)
491486
492487
let test () =
493-
S.Repo.v config >>= S.main >>= fun t ->
494-
Sync.pull_exn t upstream `Set >>= fun () ->
495-
S.get t [ "README.md" ] >|= fun r -> Printf.printf "%s\n%!" r
496-
497-
let () = Lwt_main.run (test ())
488+
let repo = S.Repo.v config in
489+
let t = S.main repo in
490+
Sync.pull_exn t upstream `Set;
491+
let r = S.get t [ "README.md" ] in
492+
Printf.printf "%s\n%!" r
498493
]} *)
499494

500495
(** {1 Helpers} *)

0 commit comments

Comments
 (0)