Deal with missing tags
This commit is contained in:
parent
dffb461f94
commit
b5b9c5a671
|
@ -3,6 +3,6 @@ bin = @["nim_lk"]
|
||||||
description = "Tool for generating Nim lockfiles"
|
description = "Tool for generating Nim lockfiles"
|
||||||
license = "BSD-3-Clause"
|
license = "BSD-3-Clause"
|
||||||
srcDir = "src"
|
srcDir = "src"
|
||||||
version = "20231008"
|
version = "20231009"
|
||||||
|
|
||||||
requires "nim >= 2.0.0"
|
requires "nim >= 2.0.0"
|
||||||
|
|
|
@ -28,14 +28,12 @@ func isGitUrl(uri: Uri): bool =
|
||||||
uri.scheme.startsWith("git+")
|
uri.scheme.startsWith("git+")
|
||||||
|
|
||||||
proc isWebGitForgeUrl(uri: Uri): bool =
|
proc isWebGitForgeUrl(uri: Uri): bool =
|
||||||
result =
|
case uri.hostname
|
||||||
case uri.hostname
|
of "github.com", "git.sr.ht", "codeberg.org": true
|
||||||
of "github.com", "git.sr.ht", "codeberg.org": true
|
else: false
|
||||||
else: false
|
|
||||||
if not result:
|
|
||||||
stderr.writeLine "not a web forge hostname: '", uri.hostname, "'"
|
|
||||||
|
|
||||||
proc startProcess(cmd: string; cmdArgs: varargs[string]): Process =
|
proc startProcess(cmd: string; cmdArgs: varargs[string]): Process =
|
||||||
|
# stderr.writeLine(cmd, " ", join(cmdArgs, " "))
|
||||||
startProcess(cmd, args = cmdArgs, options = {poUsePath})
|
startProcess(cmd, args = cmdArgs, options = {poUsePath})
|
||||||
|
|
||||||
proc gitLsRemote(url: string; withTags: bool): seq[tuple[tag: string, rev: string]] =
|
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)
|
startProcess("git", "ls-remote", "--tags", url)
|
||||||
else:
|
else:
|
||||||
startProcess("git", "ls-remote", url)
|
startProcess("git", "ls-remote", url)
|
||||||
while process.running:
|
while process.outputStream.readLine(line):
|
||||||
while process.outputStream.readLine(line):
|
var off = 0
|
||||||
var off = 0
|
off.inc parseUntil(line, rev, Whitespace, off)
|
||||||
off.inc parseUntil(line, rev, Whitespace, off)
|
off.inc skipWhile(line, Whitespace, off)
|
||||||
off.inc skipWhile(line, Whitespace, off)
|
refer = line[off..line.high]
|
||||||
refer = line[off..line.high]
|
const
|
||||||
const
|
refsTags = "refs/tags/"
|
||||||
refsTags = "refs/tags/"
|
headsTags = "refs/heads/"
|
||||||
headsTags = "refs/heads/"
|
if refer.startsWith(refsTags):
|
||||||
if refer.startsWith(refsTags):
|
refer.removePrefix(refsTags)
|
||||||
refer.removePrefix(refsTags)
|
result.add((refer, rev,))
|
||||||
elif refer.startsWith(headsTags):
|
elif refer.startsWith(headsTags):
|
||||||
refer.removePrefix(headsTags)
|
refer.removePrefix(headsTags)
|
||||||
result.add((refer, rev,))
|
result.add((refer, rev,))
|
||||||
stderr.write(process.errorStream.readAll)
|
stderr.write(process.errorStream.readAll)
|
||||||
close(process)
|
close(process)
|
||||||
|
if withTags and result.len == 0:
|
||||||
|
result = gitLsRemote(url, not withTags)
|
||||||
|
|
||||||
proc matchRev(url: string; wanted: VersionRange): tuple[tag: string, rev: string] =
|
proc matchRev(url: string; wanted: VersionRange): tuple[tag: string, rev: string] =
|
||||||
let withTags = wanted.kind != verAny
|
if wanted.kind == verSpecial:
|
||||||
let pairs = gitLsRemote(url, withTags)
|
let special = string(wanted.spe)
|
||||||
var resultVersion: Version
|
if special.len == 41 and special[0] == '#':
|
||||||
for (tag, rev) in pairs:
|
result[1] = special[1..39]
|
||||||
var tagVer = Version(tag)
|
else:
|
||||||
if tagVer.withinRange(wanted) and resultVersion < tagVer:
|
quit("unhandled version " & url & " " & $wanted)
|
||||||
resultVersion = tagVer
|
else:
|
||||||
result = (tag, rev)
|
let withTags = wanted.kind != verAny
|
||||||
if result.rev == "" and pairs.len > 0:
|
let pairs = gitLsRemote(url, withTags)
|
||||||
result = pairs[pairs.high]
|
var resultVersion: Version
|
||||||
doAssert result.rev != ""
|
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) =
|
proc collectMetadata(data: JsonNode) =
|
||||||
let storePath = data["path"].getStr
|
let storePath = data["path"].getStr
|
||||||
|
|
Loading…
Reference in New Issue