diff --git a/examples/client_batch.ml b/examples/client_batch.ml index 8f647be66e..8889797ab0 100644 --- a/examples/client_batch.ml +++ b/examples/client_batch.ml @@ -18,11 +18,12 @@ module Store = Irmin_mem.KV.Make (Irmin.Contents.String) module Client = Irmin_client_unix.Make (Store) module Error = Irmin_client.Error -let main () = +let main env = Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in let info () = Client.Info.empty in let uri = Uri.of_string Sys.argv.(1) in - let client = Client.connect ~sw uri in + let client = Client.connect ~sw ~fs uri in let main = Client.main client in Client.set_exn ~info main [ "testing" ] "testing"; @@ -45,4 +46,4 @@ let main () = let () = Eio_main.run @@ fun env -> - Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main () + Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main env diff --git a/examples/custom_graphql.ml b/examples/custom_graphql.ml index 5bd484d5bd..9a867f733b 100644 --- a/examples/custom_graphql.ml +++ b/examples/custom_graphql.ml @@ -106,11 +106,12 @@ end module Server = Irmin_graphql_unix.Server.Make_ext (Store) (Remote) (Custom_types) -let main () = +let main env = Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in Config.init (); let config = Irmin_git.config Config.root in - let repo = Store.Repo.v ~sw config in + let repo = Store.Repo.v ~sw ~fs config in let server = Server.v repo in let src = "localhost" in let port = 9876 in @@ -123,4 +124,4 @@ let main () = let () = Eio_main.run @@ fun env -> - Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main () + Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main env diff --git a/examples/custom_merge.ml b/examples/custom_merge.ml index 05296d1e54..036c25d3de 100644 --- a/examples/custom_merge.ml +++ b/examples/custom_merge.ml @@ -137,10 +137,11 @@ let print_logs name t = let logs = all_logs t in Fmt.pr "-----------\n%s:\n-----------\n%a%!" name (Irmin.Type.pp Log.t) logs -let main () = +let main env = Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in Config.init (); - let repo = Store.Repo.v ~sw config in + let repo = Store.Repo.v ~sw ~fs config in let t = Store.main repo in (* populate the log with some random messages *) @@ -162,4 +163,4 @@ let main () = let () = Eio_main.run @@ fun env -> - Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main () + Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main env diff --git a/examples/custom_storage.ml b/examples/custom_storage.ml index 245c17368f..72ffd87cfd 100644 --- a/examples/custom_storage.ml +++ b/examples/custom_storage.ml @@ -48,7 +48,7 @@ functor (** Initialisation / Closing *) - let v ~sw:_ config = + let v ~sw:_ ~fs:_ config = let init_size = Irmin.Backend.Conf.get config Hashtbl_config.init_size in { t = Tbl.create init_size; l = Eio.Mutex.create () } @@ -86,9 +86,10 @@ module Store = let config ?(config = Hashtbl_config.empty) ?(init_size = 42) () = Irmin.Backend.Conf.add config Hashtbl_config.init_size init_size -let main () = +let main env = Eio.Switch.run @@ fun sw -> - let repo = Store.Repo.v ~sw (config ()) in + let fs = Eio.Stdenv.fs env in + let repo = Store.Repo.v ~sw ~fs (config ()) in let main = Store.main repo in let info () = Store.Info.v 0L in let key = "Hello" in @@ -98,4 +99,4 @@ let main () = let () = Eio_main.run @@ fun env -> - Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main () + Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main env diff --git a/examples/deploy.ml b/examples/deploy.ml index 4341a290c9..dec63addd2 100644 --- a/examples/deploy.ml +++ b/examples/deploy.ml @@ -80,7 +80,7 @@ let revert repo = Eio_unix.sleep 2.; Store.Head.set prod h2) -let main () = +let main env = let cmd = Sys.argv.(0) in let help () = Printf.eprintf @@ -102,18 +102,19 @@ let main () = cmd cmd cmd cmd Config.root in Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in if Array.length Sys.argv <> 2 then help () else match Sys.argv.(1) with | "provision" -> - (let repo = Store.Repo.v ~sw config in + (let repo = Store.Repo.v ~sw ~fs config in provision repo); Printf.printf "The VM is now provisioned. Run `%s configure` to simulate a sysadmin \n\ configuration.\n" cmd | "configure" -> - (let repo = Store.Repo.v ~sw config in + (let repo = Store.Repo.v ~sw ~fs config in configure repo); Printf.printf "The VM is now configured. Run `%s attack` to simulate an attack by \ @@ -121,17 +122,17 @@ let main () = intruder.\n" cmd | "attack" -> - (let repo = Store.Repo.v ~sw config in + (let repo = Store.Repo.v ~sw ~fs config in attack repo); Printf.printf "The VM has been attacked. Run `%s revert` to revert the VM state to \ a safe one.\n" cmd | "revert" -> - let repo = Store.Repo.v ~sw config in + let repo = Store.Repo.v ~sw ~fs config in revert repo | _ -> help () let () = Eio_main.run @@ fun env -> - Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main () + Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main env diff --git a/examples/fold.ml b/examples/fold.ml index 027c37ea47..b92774d853 100644 --- a/examples/fold.ml +++ b/examples/fold.ml @@ -62,11 +62,12 @@ end = struct | None -> failwith "no kind" end -let main () = +let main env = let ps name = Fmt.(pf stdout "\n%s\n" name) in ps "Demo of how tree folders visit nodes."; Eio.Switch.run @@ fun sw -> - let repo = Store.Repo.v ~sw config in + let fs = Eio.Stdenv.fs env in + let repo = Store.Repo.v ~sw ~fs config in let main_b = Store.main repo in Store.set_exn ~info:(info "add c1") main_b [ "c1" ] "c1"; Store.set_exn ~info:(info "add c2") main_b [ "c2" ] "c2"; @@ -91,4 +92,4 @@ let main () = let () = Eio_main.run @@ fun env -> - Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main () + Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main env diff --git a/examples/irmin-pack/gc.ml b/examples/irmin-pack/gc.ml index ad3d160e57..c626beab70 100644 --- a/examples/irmin-pack/gc.ml +++ b/examples/irmin-pack/gc.ml @@ -160,11 +160,13 @@ let run_gc domain_mgr config repo tracker = let () = Store.split repo in Tracker.mark_next_gc_commit tracker -let run_experiment domain_mgr config = +let run_experiment env config = Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in + let domain_mgr = Eio.Stdenv.domain_mgr env in let num_of_commits = 200_000 in let gc_every = 1_000 in - let repo = Store.Repo.v ~sw config in + let repo = Store.Repo.v ~sw ~fs config in let tracker = Tracker.v () in (* Create commits *) let _ = @@ -190,9 +192,7 @@ let run_experiment domain_mgr config = let () = Eio_main.run @@ fun env -> - let domain_mgr = Eio.Stdenv.domain_mgr env in - Irmin_pack_unix.Io.set_env (Eio.Stdenv.fs env); Printf.printf "== RUN 1: deleting discarded data ==\n"; - run_experiment domain_mgr Repo_config.config; + run_experiment env Repo_config.config; Printf.printf "== RUN 2: archiving discarded data ==\n"; - run_experiment domain_mgr Repo_config.config_with_lower + run_experiment env Repo_config.config_with_lower diff --git a/examples/irmin-pack/kv.ml b/examples/irmin-pack/kv.ml index 8f48978a69..7586d06a62 100644 --- a/examples/irmin-pack/kv.ml +++ b/examples/irmin-pack/kv.ml @@ -68,11 +68,12 @@ end module StoreMaker = Irmin_pack_unix.KV (Conf) module Store = StoreMaker.Make (Irmin.Contents.String) -let main () = +let main env = (* Create a switch *) Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in (* Instantiate a repository *) - let repo = Store.Repo.v ~sw Repo_config.config in + let repo = Store.Repo.v ~sw ~fs Repo_config.config in (* Get the store from the main branch. *) let store = Store.main repo in @@ -96,6 +97,5 @@ let setup_logs () = let () = Eio_main.run @@ fun env -> - Irmin_pack_unix.Io.set_env (Eio.Stdenv.fs env); setup_logs (); - main () + main env diff --git a/examples/irmin_git_store.ml b/examples/irmin_git_store.ml index e29b7c1fb7..00949adfc7 100644 --- a/examples/irmin_git_store.ml +++ b/examples/irmin_git_store.ml @@ -30,11 +30,12 @@ let read_exn t k = print_endline msg; Store.get t k -let main () = +let main env = Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in Config.init (); let config = Irmin_git.config ~bare:true Config.root in - let repo = Store.Repo.v ~sw config in + let repo = Store.Repo.v ~sw ~fs config in let t = Store.main repo in update t [ "root"; "misc"; "1.txt" ] "Hello world!"; update t [ "root"; "misc"; "2.txt" ] "Hi!"; @@ -53,16 +54,16 @@ let main () = let _ = read_exn t [ "root"; "misc"; "3.txt" ] in () -let main () = +let main env = Printf.printf "This example creates a Git repository in %s and use it to read \n\ and write data:\n" Config.root; let _ = Sys.command (Printf.sprintf "rm -rf %s" Config.root) in - main (); + main env; Printf.printf "You can now run `cd %s && tig` to inspect the store.\n" Config.root let () = Eio_main.run @@ fun env -> - Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main () + Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main env diff --git a/examples/merkle_proofs.md b/examples/merkle_proofs.md index 5f2e0f79ad..dacb87a991 100644 --- a/examples/merkle_proofs.md +++ b/examples/merkle_proofs.md @@ -29,6 +29,7 @@ module Store = Irmin_git_unix.FS.KV (Contents) let eio_run fn = Eio_main.run @@ fun env -> Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in Lwt_eio.with_event_loop ~clock:env#clock (fn ~sw) ``` @@ -36,7 +37,7 @@ Open a repo. ```ocaml # let config = Irmin_git.config ~bare:true "./tmp-irmin/test" - let repo = eio_run @@ fun ~sw _ -> Store.Repo.v ~sw config;; + let repo = eio_run @@ fun ~sw _ -> Store.Repo.v ~sw ~fs config;; val config : Irmin.config = val repo : Store.repo = ``` diff --git a/examples/plugin/plugin.ml b/examples/plugin/plugin.ml index c2af8f8cce..4f063f0328 100644 --- a/examples/plugin/plugin.ml +++ b/examples/plugin/plugin.ml @@ -48,7 +48,6 @@ let () = @@ Logs.Src.list () let () = - Eio_main.run @@ fun env -> - Irmin_pack_unix.Io.set_env (Eio.Stdenv.fs env); + Eio_main.run @@ fun _env -> Resolver.Contents.add ~default:true "int" (module Int); Resolver.Store.add ~default:true "mem-int" (Fixed store) diff --git a/examples/process.ml b/examples/process.ml index a3497a59ad..be49b7e4ce 100644 --- a/examples/process.ml +++ b/examples/process.ml @@ -110,10 +110,11 @@ let info image message () = let main = branch images.(0) -let init () = +let init env = Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in Config.init (); - let repo = Store.Repo.v ~sw config in + let repo = Store.Repo.v ~sw ~fs config in let t = Store.of_branch repo main in Store.set_exn t ~info:(info images.(0) "init") [ "0" ] "0"; List.iter @@ -125,8 +126,9 @@ let init () = let random_array a = a.(Random.int (Array.length a)) let random_list l = random_array (Array.of_list l) -let rec process image = +let rec process env image = Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in let id = branch image in Printf.printf "Processing %s\n%!" id; let actions = random_list image.actions in @@ -135,7 +137,7 @@ let rec process image = with _ -> ([ "log"; id; "0" ], fun () -> id ^ string_of_int (Random.int 10)) in - let repo = Store.Repo.v ~sw config in + let repo = Store.Repo.v ~sw ~fs config in let t = Store.of_branch repo id in Store.set_exn t ~info:(info image actions.message) key (value ()); let () = @@ -153,7 +155,7 @@ let rec process image = | Error _ -> failwith "conflict!") in Eio_unix.sleep (max 0.1 (Random.float 0.3)); - process image + process env image let rec protect fn x () = try fn x @@ -166,10 +168,11 @@ let rec watchdog () = Eio_unix.sleep 1.; watchdog () -let main () = - init (); - Eio.Fiber.any (watchdog :: List.map (protect process) (Array.to_list images)) +let main env = + init env; + Eio.Fiber.any + (watchdog :: List.map (protect (process env)) (Array.to_list images)) let () = Eio_main.run @@ fun env -> - Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main () + Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main env diff --git a/examples/push.ml b/examples/push.ml index bc5c05df20..af245b9ef5 100644 --- a/examples/push.ml +++ b/examples/push.ml @@ -29,11 +29,12 @@ let headers = let e = Cohttp.Header.of_list [] in Cohttp.Header.add_authorization e (`Basic (user, token)) -let test () = +let test env = Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in Config.init (); let config = Irmin_git.config Config.root in - let repo = Store.Repo.v ~sw config in + let repo = Store.Repo.v ~sw ~fs config in let t = Store.main repo in let remote = Store.remote ~headers url () in let _ = Sync.pull_exn t remote `Set in @@ -52,4 +53,4 @@ let test () = let () = Eio_main.run @@ fun env -> - Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> test () + Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> test env diff --git a/examples/readme.ml b/examples/readme.ml index fffb45c670..948276053b 100644 --- a/examples/readme.ml +++ b/examples/readme.ml @@ -10,11 +10,12 @@ let author = "Example " (* Commit information *) let info fmt = Irmin_git_unix.info ~author fmt -let main () = +let main env = (* Create the switch *) Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in (* Open the repo *) - let repo = Store.Repo.v ~sw config in + let repo = Store.Repo.v ~sw ~fs config in (* Load the main branch *) let t = Store.main repo in @@ -29,4 +30,4 @@ let main () = (* Run the program *) let () = Eio_main.run @@ fun env -> - Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main () + Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main env diff --git a/examples/server.ml b/examples/server.ml index 42574fc489..9f48d67d9d 100644 --- a/examples/server.ml +++ b/examples/server.ml @@ -20,24 +20,26 @@ module Server = Irmin_server_unix.Make (Store) let info () = Irmin.Info.Default.empty -let init () = +let init env = Eio.Switch.run @@ fun sw -> - let repo = Store.Repo.v ~sw (Irmin_mem.config ()) in + let fs = Eio.Stdenv.fs env in + let repo = Store.Repo.v ~sw ~fs (Irmin_mem.config ()) in let main = Store.main repo in Store.set_exn ~info main [ "foo" ] "bar" -let main () = +let main env = Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in let uri = Uri.of_string Sys.argv.(1) in let config = Irmin_mem.config () in let dashboard = `TCP (`Port 1234) in Lwt_eio.run_lwt @@ fun () -> - let* server = Server.v ~sw ~uri ~dashboard config in + let* server = Server.v ~sw ~fs ~uri ~dashboard config in Format.printf "Listening on %a@." Uri.pp uri; Server.serve server let () = Eio_main.run @@ fun env -> Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> - init (); - main () + init env; + main env diff --git a/examples/sync.ml b/examples/sync.ml index 3e5cac7daa..da7681f745 100644 --- a/examples/sync.ml +++ b/examples/sync.ml @@ -23,11 +23,12 @@ let path = module Store = Irmin_git_unix.FS.KV (Irmin.Contents.String) module Sync = Irmin.Sync.Make (Store) -let test () = +let test env = Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in Config.init (); let config = Irmin_git.config Config.root in - let repo = Store.Repo.v ~sw config in + let repo = Store.Repo.v ~sw ~fs config in let t = Store.of_branch repo "master" in let upstream = Store.remote path () in let _ = Sync.pull_exn t upstream `Set in @@ -40,4 +41,4 @@ let test () = let () = Eio_main.run @@ fun env -> - Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> test () + Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> test env diff --git a/examples/trees.ml b/examples/trees.ml index 9f4f478ad2..e94fd4e9ab 100644 --- a/examples/trees.ml +++ b/examples/trees.ml @@ -50,15 +50,16 @@ let t_of_tree v = let t2s = List.rev (List.sort compare t2s) in List.fold_left aux [] t2s -let main () = +let main env = Eio.Switch.run @@ fun sw -> + let fs = Eio.Stdenv.fs env in Config.init (); let config = Irmin_git.config ~bare:false Config.root in let t = [ { x = "foo"; y = 3 }; { x = "bar"; y = 5 }; { x = "too"; y = 10 } ] in let v = tree_of_t t in - let repo = Store.Repo.v ~sw config in + let repo = Store.Repo.v ~sw ~fs config in let t = Store.main repo in Store.set_tree_exn t ~info:(info "update a/b") [ "a"; "b" ] v; let v = Store.get_tree t [ "a"; "b" ] in @@ -70,4 +71,4 @@ let main () = let () = Eio_main.run @@ fun env -> - Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main () + Lwt_eio.with_event_loop ~clock:env#clock @@ fun _ -> main env