prefer versions with the same prefix

This commit is contained in:
figsoda 2022-11-29 12:44:09 -05:00
parent 9838795b16
commit 0dea3ba6f3
2 changed files with 29 additions and 1 deletions

View File

@ -139,8 +139,12 @@ def update_version(
else:
if not package.parsed_url:
raise UpdateError("Could not find a url in the derivations src attribute")
version_prefix = ""
if preference != VersionPreference.BRANCH:
branch = None
if package.rev and package.rev.endswith(package.old_version):
version_prefix = package.rev.removesuffix(package.old_version)
elif version == "branch":
# fallback
branch = "HEAD"
@ -148,7 +152,12 @@ def update_version(
assert version.startswith("branch=")
branch = version[7:]
new_version = fetch_latest_version(
package.parsed_url, preference, version_regex, branch
package.parsed_url,
preference,
version_regex,
branch,
package.rev,
version_prefix,
)
package.new_version = new_version
position = package.version_position

View File

@ -60,6 +60,8 @@ def fetch_latest_version(
preference: VersionPreference,
version_regex: str,
branch: Optional[str] = None,
old_rev: Optional[str] = None,
version_prefix: str = "",
) -> Version:
unstable: List[str] = []
filtered: List[str] = []
@ -82,6 +84,23 @@ def fetch_latest_version(
else:
final.append(extracted)
if final != []:
if version_prefix != "":
ver = next(
(
Version(
version.number.removeprefix(version_prefix),
prerelease=version.prerelease,
rev=version.number,
)
for version in final
if version.number.startswith(version_prefix)
),
None,
)
if ver is not None and ver.rev != old_rev:
return ver
return final[0]
if filtered: