--- a/mercurial/commands.py Thu Jun 21 11:54:16 2007 -0500
+++ b/mercurial/commands.py Thu Jun 21 10:40:09 2007 -0700
@@ -237,21 +237,34 @@
else:
ui.write("%s\n" % util.tolocal(repo.dirstate.branch()))
-def branches(ui, repo):
+def branches(ui, repo, active=False):
"""list repository named branches
- List the repository's named branches.
+ 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.
"""
b = repo.branchtags()
- l = [(-repo.changelog.rev(n), n, t) for t, n in b.items()]
+ heads = dict.fromkeys(repo.heads(), 1)
+ l = [((n in heads), repo.changelog.rev(n), n, t) for t, n in b.items()]
l.sort()
- for r, n, t in l:
- hexfunc = ui.debugflag and hex or short
- if ui.quiet:
- ui.write("%s\n" % t)
+ l.reverse()
+ 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
+ break
else:
- spaces = " " * (30 - util.locallen(t))
- ui.write("%s%s %s:%s\n" % (t, spaces, -r, hexfunc(n)))
+ hexfunc = ui.debugflag and hex or short
+ if ui.quiet:
+ ui.write("%s\n" % t)
+ else:
+ 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))
def bundle(ui, repo, fname, dest=None, **opts):
"""create a changegroup file
@@ -2738,7 +2751,10 @@
[('f', 'force', None,
_('set branch name even if it shadows an existing branch'))],
_('hg branch [NAME]')),
- "branches": (branches, [], _('hg branches')),
+ "branches": (branches,
+ [('a', 'active', False,
+ _("show only branches that have unmerged heads"))],
+ _('hg branches [-a]')),
"bundle":
(bundle,
[('f', 'force', None,