Monorepo management for opam overlays
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Rename 'create' to 'v' for idiomatic OCaml constructors

Fix [E332] Prefer 'v' Constructor:
- Config.create -> Config.v
- Package.create -> Package.v
- Remote_cache.create -> Remote_cache.v
- Sync_progress.create -> Sync_progress.v

Updated all call sites and documentation examples.

+58 -58
+1 -1
lib/config.ml
··· 114 114 let domain = String.sub handle (i + 1) (String.length handle - i - 1) in 115 115 "git." ^ domain 116 116 117 - let create ~root ~handle ?knot ?(packages = []) ?(paths = default_paths) () = 117 + let v ~root ~handle ?knot ?(packages = []) ?(paths = default_paths) () = 118 118 let knot = 119 119 match knot with Some k -> k | None -> default_knot_from_handle handle 120 120 in
+1 -1
lib/config.mli
··· 122 122 123 123 (** {1 Construction} *) 124 124 125 - val create : 125 + val v : 126 126 root:Fpath.t -> 127 127 handle:string -> 128 128 ?knot:string ->
+1 -1
lib/opam_repo.ml
··· 116 116 let dev_repo = normalize_git_url url in 117 117 let depends = depends opamfile.file_contents in 118 118 let synopsis = synopsis opamfile.file_contents in 119 - Ok (Package.create ~name ~version ~dev_repo ~depends ?synopsis ()) 119 + Ok (Package.v ~name ~version ~dev_repo ~depends ?synopsis ()) 120 120 with 121 121 | Eio.Io _ as e -> Error (Io_error (Printexc.to_string e)) 122 122 | exn -> Error (Parse_error (path_str, Printexc.to_string exn)))
+1 -1
lib/package.ml
··· 7 7 synopsis : string option; 8 8 } 9 9 10 - let create ~name ~version ~dev_repo ?branch ?(depends = []) ?synopsis () = 10 + let v ~name ~version ~dev_repo ?branch ?(depends = []) ?synopsis () = 11 11 { name; version; dev_repo; branch; depends; synopsis } 12 12 13 13 let name t = t.name
+1 -1
lib/package.mli
··· 11 11 12 12 (** {1 Constructors} *) 13 13 14 - val create : 14 + val v : 15 15 name:string -> 16 16 version:string -> 17 17 dev_repo:Uri.t ->
+1 -1
lib/remote_cache.ml
··· 61 61 in 62 62 String.concat "\n" lines ^ "\n" 63 63 64 - let create ?(ttl = default_ttl) ~now () = 64 + let v ?(ttl = default_ttl) ~now () = 65 65 let tbl = Hashtbl.create 32 in 66 66 { tbl; ttl; now } 67 67
+3 -3
lib/remote_cache.mli
··· 22 22 {[ 23 23 let time = ref 0.0 in 24 24 let now () = !time in 25 - let cache = Remote_cache.create ~ttl:60.0 ~now () in 25 + let cache = Remote_cache.v ~ttl:60.0 ~now () in 26 26 27 27 (* Set a value *) 28 28 let url = Uri.of_string "https://github.com/ocaml/ocaml.git" in ··· 45 45 val default_ttl : float 46 46 (** Default TTL in seconds (300.0 = 5 minutes). *) 47 47 48 - val create : ?ttl:float -> now:(unit -> float) -> unit -> t 49 - (** [create ~ttl ~now ()] creates a new empty cache. 48 + val v : ?ttl:float -> now:(unit -> float) -> unit -> t 49 + (** [v ~ttl ~now ()] creates a new empty cache. 50 50 51 51 @param ttl Time-to-live in seconds (default {!default_ttl}). 52 52 @param now Function to get current time in seconds. *)
+2 -2
lib/sync_progress.ml
··· 12 12 phase_name : string; 13 13 } 14 14 15 - let create ~total phase_name = 15 + let v ~total phase_name = 16 16 let msg = Fmt.str "%s (0/%d)" phase_name total in 17 17 let progress = Tty.Progress.create ~total msg in 18 18 { progress; completed = Atomic.make 0; total; phase_name } ··· 40 40 module Active : S with type t = t = struct 41 41 type nonrec t = t 42 42 43 - let create = create 43 + let create = v 44 44 let tick = tick 45 45 let clear = clear 46 46 let finish = finish
+3 -3
lib/sync_progress.mli
··· 7 7 {2 Usage} 8 8 9 9 {[ 10 - let progress = Sync_progress.create ~total:10 "Fetching" in 10 + let progress = Sync_progress.v ~total:10 "Fetching" in 11 11 List.iter 12 12 (fun name -> 13 13 do_work name; ··· 31 31 type t 32 32 (** Progress state for a sync phase. *) 33 33 34 - val create : total:int -> string -> t 35 - (** [create ~total phase_name] creates progress for a phase with [total] items. 34 + val v : total:int -> string -> t 35 + (** [v ~total phase_name] creates progress for a phase with [total] items. 36 36 Shows as "[phase_name] (0/[total])" initially. *) 37 37 38 38 val tick : t -> string -> unit
+10 -10
test/test_config.ml
··· 8 8 9 9 let test_create_basic () = 10 10 let root = Fpath.v "/home/user/workspace" in 11 - let config = Config.create ~root ~handle:"anil.recoil.org" () in 11 + let config = Config.v ~root ~handle:"anil.recoil.org" () in 12 12 Alcotest.(check string) "handle" "anil.recoil.org" (Config.handle config); 13 13 Alcotest.check fpath "root" root (Config.root config) 14 14 15 15 let test_create_with_knot () = 16 16 let root = Fpath.v "/home/user/workspace" in 17 17 let config = 18 - Config.create ~root ~handle:"anil.recoil.org" ~knot:"git.example.com" () 18 + Config.v ~root ~handle:"anil.recoil.org" ~knot:"git.example.com" () 19 19 in 20 20 Alcotest.(check string) "knot" "git.example.com" (Config.knot config) 21 21 22 22 let test_default_knot_derivation () = 23 23 let root = Fpath.v "/home/user/workspace" in 24 - let config = Config.create ~root ~handle:"anil.recoil.org" () in 24 + let config = Config.v ~root ~handle:"anil.recoil.org" () in 25 25 (* Default knot should be derived from handle: anil.recoil.org -> git.recoil.org *) 26 26 Alcotest.(check string) "derived knot" "git.recoil.org" (Config.knot config) 27 27 28 28 let test_default_knot_no_dot () = 29 29 let root = Fpath.v "/home/user/workspace" in 30 - let config = Config.create ~root ~handle:"localuser" () in 30 + let config = Config.v ~root ~handle:"localuser" () in 31 31 (* Fallback when no dot in handle *) 32 32 Alcotest.(check string) "fallback knot" "git.localuser" (Config.knot config) 33 33 ··· 41 41 42 42 let test_derived_paths () = 43 43 let root = Fpath.v "/home/user/workspace" in 44 - let config = Config.create ~root ~handle:"test.example.org" () in 44 + let config = Config.v ~root ~handle:"test.example.org" () in 45 45 Alcotest.check fpath "mono_path" 46 46 (Fpath.v "/home/user/workspace/mono") 47 47 (Config.mono_path config); ··· 58 58 let test_custom_paths () = 59 59 let root = Fpath.v "/home/user/workspace" in 60 60 let paths = { Config.mono = "."; src = "checkouts"; verse = "others" } in 61 - let config = Config.create ~root ~handle:"test.example.org" ~paths () in 61 + let config = Config.v ~root ~handle:"test.example.org" ~paths () in 62 62 Alcotest.check fpath "custom mono_path" 63 63 (Fpath.v "/home/user/workspace/.") 64 64 (Config.mono_path config); ··· 73 73 74 74 let test_paths_module_aliases () = 75 75 let root = Fpath.v "/home/user/workspace" in 76 - let config = Config.create ~root ~handle:"test.example.org" () in 76 + let config = Config.v ~root ~handle:"test.example.org" () in 77 77 Alcotest.check fpath "Paths.monorepo = mono_path" (Config.mono_path config) 78 78 (Config.Paths.monorepo config); 79 79 Alcotest.check fpath "Paths.checkouts = src_path" (Config.src_path config) ··· 86 86 87 87 let test_no_package_overrides () = 88 88 let root = Fpath.v "/home/user/workspace" in 89 - let config = Config.create ~root ~handle:"test.example.org" () in 89 + let config = Config.v ~root ~handle:"test.example.org" () in 90 90 Alcotest.(check (list (pair string pass))) 91 91 "empty packages" [] (Config.packages config); 92 92 Alcotest.(check (option pass)) ··· 95 95 96 96 let test_with_package_override () = 97 97 let root = Fpath.v "/home/user/workspace" in 98 - let config = Config.create ~root ~handle:"test.example.org" () in 98 + let config = Config.v ~root ~handle:"test.example.org" () in 99 99 let config' = 100 100 Config.with_package_override config ~name:"my-pkg" ~branch:"feature" () 101 101 in ··· 109 109 110 110 let test_override_update () = 111 111 let root = Fpath.v "/home/user/workspace" in 112 - let config = Config.create ~root ~handle:"test.example.org" () in 112 + let config = Config.v ~root ~handle:"test.example.org" () in 113 113 let config' = 114 114 Config.with_package_override config ~name:"my-pkg" ~branch:"v1" () 115 115 in
+21 -21
test/test_package.ml
··· 9 9 10 10 let test_create_basic () = 11 11 let dev_repo = Uri.of_string "https://github.com/ocaml/ocaml.git" in 12 - let pkg = Package.create ~name:"ocaml" ~version:"dev" ~dev_repo () in 12 + let pkg = Package.v ~name:"ocaml" ~version:"dev" ~dev_repo () in 13 13 Alcotest.(check string) "name" "ocaml" (Package.name pkg); 14 14 Alcotest.(check string) "version" "dev" (Package.version pkg); 15 15 Alcotest.check uri "dev_repo" dev_repo (Package.dev_repo pkg) ··· 17 17 let test_create_with_branch () = 18 18 let dev_repo = Uri.of_string "https://github.com/ocaml/ocaml.git" in 19 19 let pkg = 20 - Package.create ~name:"ocaml" ~version:"dev" ~dev_repo ~branch:"trunk" () 20 + Package.v ~name:"ocaml" ~version:"dev" ~dev_repo ~branch:"trunk" () 21 21 in 22 22 Alcotest.(check (option string)) "branch" (Some "trunk") (Package.branch pkg) 23 23 24 24 let test_create_with_depends () = 25 25 let dev_repo = Uri.of_string "https://github.com/example/mylib.git" in 26 26 let pkg = 27 - Package.create ~name:"mylib" ~version:"dev" ~dev_repo 27 + Package.v ~name:"mylib" ~version:"dev" ~dev_repo 28 28 ~depends:[ "base"; "stdio" ] () 29 29 in 30 30 Alcotest.(check (list string)) ··· 33 33 let test_create_with_synopsis () = 34 34 let dev_repo = Uri.of_string "https://github.com/example/mylib.git" in 35 35 let pkg = 36 - Package.create ~name:"mylib" ~version:"dev" ~dev_repo 36 + Package.v ~name:"mylib" ~version:"dev" ~dev_repo 37 37 ~synopsis:"A useful library" () 38 38 in 39 39 Alcotest.(check (option string)) ··· 41 41 42 42 let test_default_values () = 43 43 let dev_repo = Uri.of_string "https://github.com/example/mylib.git" in 44 - let pkg = Package.create ~name:"mylib" ~version:"dev" ~dev_repo () in 44 + let pkg = Package.v ~name:"mylib" ~version:"dev" ~dev_repo () in 45 45 Alcotest.(check (option string)) "default branch" None (Package.branch pkg); 46 46 Alcotest.(check (list string)) "default depends" [] (Package.depends pkg); 47 47 Alcotest.(check (option string)) ··· 51 51 52 52 let test_repo_name_github () = 53 53 let dev_repo = Uri.of_string "https://github.com/ocaml/ocaml.git" in 54 - let pkg = Package.create ~name:"ocaml" ~version:"dev" ~dev_repo () in 54 + let pkg = Package.v ~name:"ocaml" ~version:"dev" ~dev_repo () in 55 55 Alcotest.(check string) "github repo name" "ocaml" (Package.repo_name pkg) 56 56 57 57 let test_repo_name_no_git_suffix () = 58 58 let dev_repo = Uri.of_string "https://github.com/ocaml/dune" in 59 - let pkg = Package.create ~name:"dune" ~version:"dev" ~dev_repo () in 59 + let pkg = Package.v ~name:"dune" ~version:"dev" ~dev_repo () in 60 60 Alcotest.(check string) "no .git suffix" "dune" (Package.repo_name pkg) 61 61 62 62 let test_repo_name_gitlab () = 63 63 let dev_repo = Uri.of_string "https://gitlab.com/org/myrepo.git" in 64 - let pkg = Package.create ~name:"mylib" ~version:"dev" ~dev_repo () in 64 + let pkg = Package.v ~name:"mylib" ~version:"dev" ~dev_repo () in 65 65 Alcotest.(check string) "gitlab repo name" "myrepo" (Package.repo_name pkg) 66 66 67 67 let test_repo_name_nested_path () = 68 68 let dev_repo = Uri.of_string "https://github.com/org/sub/repo.git" in 69 - let pkg = Package.create ~name:"mylib" ~version:"dev" ~dev_repo () in 69 + let pkg = Package.v ~name:"mylib" ~version:"dev" ~dev_repo () in 70 70 Alcotest.(check string) "nested path" "repo" (Package.repo_name pkg) 71 71 72 72 (* Test derived paths *) 73 73 74 74 let test_checkout_dir () = 75 75 let dev_repo = Uri.of_string "https://github.com/ocaml/ocaml.git" in 76 - let pkg = Package.create ~name:"ocaml" ~version:"dev" ~dev_repo () in 76 + let pkg = Package.v ~name:"ocaml" ~version:"dev" ~dev_repo () in 77 77 let checkouts_root = Fpath.v "/home/user/src" in 78 78 Alcotest.check fpath "checkout dir" 79 79 (Fpath.v "/home/user/src/ocaml") ··· 81 81 82 82 let test_subtree_prefix () = 83 83 let dev_repo = Uri.of_string "https://github.com/ocaml/ocaml.git" in 84 - let pkg = Package.create ~name:"ocaml" ~version:"dev" ~dev_repo () in 84 + let pkg = Package.v ~name:"ocaml" ~version:"dev" ~dev_repo () in 85 85 Alcotest.(check string) "subtree prefix" "ocaml" (Package.subtree_prefix pkg) 86 86 87 87 let test_multiple_packages_same_repo () = 88 88 let dev_repo = Uri.of_string "https://github.com/mirage/mirage.git" in 89 - let pkg1 = Package.create ~name:"mirage" ~version:"dev" ~dev_repo () in 90 - let pkg2 = Package.create ~name:"mirage-unix" ~version:"dev" ~dev_repo () in 89 + let pkg1 = Package.v ~name:"mirage" ~version:"dev" ~dev_repo () in 90 + let pkg2 = Package.v ~name:"mirage-unix" ~version:"dev" ~dev_repo () in 91 91 Alcotest.(check string) 92 92 "same repo name" (Package.repo_name pkg1) (Package.repo_name pkg2); 93 93 Alcotest.(check string) ··· 99 99 100 100 let test_compare () = 101 101 let dev_repo = Uri.of_string "https://github.com/example/repo.git" in 102 - let pkg_a = Package.create ~name:"aaa" ~version:"dev" ~dev_repo () in 103 - let pkg_b = Package.create ~name:"bbb" ~version:"dev" ~dev_repo () in 102 + let pkg_a = Package.v ~name:"aaa" ~version:"dev" ~dev_repo () in 103 + let pkg_b = Package.v ~name:"bbb" ~version:"dev" ~dev_repo () in 104 104 Alcotest.(check bool) "a < b" true (Package.compare pkg_a pkg_b < 0); 105 105 Alcotest.(check bool) "b > a" true (Package.compare pkg_b pkg_a > 0); 106 106 Alcotest.(check bool) "a = a" true (Package.compare pkg_a pkg_a = 0) 107 107 108 108 let test_equal () = 109 109 let dev_repo = Uri.of_string "https://github.com/example/repo.git" in 110 - let pkg1 = Package.create ~name:"test" ~version:"dev" ~dev_repo () in 111 - let pkg2 = Package.create ~name:"test" ~version:"1.0" ~dev_repo () in 112 - let pkg3 = Package.create ~name:"other" ~version:"dev" ~dev_repo () in 110 + let pkg1 = Package.v ~name:"test" ~version:"dev" ~dev_repo () in 111 + let pkg2 = Package.v ~name:"test" ~version:"1.0" ~dev_repo () in 112 + let pkg3 = Package.v ~name:"other" ~version:"dev" ~dev_repo () in 113 113 Alcotest.(check bool) "same name equal" true (Package.equal pkg1 pkg2); 114 114 Alcotest.(check bool) 115 115 "different name not equal" false (Package.equal pkg1 pkg3) ··· 118 118 let dev_repo1 = Uri.of_string "https://github.com/ocaml/ocaml.git" in 119 119 let dev_repo2 = Uri.of_string "https://github.com/mirage/mirage.git" in 120 120 let pkg1 = 121 - Package.create ~name:"ocaml" ~version:"dev" ~dev_repo:dev_repo1 () 121 + Package.v ~name:"ocaml" ~version:"dev" ~dev_repo:dev_repo1 () 122 122 in 123 123 let pkg2 = 124 - Package.create ~name:"ocaml-base" ~version:"dev" ~dev_repo:dev_repo1 () 124 + Package.v ~name:"ocaml-base" ~version:"dev" ~dev_repo:dev_repo1 () 125 125 in 126 126 let pkg3 = 127 - Package.create ~name:"mirage" ~version:"dev" ~dev_repo:dev_repo2 () 127 + Package.v ~name:"mirage" ~version:"dev" ~dev_repo:dev_repo2 () 128 128 in 129 129 Alcotest.(check bool) "same repo" true (Package.same_repo pkg1 pkg2); 130 130 Alcotest.(check bool) "different repo" false (Package.same_repo pkg1 pkg3)
+12 -12
test/test_remote_cache.ml
··· 15 15 16 16 let test_empty_cache () = 17 17 let now, _, _ = make_mock_clock () in 18 - let cache = Remote_cache.create ~now () in 18 + let cache = Remote_cache.v ~now () in 19 19 Alcotest.(check int) "empty cache" 0 (Remote_cache.size cache); 20 20 Alcotest.(check (option string)) 21 21 "get from empty" None ··· 23 23 24 24 let test_set_get () = 25 25 let now, _, _ = make_mock_clock () in 26 - let cache = Remote_cache.create ~now () in 26 + let cache = Remote_cache.v ~now () in 27 27 Remote_cache.set cache ~url:test_url ~branch:"main" ~hash:"abc123"; 28 28 Alcotest.(check int) "size after set" 1 (Remote_cache.size cache); 29 29 Alcotest.(check (option string)) ··· 32 32 33 33 let test_different_branches () = 34 34 let now, _, _ = make_mock_clock () in 35 - let cache = Remote_cache.create ~now () in 35 + let cache = Remote_cache.v ~now () in 36 36 Remote_cache.set cache ~url:test_url ~branch:"main" ~hash:"main123"; 37 37 Remote_cache.set cache ~url:test_url ~branch:"develop" ~hash:"dev456"; 38 38 Alcotest.(check int) "size with two branches" 2 (Remote_cache.size cache); ··· 45 45 46 46 let test_different_urls () = 47 47 let now, _, _ = make_mock_clock () in 48 - let cache = Remote_cache.create ~now () in 48 + let cache = Remote_cache.v ~now () in 49 49 Remote_cache.set cache ~url:test_url ~branch:"main" ~hash:"ocaml123"; 50 50 Remote_cache.set cache ~url:test_url2 ~branch:"main" ~hash:"mirage456"; 51 51 Alcotest.(check int) "size with two urls" 2 (Remote_cache.size cache); ··· 58 58 59 59 let test_update_existing () = 60 60 let now, _, _ = make_mock_clock () in 61 - let cache = Remote_cache.create ~now () in 61 + let cache = Remote_cache.v ~now () in 62 62 Remote_cache.set cache ~url:test_url ~branch:"main" ~hash:"old123"; 63 63 Remote_cache.set cache ~url:test_url ~branch:"main" ~hash:"new456"; 64 64 Alcotest.(check int) "size after update" 1 (Remote_cache.size cache); ··· 69 69 let test_expiration () = 70 70 let now, advance, _ = make_mock_clock () in 71 71 let ttl = 60.0 in 72 - let cache = Remote_cache.create ~ttl ~now () in 72 + let cache = Remote_cache.v ~ttl ~now () in 73 73 Remote_cache.set cache ~url:test_url ~branch:"main" ~hash:"abc123"; 74 74 (* Still valid *) 75 75 Alcotest.(check (option string)) ··· 89 89 let test_expiration_boundary () = 90 90 let now, advance, _ = make_mock_clock () in 91 91 let ttl = 60.0 in 92 - let cache = Remote_cache.create ~ttl ~now () in 92 + let cache = Remote_cache.v ~ttl ~now () in 93 93 Remote_cache.set cache ~url:test_url ~branch:"main" ~hash:"abc123"; 94 94 (* Just before TTL - still valid *) 95 95 advance 59.999; ··· 105 105 let test_refresh_extends_ttl () = 106 106 let now, advance, _ = make_mock_clock () in 107 107 let ttl = 60.0 in 108 - let cache = Remote_cache.create ~ttl ~now () in 108 + let cache = Remote_cache.v ~ttl ~now () in 109 109 Remote_cache.set cache ~url:test_url ~branch:"main" ~hash:"abc123"; 110 110 (* Advance 50 seconds *) 111 111 advance 50.0; ··· 122 122 123 123 let test_clear () = 124 124 let now, _, _ = make_mock_clock () in 125 - let cache = Remote_cache.create ~now () in 125 + let cache = Remote_cache.v ~now () in 126 126 Remote_cache.set cache ~url:test_url ~branch:"main" ~hash:"abc123"; 127 127 Remote_cache.set cache ~url:test_url2 ~branch:"main" ~hash:"def456"; 128 128 Alcotest.(check int) "before clear" 2 (Remote_cache.size cache); ··· 134 134 135 135 let test_serialization () = 136 136 let now, _, _ = make_mock_clock () in 137 - let cache = Remote_cache.create ~now () in 137 + let cache = Remote_cache.v ~now () in 138 138 Remote_cache.set cache ~url:test_url ~branch:"main" ~hash:"abc123"; 139 139 Remote_cache.set cache ~url:test_url ~branch:"develop" ~hash:"def456"; 140 140 let serialized = Remote_cache.to_string cache in ··· 151 151 let test_serialization_excludes_expired () = 152 152 let now, advance, set = make_mock_clock () in 153 153 let ttl = 60.0 in 154 - let cache = Remote_cache.create ~ttl ~now () in 154 + let cache = Remote_cache.v ~ttl ~now () in 155 155 Remote_cache.set cache ~url:test_url ~branch:"main" ~hash:"fresh"; 156 156 advance 30.0; 157 157 Remote_cache.set cache ~url:test_url ~branch:"develop" ~hash:"newer"; ··· 172 172 173 173 let test_many_entries () = 174 174 let now, _, _ = make_mock_clock () in 175 - let cache = Remote_cache.create ~now () in 175 + let cache = Remote_cache.v ~now () in 176 176 for i = 0 to 999 do 177 177 let url = 178 178 Uri.of_string (Printf.sprintf "https://example.com/repo%d.git" i)
+1 -1
test/test_status.ml
··· 6 6 (* Helper to create a test package *) 7 7 let make_package name = 8 8 let dev_repo = Uri.of_string ("https://github.com/test/" ^ name ^ ".git") in 9 - Package.create ~name ~version:"dev" ~dev_repo () 9 + Package.v ~name ~version:"dev" ~dev_repo () 10 10 11 11 (* Helper to create a status with given parameters *) 12 12 let make_status ?(checkout = Status.Missing) ?(subtree = Status.Not_added)