# Date 1779395353 -7200
# Thu May 21 22:29:13 2026 +0200
# Branch stable
# Node ID c5fb1c5ac3575429e68d1d2d99cfae4260a7faa3
# Parent 2d585c420697fa0a6a7162e6549296cdeab89a24
hg72: handle repo.branchheads being removed from branchmap in hg >= 7.2
The removal happened on 2025-11-06, in mercurial commit a49c8fe2c986
("branchmap: drop the `repo.branchheads` method"), and was integrated in
mercurial 7.2.
From at least 2019 (and possibly before), in mercurial, branchmap was already
exposing a branchheads() method.
Unfortunately, we can't se this solution, because branchmap.branchheads() is
buggy in 7.0.1 <= hg < 7.2.
Mercurial fixed that problem in 0969bb749bec ("branchmap: accept missing
`branch` in `branchheads`"), integrated in 7.2.
For this reason, we have to resort to explicitly perform version checking.
This changeset is inspired to what mercurial has done on 2025-11-06 in
dff46af5e54d ("branchmap: directly use the branchmap in `summary`").
From this commit on, tortoisehg is working under mercurial >= 7.2, while keeping
compatibility with hg <= 7.1.2.
diff --git a/tortoisehg/hgqt/csinfo.py b/tortoisehg/hgqt/csinfo.py
--- a/tortoisehg/hgqt/csinfo.py
+++ b/tortoisehg/hgqt/csinfo.py
@@ -253,7 +253,7 @@ class SummaryInfo:
else:
return None
elif item == 'ishead':
- return ctx.node() in ctx.repo().branchheads(ctx.branch())
+ return ctx.node() in hglib.branchheads(ctx.repo(), ctx.branch())
elif item == 'mqoriginalparent':
target = ctx.thgmqoriginalparent()
if not target:
diff --git a/tortoisehg/hgqt/repomodel.py b/tortoisehg/hgqt/repomodel.py
--- a/tortoisehg/hgqt/repomodel.py
+++ b/tortoisehg/hgqt/repomodel.py
@@ -833,7 +833,7 @@ class HgRepoListModel(QAbstractTableMode
try:
branchheads = self._branchheads[branch]
except KeyError:
- branchheads = set(self.repo.branchheads(branch))
+ branchheads = set(hglib.branchheads(self.repo, branch))
self._branchheads[branch] = branchheads
if ctx.rev() is None:
diff --git a/tortoisehg/hgqt/sync.py b/tortoisehg/hgqt/sync.py
--- a/tortoisehg/hgqt/sync.py
+++ b/tortoisehg/hgqt/sync.py
@@ -351,7 +351,7 @@ class SyncWidget(QWidget, qtlib.TaskWidg
for name in ctx.bookmarks():
uname = hglib.tounicode(name)
return self.targetcombo.findText(_('bookmark: ') + uname)
- if ctx.node() in self.repo.branchheads(ctx.branch()):
+ if ctx.node() in hglib.branchheads(self.repo, ctx.branch()):
uname = hglib.tounicode(ctx.branch())
return self.targetcombo.findText(_('branch: ') + uname)
return 0
diff --git a/tortoisehg/util/hglib.py b/tortoisehg/util/hglib.py
--- a/tortoisehg/util/hglib.py
+++ b/tortoisehg/util/hglib.py
@@ -1452,10 +1452,27 @@ def parsecmdline(cmdline: str, cwd: str)
args.append(e)
+if util.versiontuple() >= (7, 2):
+ def branchheads(repo, branch):
+ # This code is API-compatible with very ancient mercurial versions, but
+ # it is bugged in hg >= 7.0 and hg < 7.2.
+ #
+ # Consequently, we have to do an explicit version check and only
+ # activate it for hg >= 7.2.
+ return repo.branchmap().branchheads(branch)
+else:
+ def branchheads(repo, branch):
+ # Original thg code (up to thg <= 7.0.1), compatible with hg < 7.2.
+ #
+ # Mercurial 7.2 removed support for repo.branchheads() in a49c8fe2c986
+ # ("branchmap: drop the `repo.branchheads` method").
+ return repo.branchheads(branch)
+
+
def createsnewhead(ctx, branch_heads=None):
branch = ctx.branch()
if branch_heads is None:
- branch_heads = set(ctx.repo().branchheads(branch))
+ branch_heads = set(branchheads(ctx.repo(), branch))
return branch_heads and not any(