[PATCH 5 of 5] Change branches to only show 'active' branches by default. Add an option to show all branches
Eric Hopper
hopper at omnifarious.org
Tue Jun 5 16:59:06 UTC 2007
# HG changeset patch
# User Eric Hopper <hopper at omnifarious.org>
# Date 1181060557 25200
# Node ID 70dcd512007417bc4494491624c21985afbcdbd2
# Parent 3e2dbd9da8f1f83458467479d401bcd3315e0572
Change branches to only show 'active' branches by default. Add an option to show all branches.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -271,13 +271,18 @@ 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, all=False):
"""list repository named branches
- List the repository's named branches.
+ List the repository's named branches. By default omit the
+ branches that have no heads.
"""
b = repo.branchtags()
- l = [(-repo.changelog.rev(n), n, t) for t, n in b.items()]
+ if all:
+ l = [(-repo.changelog.rev(n), n, t) for t, n in b.items()]
+ else:
+ heads = dict.fromkeys(repo.heads(), 1)
+ l = [(-repo.changelog.rev(n), n, t) for t, n in b.items() if n in heads]
l.sort()
for r, n, t in l:
hexfunc = ui.debugflag and hex or short
@@ -2720,7 +2725,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', 'all', False,
+ _("show even dead branches that have no active heads"))],
+ _('hg branches [-a]')),
"bundle":
(bundle,
[('f', 'force', None,
diff --git a/tests/test-encoding b/tests/test-encoding
--- a/tests/test-encoding
+++ b/tests/test-encoding
@@ -42,11 +42,11 @@ echo % utf-8
echo % utf-8
HGENCODING=utf-8 hg tags
echo % ascii
-HGENCODING=ascii hg branches
+HGENCODING=ascii hg branches -a
echo % latin-1
-HGENCODING=latin-1 hg branches
+HGENCODING=latin-1 hg branches -a
echo % utf-8
-HGENCODING=utf-8 hg branches
+HGENCODING=utf-8 hg branches -a
echo '[ui]' >> .hg/hgrc
echo 'fallbackencoding = koi8-r' >> .hg/hgrc
diff --git a/tests/test-newbranch b/tests/test-newbranch
--- a/tests/test-newbranch
+++ b/tests/test-newbranch
@@ -2,7 +2,7 @@
hg init t
cd t
-hg branches
+hg branches -a
echo foo > a
hg add a
@@ -27,8 +27,8 @@ hg ci -m "merge" -d "1000000 0"
hg ci -m "merge" -d "1000000 0"
hg log
-hg branches
-hg branches -q
+hg branches -a
+hg branches -qa
echo % test for invalid branch cache
hg rollback
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-devel/attachments/20070605/677ad132/attachment.asc>
More information about the Mercurial-devel
mailing list