@@ 0,0 1,93 @@
+#!/usr/bin/env python3
+import os
+import subprocess
+import sys
+
+if len(sys.argv) != 2:
+ print("Usage: {0} [patch|minor|major|<new version>]".format(sys.argv[0]))
+ sys.exit(1)
+
+if (
+ subprocess.run(["hg", "branch"], stdout=subprocess.PIPE)
+ .stdout.decode()
+ .strip()
+ != "stable"
+):
+ print("Exiting! Not on the stable branch.")
+ sys.exit(1)
+
+subprocess.run(["hg", "pull", "--rebase"])
+p = subprocess.run(
+ [
+ "hg",
+ "log",
+ "-r",
+ ".",
+ "-T",
+ "{latesttag}{sub('^-0-.*', '', '-{latesttagdistance}-m{node|short}')}",
+ ],
+ stdout=subprocess.PIPE,
+)
+describe = p.stdout.decode().strip()
+old_version = describe.split("-")[0].split(".")
+if len(old_version) == 2:
+ [major, minor] = old_version
+ [major, minor] = map(int, [major, minor])
+ patch = 0
+else:
+ [major, minor, patch] = old_version
+ [major, minor, patch] = map(int, [major, minor, patch])
+
+p = subprocess.run(
+ [
+ "hg",
+ "log",
+ "--no-merges",
+ "-T",
+ "{node|short} {desc|firstline}\n",
+ "-r",
+ f"{'.'.join(old_version)}:.",
+ ],
+ stdout=subprocess.PIPE,
+)
+shortlog = p.stdout.decode()
+
+new_version = None
+
+if sys.argv[1] == "patch":
+ patch += 1
+elif sys.argv[1] == "minor":
+ minor += 1
+ patch = 0
+elif sys.argv[1] == "major":
+ major += 1
+ minor = patch = 0
+else:
+ new_version = sys.argv[1]
+
+if new_version is None:
+ if len(old_version) == 2 and patch == 0:
+ new_version = f"{major}.{minor}"
+ else:
+ new_version = f"{major}.{minor}.{patch}"
+
+p = None
+if os.path.exists("contrib/_incr_version"):
+ p = subprocess.run(["contrib/_incr_version", describe, new_version])
+elif os.path.exists(".hg/_incr_version"):
+ print("Warning: _incr_version found at legacy path")
+ p = subprocess.run([".hg/_incr_version", describe, new_version])
+else:
+ print(
+ "Warning: no _incr_version script. "
+ + "Does this project have any specific release requirements?"
+ )
+
+if p and p.returncode != 0:
+ print("Error: _incr_version returned nonzero exit code")
+ sys.exit(1)
+
+basename = os.path.basename(os.getcwd())
+message = f"{basename} {new_version}\n\n{shortlog}"
+subprocess.run(["hg", "tag", "-e", "-m", f"{message}", new_version])
+print(new_version)