[PATCH 6 of 6] Change branches to sort 'active' branches first, and add an option to show only active branches
Eric Hopper
hopper at omnifarious.org
Thu Jun 7 17:58:33 CDT 2007
# HG changeset patch
# User Eric Hopper <hopper at omnifarious.org>
# Date 1181256560 25200
# Node ID 2de8ff77d4f6c08577903153e0a2bfb6f9ad9844
# Parent aa3b7f16a887f0a2849499b847248ad89d4f5d6d
Change branches to sort 'active' branches first, and add an option to show only active branches.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -271,21 +271,34 @@ def branch(ui, repo, label=None, **opts)
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
@@ -2727,7 +2740,10 @@ table = {
[('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,
diff --git a/tests/test-encoding.out b/tests/test-encoding.out
--- a/tests/test-encoding.out
+++ b/tests/test-encoding.out
@@ -126,13 +126,13 @@ tip 5:db5
?? 3:770b9b11621d
% ascii
? 5:db5520b4645f
-default 4:9cff3c980b58
+default 4:9cff3c980b58 (inactive)
% latin-1
? 5:db5520b4645f
-default 4:9cff3c980b58
+default 4:9cff3c980b58 (inactive)
% utf-8
?? 5:db5520b4645f
-default 4:9cff3c980b58
+default 4:9cff3c980b58 (inactive)
% utf-8
changeset: 5:db5520b4645f
branch: ??
diff --git a/tests/test-newbranch.out b/tests/test-newbranch.out
--- a/tests/test-newbranch.out
+++ b/tests/test-newbranch.out
@@ -45,8 +45,8 @@ summary: initial
summary: initial
foo 5:5f8fb06e083e
-default 3:bf1bc2f45e83
-bar 2:67ec16bde7f1
+default 3:bf1bc2f45e83 (inactive)
+bar 2:67ec16bde7f1 (inactive)
foo
default
bar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20070607/566edd81/attachment.pgp
More information about the Mercurial-devel
mailing list