tangled
alpha
login
or
join now
anil.recoil.org
/
unpac
0
fork
atom
A monorepo management tool for the agentic ages
0
fork
atom
overview
issues
pulls
pipelines
rewrites
anil.recoil.org
3 months ago
b74bb6f1
96ef1df3
+44
-23
1 changed file
expand all
collapse all
unified
split
lib
git_repo_lookup.ml
+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
10
-
- erratique.ch repos are mirrored on GitHub under dbuenzli *)
10
10
+
- erratique.ch repos are mirrored on GitHub under dbuenzli
11
11
+
- git.robur.coop repos are mirrored on GitHub under robur-coop
12
12
+
(strips the org prefix: git.robur.coop/robur/X -> github.com/robur-coop/X) *)
11
13
let rewrite_url url =
12
12
-
(* Rewrite erratique.ch repos to GitHub mirrors (faster) *)
13
13
-
let erratique_https = "https://erratique.ch/repos/" in
14
14
-
let erratique_http = "http://erratique.ch/repos/" in
15
15
-
let github_mirror = "https://github.com/dbuenzli/" in
16
16
-
if String.length url > String.length erratique_https
17
17
-
&& String.sub url 0 (String.length erratique_https) = erratique_https
18
18
-
then
19
19
-
let rest =
20
20
-
String.sub url (String.length erratique_https)
21
21
-
(String.length url - String.length erratique_https)
22
22
-
in
23
23
-
github_mirror ^ rest
24
24
-
else if
25
25
-
String.length url > String.length erratique_http
26
26
-
&& String.sub url 0 (String.length erratique_http) = erratique_http
27
27
-
then
28
28
-
let rest =
29
29
-
String.sub url (String.length erratique_http)
30
30
-
(String.length url - String.length erratique_http)
31
31
-
in
32
32
-
github_mirror ^ rest
33
33
-
else url
14
14
+
(* Helper to check and rewrite prefix *)
15
15
+
let try_rewrite ~prefix ~replacement url =
16
16
+
if String.length url > String.length prefix
17
17
+
&& String.sub url 0 (String.length prefix) = prefix
18
18
+
then
19
19
+
let rest = String.sub url (String.length prefix)
20
20
+
(String.length url - String.length prefix) in
21
21
+
Some (replacement ^ rest)
22
22
+
else None
23
23
+
in
24
24
+
(* Helper to rewrite robur.coop URLs, stripping the org path component *)
25
25
+
let try_rewrite_robur ~prefix url =
26
26
+
if String.length url > String.length prefix
27
27
+
&& String.sub url 0 (String.length prefix) = prefix
28
28
+
then
29
29
+
(* rest is e.g. "robur/ohex.git" - strip org prefix *)
30
30
+
let rest = String.sub url (String.length prefix)
31
31
+
(String.length url - String.length prefix) in
32
32
+
(* Find the first slash to strip the org *)
33
33
+
match String.index_opt rest '/' with
34
34
+
| Some idx ->
35
35
+
let repo = String.sub rest (idx + 1) (String.length rest - idx - 1) in
36
36
+
Some ("https://github.com/robur-coop/" ^ repo)
37
37
+
| None -> Some ("https://github.com/robur-coop/" ^ rest)
38
38
+
else None
39
39
+
in
40
40
+
(* Try each rewrite rule in order *)
41
41
+
match try_rewrite ~prefix:"https://erratique.ch/repos/"
42
42
+
~replacement:"https://github.com/dbuenzli/" url with
43
43
+
| Some u -> u
44
44
+
| None ->
45
45
+
match try_rewrite ~prefix:"http://erratique.ch/repos/"
46
46
+
~replacement:"https://github.com/dbuenzli/" url with
47
47
+
| Some u -> u
48
48
+
| None ->
49
49
+
match try_rewrite_robur ~prefix:"https://git.robur.coop/" url with
50
50
+
| Some u -> u
51
51
+
| None ->
52
52
+
match try_rewrite_robur ~prefix:"git://git.robur.coop/" url with
53
53
+
| Some u -> u
54
54
+
| None -> url
34
55
35
56
(** Override branch/tag for specific packages.
36
57