@@ -28,10 +28,10 @@ structure RepoInfo where
2828Helper function to extract repository name from a git remote URL
2929-/
3030def extractRepoFromUrl (url : String) : Option String := do
31- let url := url.stripSuffix ".git"
32- let pos ← url.revFind (· == '/' )
33- let pos ← url.revFindAux (fun c => c == '/' || c == ':' ) pos
34- return (String.Pos.Raw.extract url) (String.Pos.Raw.next url pos) url.rawEndPos
31+ let url := url.dropSuffix ".git"
32+ let pos ← url.revFind? (· == '/' )
33+ let pos ← ( url.sliceTo pos).revFind? (fun c => c == '/' || c == ':' )
34+ return url.sliceFrom (String.Slice. Pos.ofSliceTo pos).next! |>.copy
3535
3636/-- Spot check if a URL is valid for a git remote -/
3737def isRemoteURL (url : String) : Bool :=
@@ -50,14 +50,14 @@ def getRepoFromRemote (mathlibDepPath : FilePath) (remoteName : String) (errorCo
5050 let out ← IO.Process.output
5151 {cmd := "git" , args := #["remote" , "get-url" , remoteName], cwd := mathlibDepPath}
5252 -- If `git remote get-url` fails then bail out with an error to help debug
53- let output := out.stdout.trim
53+ let output := out.stdout.trimAscii
5454 unless out.exitCode == 0 do
5555 throw <| IO.userError s! "\
5656 Failed to run Git to determine Mathlib's repository from { remoteName} remote (exit code: { out.exitCode} ).\n \
5757 { errorContext} \n \
58- Stdout:\n { output} \n Stderr:\n { out.stderr.trim } \n "
58+ Stdout:\n { output} \n Stderr:\n { out.stderr.trimAscii } \n "
5959 -- Finally attempt to extract the repository from the remote URL returned by `git remote get-url`
60- repoFromURL output
60+ repoFromURL output.copy
6161where repoFromURL (url : String) : IO String := do
6262 if let some repo := extractRepoFromUrl url then
6363 return repo
@@ -79,17 +79,17 @@ def findMathlibRemote (mathlibDepPath : FilePath) : IO String := do
7979 throw <| IO.userError s! "\
8080 Failed to run Git to list remotes (exit code: { remotesInfo.exitCode} ).\n \
8181 Ensure Git is installed.\n \
82- Stdout:\n { remotesInfo.stdout.trim } \n Stderr:\n { remotesInfo.stderr.trim } \n "
82+ Stdout:\n { remotesInfo.stdout.trimAscii } \n Stderr:\n { remotesInfo.stderr.trimAscii } \n "
8383
8484 let remoteLines := remotesInfo.stdout.splitToList (· == '\n ' )
8585 let mut mathlibRemote : Option String := none
8686 let mut originPointsToMathlib : Bool := false
8787
8888 for line in remoteLines do
89- let parts := line.trim .splitToList (· == '\t ' )
89+ let parts := line.trimAscii.copy .splitToList (· == '\t ' )
9090 if parts.length >= 2 then
9191 let remoteName := parts[0 ]!
92- let remoteUrl := parts[1 ]!.takeWhile (· != ' ' ) -- Remove (fetch) or (push) suffix
92+ let remoteUrl := parts[1 ]!.takeWhile (· != ' ' ) |>.copy -- Remove (fetch) or (push) suffix
9393
9494 -- Check if this remote points to leanprover-community/mathlib4
9595 let isMathlibRepo := remoteUrl.containsSubstr "leanprover-community/mathlib4"
@@ -128,11 +128,11 @@ def isDetachedAtNightlyTesting (mathlibDepPath : FilePath) : IO Bool := do
128128 let currentCommit ← IO.Process.output
129129 {cmd := "git" , args := #["rev-parse" , "HEAD" ], cwd := mathlibDepPath}
130130 if currentCommit.exitCode == 0 then
131- let commitHash := currentCommit.stdout.trim
131+ let commitHash := currentCommit.stdout.trimAscii.copy
132132 let tagInfo ← IO.Process.output
133133 {cmd := "git" , args := #["name-rev" , "--tags" , commitHash], cwd := mathlibDepPath}
134134 if tagInfo.exitCode == 0 then
135- let parts := tagInfo.stdout.trim .splitOn " "
135+ let parts := tagInfo.stdout.trimAscii.copy .splitOn " "
136136 -- git name-rev returns "commit_hash tags/tag_name" or just "commit_hash undefined" if no tag
137137 if parts.length >= 2 && parts[1 ]!.startsWith "tags/" then
138138 let tagName := parts[1 ]!.drop 5 -- Remove "tags/" prefix
@@ -159,17 +159,17 @@ def getRemoteRepo (mathlibDepPath : FilePath) : IO RepoInfo := do
159159 {cmd := "git" , args := #["rev-parse" , "--abbrev-ref" , "HEAD" ], cwd := mathlibDepPath}
160160
161161 if currentBranch.exitCode == 0 then
162- let branchName := currentBranch.stdout.trim.stripPrefix "heads/"
162+ let branchName := currentBranch.stdout.trimAscii.dropPrefix "heads/"
163163 IO.println s! "Current branch: { branchName} "
164164
165165 -- Check if we're in a detached HEAD state at a nightly-testing tag
166- let isDetachedAtNightlyTesting ← if branchName == "HEAD" then
166+ let isDetachedAtNightlyTesting ← if branchName == "HEAD" .toSlice then
167167 isDetachedAtNightlyTesting mathlibDepPath
168168 else
169169 pure false
170170
171171 -- Check if we're on a branch that should use nightly-testing remote
172- let shouldUseNightlyTesting := branchName == "nightly-testing" ||
172+ let shouldUseNightlyTesting := branchName == "nightly-testing" .toSlice ||
173173 branchName.startsWith "lean-pr-testing-" ||
174174 branchName.startsWith "batteries-pr-testing-" ||
175175 branchName.startsWith "bump/" ||
@@ -229,10 +229,10 @@ def getRemoteRepo (mathlibDepPath : FilePath) : IO RepoInfo := do
229229
230230 -- Fall back to using the remote that the current branch is tracking
231231 let trackingRemote ← IO.Process.output
232- {cmd := "git" , args := #["config" , "--get" , s! "branch.{ currentBranch.stdout.trim } .remote" ], cwd := mathlibDepPath}
232+ {cmd := "git" , args := #["config" , "--get" , s! "branch.{ currentBranch.stdout.trimAscii } .remote" ], cwd := mathlibDepPath}
233233
234234 let remoteName := if trackingRemote.exitCode == 0 then
235- trackingRemote.stdout.trim
235+ trackingRemote.stdout.trimAscii.copy
236236 else
237237 -- If no tracking remote is configured, fall back to origin
238238 "origin"
@@ -329,15 +329,15 @@ def monitorCurl (args : Array String) (size : Nat)
329329 let s@{success, failed, done, speed, ..} ← IO.runCurlStreaming args init fun a line => do
330330 let mut {last, success, failed, done, speed} := a
331331 -- output errors other than 404 and remove corresponding partial downloads
332- let line := line.trim
332+ let line := line.trimAscii
333333 if !line.isEmpty then
334- match Lean.Json.parse line with
334+ match Lean.Json.parse line.copy with
335335 | .ok result =>
336336 match result.getObjValAs? Nat "http_code" with
337337 | .ok 200 =>
338338 if let .ok fn := result.getObjValAs? String "filename_effective" then
339339 if (← System.FilePath.pathExists fn) && fn.endsWith ".part" then
340- IO.FS.rename fn (fn.dropRight 5 )
340+ IO.FS.rename fn (fn.dropEnd 5 ).copy
341341 success := success + 1
342342 | .ok 404 => pure ()
343343 | code? =>
@@ -415,10 +415,10 @@ def checkForToolchainMismatch : IO.CacheM Unit := do
415415 let mathlibToolchainFile := (← read).mathlibDepPath / "lean-toolchain"
416416 let downstreamToolchain ← IO.FS.readFile "lean-toolchain"
417417 let mathlibToolchain ← IO.FS.readFile mathlibToolchainFile
418- if !(mathlibToolchain.trim = downstreamToolchain.trim ) then
418+ if !(mathlibToolchain.trimAscii == downstreamToolchain.trimAscii ) then
419419 IO.println "Dependency Mathlib uses a different lean-toolchain"
420- IO.println s! " Project uses { downstreamToolchain.trim } "
421- IO.println s! " Mathlib uses { mathlibToolchain.trim } "
420+ IO.println s! " Project uses { downstreamToolchain.trimAscii } "
421+ IO.println s! " Mathlib uses { mathlibToolchain.trimAscii } "
422422 IO.println "\n The cache will not work unless your project's toolchain matches Mathlib's toolchain"
423423 IO.println s! "This can be achieved by copying the contents of the file `{ mathlibToolchainFile} `
424424into the `lean-toolchain` file at the root directory of your project"
@@ -554,7 +554,8 @@ section Commit
554554def isGitStatusClean : IO Bool :=
555555 return (← IO.runCmd "git" #["status" , "--porcelain" ]).isEmpty
556556
557- def getGitCommitHash : IO String := return (← IO.runCmd "git" #["rev-parse" , "HEAD" ]).trimRight
557+ def getGitCommitHash : IO String :=
558+ return (← IO.runCmd "git" #["rev-parse" , "HEAD" ]).trimAsciiEnd.copy
558559
559560/--
560561Sends a commit file to the server, containing the hashes of the respective committed files.
0 commit comments