A monorepo management tool for the agentic ages

rewrites

+44 -23
+44 -23
lib/git_repo_lookup.ml
··· 7 7 (** Rewrite a git URL to use a faster mirror if available. 8 8 9 9 Currently handles: 10 - - erratique.ch repos are mirrored on GitHub under dbuenzli *) 10 + - erratique.ch repos are mirrored on GitHub under dbuenzli 11 + - git.robur.coop repos are mirrored on GitHub under robur-coop 12 + (strips the org prefix: git.robur.coop/robur/X -> github.com/robur-coop/X) *) 11 13 let rewrite_url url = 12 - (* Rewrite erratique.ch repos to GitHub mirrors (faster) *) 13 - let erratique_https = "https://erratique.ch/repos/" in 14 - let erratique_http = "http://erratique.ch/repos/" in 15 - let github_mirror = "https://github.com/dbuenzli/" in 16 - if String.length url > String.length erratique_https 17 - && String.sub url 0 (String.length erratique_https) = erratique_https 18 - then 19 - let rest = 20 - String.sub url (String.length erratique_https) 21 - (String.length url - String.length erratique_https) 22 - in 23 - github_mirror ^ rest 24 - else if 25 - String.length url > String.length erratique_http 26 - && String.sub url 0 (String.length erratique_http) = erratique_http 27 - then 28 - let rest = 29 - String.sub url (String.length erratique_http) 30 - (String.length url - String.length erratique_http) 31 - in 32 - github_mirror ^ rest 33 - else url 14 + (* Helper to check and rewrite prefix *) 15 + let try_rewrite ~prefix ~replacement url = 16 + if String.length url > String.length prefix 17 + && String.sub url 0 (String.length prefix) = prefix 18 + then 19 + let rest = String.sub url (String.length prefix) 20 + (String.length url - String.length prefix) in 21 + Some (replacement ^ rest) 22 + else None 23 + in 24 + (* Helper to rewrite robur.coop URLs, stripping the org path component *) 25 + let try_rewrite_robur ~prefix url = 26 + if String.length url > String.length prefix 27 + && String.sub url 0 (String.length prefix) = prefix 28 + then 29 + (* rest is e.g. "robur/ohex.git" - strip org prefix *) 30 + let rest = String.sub url (String.length prefix) 31 + (String.length url - String.length prefix) in 32 + (* Find the first slash to strip the org *) 33 + match String.index_opt rest '/' with 34 + | Some idx -> 35 + let repo = String.sub rest (idx + 1) (String.length rest - idx - 1) in 36 + Some ("https://github.com/robur-coop/" ^ repo) 37 + | None -> Some ("https://github.com/robur-coop/" ^ rest) 38 + else None 39 + in 40 + (* Try each rewrite rule in order *) 41 + match try_rewrite ~prefix:"https://erratique.ch/repos/" 42 + ~replacement:"https://github.com/dbuenzli/" url with 43 + | Some u -> u 44 + | None -> 45 + match try_rewrite ~prefix:"http://erratique.ch/repos/" 46 + ~replacement:"https://github.com/dbuenzli/" url with 47 + | Some u -> u 48 + | None -> 49 + match try_rewrite_robur ~prefix:"https://git.robur.coop/" url with 50 + | Some u -> u 51 + | None -> 52 + match try_rewrite_robur ~prefix:"git://git.robur.coop/" url with 53 + | Some u -> u 54 + | None -> url 34 55 35 56 (** Override branch/tag for specific packages. 36 57