Monorepo management for opam overlays

Merge commit '49edd28f945ef002c598dc66ff9046bfd081c573'

+40 -12
+1 -2
lib/forks.ml
··· 267 267 | None -> None 268 268 | Some url_str -> 269 269 if Opam_repo.is_git_url url_str then 270 - let url, _branch = Opam_repo.normalize_git_url url_str in 271 - Some (pkg_name, url) 270 + Some (pkg_name, Opam_repo.normalize_git_url url_str) 272 271 else None 273 272 with _ -> None 274 273 with _ -> None)
+31 -4
lib/opam_repo.ml
··· 32 32 | false -> url 33 33 in 34 34 let uri = Uri.of_string url in 35 - let branch = Uri.fragment uri in 36 - let uri_without_fragment = Uri.with_fragment uri None in 37 - (uri_without_fragment, branch) 35 + (* Strip fragment from dev-repo URL - branch comes from url field *) 36 + Uri.with_fragment uri None 37 + 38 + (** Extract branch from a URL string with optional #branch fragment *) 39 + let extract_branch_from_url url = 40 + let url = 41 + match String.starts_with ~prefix:"git+" url with 42 + | true -> String.sub url 4 (String.length url - 4) 43 + | false -> url 44 + in 45 + Uri.fragment (Uri.of_string url) 38 46 39 47 module OP = OpamParserTypes.FullPos 40 48 ··· 47 55 match item.pelem with 48 56 | OP.Variable (name, value) when name.pelem = "dev-repo" -> 49 57 extract_string_value value 58 + | _ -> None) 59 + items 60 + 61 + (** Find the 'src' field inside a 'url' section *) 62 + let find_url_src (items : OP.opamfile_item list) : string option = 63 + List.find_map 64 + (fun (item : OP.opamfile_item) -> 65 + match item.pelem with 66 + | OP.Section sec when sec.section_kind.pelem = "url" -> 67 + (* Look for src field inside the section *) 68 + List.find_map 69 + (fun (inner : OP.opamfile_item) -> 70 + match inner.pelem with 71 + | OP.Variable (name, value) when name.pelem = "src" -> 72 + extract_string_value value 73 + | _ -> None) 74 + sec.section_items.pelem 50 75 | _ -> None) 51 76 items 52 77 ··· 118 143 | Some url -> 119 144 if not (is_git_url url) then Error (Not_git_remote (name, url)) 120 145 else 121 - let dev_repo, branch = normalize_git_url url in 146 + let dev_repo = normalize_git_url url in 147 + (* Extract branch from url field's src, not from dev-repo *) 148 + let branch = Option.bind (find_url_src opamfile.file_contents) extract_branch_from_url in 122 149 let depends = find_depends opamfile.file_contents in 123 150 let synopsis = find_synopsis opamfile.file_contents in 124 151 Ok (Package.create ~name ~version ~dev_repo ?branch ~depends ?synopsis ())
+8 -6
lib/opam_repo.mli
··· 69 69 Accepts URLs starting with "git+" or "git://" or ending with ".git", as well 70 70 as SSH-style URLs like "git@github.com:...". *) 71 71 72 - val normalize_git_url : string -> Uri.t * string option 72 + val normalize_git_url : string -> Uri.t 73 73 (** [normalize_git_url url] normalizes a git URL by removing the "git+" prefix 74 - if present, and extracts the branch from the URL fragment if present. 75 - 76 - Returns [(uri, branch)] where [branch] is [Some b] if the URL had a 77 - fragment like "#main", or [None] otherwise. 74 + and any fragment (branch) if present. 78 75 79 76 For example, "git+https://example.com/repo.git#main" becomes 80 - ("https://example.com/repo.git", Some "main"). *) 77 + "https://example.com/repo.git". *) 78 + 79 + val extract_branch_from_url : string -> string option 80 + (** [extract_branch_from_url url] extracts the branch from a URL fragment. 81 + 82 + For example, "git+https://example.com/repo.git#main" returns [Some "main"]. *) 81 83 82 84 val scan_opam_files_for_deps : fs:_ Eio.Path.t -> Fpath.t -> string list 83 85 (** [scan_opam_files_for_deps ~fs dir_path] scans a directory for .opam files