Deal with missing tags

This commit is contained in:
Ehmry - 2023-10-09 10:14:35 +01:00
parent dffb461f94
commit b5b9c5a671
2 changed files with 38 additions and 31 deletions

View File

@ -3,6 +3,6 @@ bin = @["nim_lk"]
description = "Tool for generating Nim lockfiles"
license = "BSD-3-Clause"
srcDir = "src"
version = "20231008"
version = "20231009"
requires "nim >= 2.0.0"

View File

@ -28,14 +28,12 @@ func isGitUrl(uri: Uri): bool =
uri.scheme.startsWith("git+")
proc isWebGitForgeUrl(uri: Uri): bool =
result =
case uri.hostname
of "github.com", "git.sr.ht", "codeberg.org": true
else: false
if not result:
stderr.writeLine "not a web forge hostname: '", uri.hostname, "'"
case uri.hostname
of "github.com", "git.sr.ht", "codeberg.org": true
else: false
proc startProcess(cmd: string; cmdArgs: varargs[string]): Process =
# stderr.writeLine(cmd, " ", join(cmdArgs, " "))
startProcess(cmd, args = cmdArgs, options = {poUsePath})
proc gitLsRemote(url: string; withTags: bool): seq[tuple[tag: string, rev: string]] =
@ -45,35 +43,44 @@ proc gitLsRemote(url: string; withTags: bool): seq[tuple[tag: string, rev: strin
startProcess("git", "ls-remote", "--tags", url)
else:
startProcess("git", "ls-remote", url)
while process.running:
while process.outputStream.readLine(line):
var off = 0
off.inc parseUntil(line, rev, Whitespace, off)
off.inc skipWhile(line, Whitespace, off)
refer = line[off..line.high]
const
refsTags = "refs/tags/"
headsTags = "refs/heads/"
if refer.startsWith(refsTags):
refer.removePrefix(refsTags)
elif refer.startsWith(headsTags):
refer.removePrefix(headsTags)
while process.outputStream.readLine(line):
var off = 0
off.inc parseUntil(line, rev, Whitespace, off)
off.inc skipWhile(line, Whitespace, off)
refer = line[off..line.high]
const
refsTags = "refs/tags/"
headsTags = "refs/heads/"
if refer.startsWith(refsTags):
refer.removePrefix(refsTags)
result.add((refer, rev,))
elif refer.startsWith(headsTags):
refer.removePrefix(headsTags)
result.add((refer, rev,))
stderr.write(process.errorStream.readAll)
close(process)
if withTags and result.len == 0:
result = gitLsRemote(url, not withTags)
proc matchRev(url: string; wanted: VersionRange): tuple[tag: string, rev: string] =
let withTags = wanted.kind != verAny
let pairs = gitLsRemote(url, withTags)
var resultVersion: Version
for (tag, rev) in pairs:
var tagVer = Version(tag)
if tagVer.withinRange(wanted) and resultVersion < tagVer:
resultVersion = tagVer
result = (tag, rev)
if result.rev == "" and pairs.len > 0:
result = pairs[pairs.high]
doAssert result.rev != ""
if wanted.kind == verSpecial:
let special = string(wanted.spe)
if special.len == 41 and special[0] == '#':
result[1] = special[1..39]
else:
quit("unhandled version " & url & " " & $wanted)
else:
let withTags = wanted.kind != verAny
let pairs = gitLsRemote(url, withTags)
var resultVersion: Version
for (tag, rev) in pairs:
var tagVer = Version(tag)
if tagVer.withinRange(wanted) and resultVersion < tagVer:
resultVersion = tagVer
result = (tag, rev)
if result.rev == "" and pairs.len > 0:
result = pairs[pairs.high]
doAssert result.rev != "", url
proc collectMetadata(data: JsonNode) =
let storePath = data["path"].getStr