[PATCH] Active branches fix (Issue 1104)
stefano at inventati.org
Wed May 7 03:22:31 CDT 2008
# HG changeset patch
# User Stefano Tortarolo <stefano at inventati.org>
# Date 1210148504 -7200
# Node ID f0cad1b79594d973b301a9e564ef0a07a4d86e69
# Parent 626cb86a6523c9e8b453719314dd31fa4d61ced3
Active branches fix (Issue 1104)
This patch solves the issue 1104, now every branch is marked active
whether it contains or not an unmerged revision (head).
It extracts the branch names from the heads, since they're
surely active branches (the original function's fault was indeed that it
wasn't able to detect properly active branches), then it scans for all
the existing branches in order to flag them 'inactive' or leave them 'active'.
This loop is necessary even if we want to print only active branches,
because it also allows to get the newer node of each active branch.
The original function, on the other hand, checked whether the last node
of a branch was in heads or not. This is clearly wrong, as pointed out
by the issue 1104.
Please note that the test-branches output is wrong as well.
The branch b is marked inactive since hg checks node 4, while it
should check node 3 and mark the branch active.
diff --git a/mercurial/commands.py b/mercurial/commands.py
@@ -372,30 +372,24 @@
List the repository's named branches, indicating which ones are
inactive. If active is specified, only show active branches.
- A branch is considered active if it contains unmerged heads.
+ A branch is considered active if it contains repository heads.
Use the command 'hg update' to switch to an existing branch.
- b = repo.branchtags()
- heads = dict.fromkeys(repo.heads(), 1)
- l = [((n in heads), repo.changelog.rev(n), n, t) for t, n in b.items()]
- for ishead, r, n, t in l:
- if active and not ishead:
- # If we're only displaying active branches, abort the loop on
- # encountering the first inactive head
- hexfunc = ui.debugflag and hex or short
+ hexfunc = ui.debugflag and hex or short
+ activebranches = [repo.changectx(n).branch() for n in repo.heads()]
+ for tag, node in repo.branchtags().items():
+ isactive = tag in activebranches
+ if (not active) or isactive:
- ui.write("%s\n" % t)
+ ui.write("%s\n" % tag)
- spaces = " " * (30 - util.locallen(t))
- # The code only gets here if inactive branches are being
- # displayed or the branch is active.
- isinactive = ((not ishead) and " (inactive)") or ''
- ui.write("%s%s %s:%s%s\n" % (t, spaces, r, hexfunc(n), isinactive))
+ spaces = " " * (30 - util.locallen(tag))
+ isinactive = ((not isactive) and " (inactive)") or ''
+ ui.write("%s%s %s:%s%s\n" % (tag, spaces,
+ repo.changelog.rev(node), hexfunc(node),
def bundle(ui, repo, fname, dest=None, **opts):
"""create a changegroup file
More information about the Mercurial-devel