@@ -13,6 +13,9 @@ namespace Cache.Requests
1313
1414open System (FilePath)
1515
16+ /-- The full name of the main Mathlib GitHub repository. -/
17+ def MATHLIBREPO := "leanprover-community/mathlib4"
18+
1619/--
1720Structure to hold repository information with priority ordering
1821-/
@@ -37,7 +40,7 @@ def isRemoteURL (url : String) : Bool :=
3740/--
3841Helper function to get repository from a remote name
3942-/
40- def getRepoFromRemote (mathlibDepPath : FilePath) (remoteName : String) (errorContext : String) : IO String := do
43+ def getRepoFromRemote (mathlibDepPath : FilePath) (remoteName : String) (errorContext : String) : IO (Option String) := do
4144 -- If the remote is already a valid URL, attempt to extract the repo from it. This happens with `gh pr checkout`
4245 if isRemoteURL remoteName then
4346 repoFromURL remoteName
@@ -46,23 +49,25 @@ def getRepoFromRemote (mathlibDepPath : FilePath) (remoteName : String) (errorCo
4649 -- standard name like `origin` or `upstream` or it errors out.
4750 let out ← IO.Process.output
4851 {cmd := "git" , args := #["remote" , "get-url" , remoteName], cwd := mathlibDepPath}
49- -- If `git remote get-url` fails then bail out with an error to help debug
52+ -- If `git remote get-url` fails then return none.
5053 let output := out.stdout.trimAscii
5154 unless out.exitCode == 0 do
52- throw <| IO.userError s! "\
53- Failed to run Git to determine Mathlib's repository from { remoteName} remote (exit code: { out.exitCode } ). \n \
55+ IO.println s! "\
56+ Warning: failed to run Git to determine Mathlib's repository from { remoteName} remote\n \
5457 { errorContext} \n \
55- Stdout:\n { output} \n Stderr:\n { out.stderr.trimAscii} \n "
58+ Continuing to fetch the cache from { MATHLIBREPO} ."
59+ return none
5660 -- Finally attempt to extract the repository from the remote URL returned by `git remote get-url`
5761 repoFromURL output.copy
58- where repoFromURL (url : String) : IO String := do
62+ where repoFromURL (url : String) : IO (Option String) := do
5963 if let some repo := extractRepoFromUrl url then
60- return repo
64+ return some repo
6165 else
62- throw <| IO.userError s! "\
63- Failed to extract repository from remote URL: { url} .\n \
66+ IO.println s! "\
67+ Warning: Failed to extract repository from remote URL: { url} .\n \
6468 { errorContext} \n \
65- Please ensure the remote URL is valid and points to a GitHub repository."
69+ Continuing to fetch the cache from { MATHLIBREPO} ."
70+ return none
6671
6772/--
6873Finds the remote name that points to `leanprover-community/mathlib4` repository.
@@ -146,7 +151,7 @@ Attempts to determine the GitHub repository of a version of Mathlib from its Git
146151If the current commit coincides with a PR ref, it will determine the source fork
147152of that PR rather than just using the origin remote.
148153-/
149- def getRemoteRepo (mathlibDepPath : FilePath) : IO RepoInfo := do
154+ def getRemoteRepo (mathlibDepPath : FilePath) : IO (Option RepoInfo) := do
150155
151156 -- Since currently we need to push a PR to `leanprover-community/mathlib` build a user cache,
152157 -- we check if we are a special branch or a branch with PR. This leaves out non-PRed fork
@@ -176,7 +181,7 @@ def getRemoteRepo (mathlibDepPath : FilePath) : IO RepoInfo := do
176181 let repo := "leanprover-community/mathlib4-nightly-testing"
177182 let cacheService := if useCloudflareCache then "Cloudflare" else "Azure"
178183 IO.println s! "Using cache ({ cacheService} ) from nightly-testing remote: { repo} "
179- return {repo := repo, useFirst := true }
184+ return some {repo := repo, useFirst := true }
180185
181186 -- Only search for PR refs if we're not on a regular branch like master, bump/*, or nightly-testing*
182187 -- let isSpecialBranch := branchName == "master" || branchName.startsWith "bump/" ||
@@ -234,11 +239,16 @@ def getRemoteRepo (mathlibDepPath : FilePath) : IO RepoInfo := do
234239 -- If no tracking remote is configured, fall back to origin
235240 "origin"
236241
237- let repo ← getRepoFromRemote mathlibDepPath remoteName
242+ let repo? ← getRepoFromRemote mathlibDepPath remoteName
238243 s! "Ensure Git is installed and the '{ remoteName} ' remote points to its GitHub repository."
239244 let cacheService := if useCloudflareCache then "Cloudflare" else "Azure"
240- IO.println s! "Using cache ({ cacheService} ) from { remoteName} : { repo} "
241- return {repo := repo, useFirst := false }
245+ match repo? with
246+ | some repo =>
247+ IO.println s! "Using cache ({ cacheService} ) from { remoteName} : { repo?} "
248+ return some {repo := repo, useFirst := false }
249+ | none =>
250+ IO.println s! "Using cache ({ cacheService} ) from { MATHLIBREPO} ."
251+ return none
242252
243253/-- Public URL for mathlib cache -/
244254initialize URL : String ← do
@@ -275,9 +285,6 @@ def getUploadAuth : IO UploadAuth := do
275285 throw <| IO.userError
276286 "environment variable MATHLIB_CACHE_AZURE_BEARER_TOKEN or MATHLIB_CACHE_SAS must be set to upload caches"
277287
278- /-- The full name of the main Mathlib GitHub repository. -/
279- def MATHLIBREPO := "leanprover-community/mathlib4"
280-
281288/--
282289Given a file name like `"1234.tar.gz"`, makes the URL to that file on the server.
283290
@@ -663,16 +670,19 @@ def getFiles
663670 isMathlibRoot mathlibDepPath
664671 if failed > 0 then IO.Process.exit 1
665672 else
666- let repoInfo ← getRemoteRepo (← read).mathlibDepPath
673+ let repoInfo? ← getRemoteRepo (← read).mathlibDepPath
667674
668675 -- Build list of repositories to download from in order
669676 let repos : List String :=
670- if repoInfo.repo == MATHLIBREPO then
671- [repoInfo.repo]
672- else if repoInfo.useFirst then
673- [repoInfo.repo, MATHLIBREPO]
677+ if let some repoInfo := repoInfo? then
678+ if repoInfo.repo == MATHLIBREPO then
679+ [MATHLIBREPO]
680+ else if repoInfo.useFirst then
681+ [repoInfo.repo, MATHLIBREPO]
682+ else
683+ [MATHLIBREPO, repoInfo.repo]
674684 else
675- [MATHLIBREPO, repoInfo.repo ]
685+ [MATHLIBREPO]
676686
677687 let mut failed : Nat := 0
678688 for h : i in [0 :repos.length] do
0 commit comments