aboutsummaryrefslogtreecommitdiff
path: root/releng/gitutils.xsh
diff options
context:
space:
mode:
authorjade <lix@jade.fyi>2024-08-08 23:12:11 +0000
committerGerrit Code Review <gerrit@localhost>2024-08-08 23:12:11 +0000
commit3b902683e93ad21be3537ef77f3e5200fbbed900 (patch)
treecd2c01633d9530758da972e9ff97d22ddcc8b111 /releng/gitutils.xsh
parent9682ab4f3859ca60b0b4525452b27297e31cb751 (diff)
parent7246c2d104f12877de7d5b20033346eff88048e6 (diff)
Merge changes I0373ac01,I7b543967,I537103eb into main
* changes: releng: fix the git push releng: clarify/update docs, add instructions after tag Fix is_maintenance_branch heuristic
Diffstat (limited to 'releng/gitutils.xsh')
-rw-r--r--releng/gitutils.xsh39
1 files changed, 27 insertions, 12 deletions
diff --git a/releng/gitutils.xsh b/releng/gitutils.xsh
index e18b4da5f..d3b3774c0 100644
--- a/releng/gitutils.xsh
+++ b/releng/gitutils.xsh
@@ -1,11 +1,24 @@
import subprocess
-import json
+from packaging.version import Version
from .version import VERSION
+def remote_is_plausible(url: str) -> bool:
+ return ('git.lix.systems' in url and 'lix-project/lix' in url) or ('gerrit.lix.systems' in url and url.endswith('lix'))
+
+
def version_compare(v1: str, v2: str):
- return json.loads($(nix-instantiate --eval --json --argstr v1 @(v1) --argstr v2 @(v2) --expr '{v1, v2}: builtins.compareVersions v1 v2'))
+ v1 = Version(v1)
+ v2 = Version(v2)
+ if v1 < v2:
+ return -1
+ elif v1 > v2:
+ return 1
+ elif v1 == v2:
+ return 0
+ else:
+ raise ValueError('these versions are beyond each others celestial plane')
def latest_tag_on_branch(branch: str) -> str:
@@ -13,16 +26,18 @@ def latest_tag_on_branch(branch: str) -> str:
def is_maintenance_branch(branch: str) -> bool:
- try:
- main_tag = latest_tag_on_branch('main')
- current_tag = latest_tag_on_branch(branch)
-
- return version_compare(current_tag, main_tag) < 0
- except subprocess.CalledProcessError:
- # This is the case before Lix releases 2.90, since main *has* no
- # release tag on it.
- # FIXME: delete this case after 2.91
- return False
+ """
+ Returns whether the given branch is probably a maintenance branch.
+
+ This uses a heuristic: `main` should have a newer tag than a given
+ maintenance branch if there has been a major release since that maintenance
+ branch.
+ """
+ assert remote_is_plausible($(git remote get-url origin).strip())
+ main_tag = latest_tag_on_branch('origin/main')
+ current_tag = latest_tag_on_branch(branch)
+
+ return version_compare(current_tag, main_tag) < 0
def verify_are_on_tag():