Merge pull request #9660 from borgbackup/ai-findings-autofix/src-borg-version.py

improve versioning code
This commit is contained in:
TW 2026-05-22 12:40:36 +02:00 committed by GitHub
commit 45eeb1ba3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -38,12 +38,19 @@ def format_version(version):
f = []
it = iter(version)
while True:
part = next(it)
try:
part = next(it)
except StopIteration:
raise ValueError("Invalid version tuple %r" % (version,))
if part >= 0:
f.append(str(part))
elif part == -1:
break
else:
f[-1] = f[-1] + {-2: "rc", -3: "b", -4: "a", -9: ".dev"}[part] + str(next(it))
try:
pnum = next(it)
except StopIteration:
raise ValueError("Invalid prerelease version tuple %r" % (version,))
f[-1] = f[-1] + {-2: "rc", -3: "b", -4: "a", -9: ".dev"}[part] + str(pnum)
break
return ".".join(f)