changeset 4676:0f6e2b37512d

Merge with Eric Hopper
author Matt Mackall <mpm@selenic.com>
date Thu, 21 Jun 2007 18:05:14 -0500
parents 723e0ddb6ada (current diff) 6858a7477a5e (diff)
children de8ec7e1753a
files mercurial/commands.py tests/test-branches
diffstat 5 files changed, 79 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Thu Jun 21 18:02:03 2007 -0500
+++ b/mercurial/commands.py	Thu Jun 21 18:05:14 2007 -0500
@@ -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
@@ -2746,7 +2759,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,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-branches	Thu Jun 21 18:05:14 2007 -0500
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+hg init a
+cd a
+echo 'root' >root
+hg add root
+hg commit -d '0 0' -u test -m "Adding root node"
+
+echo 'a' >a
+hg add a
+hg branch a
+hg commit -d '1 0' -u test -m "Adding a branch"
+
+hg update -C 0
+echo 'b' >b
+hg add b
+hg branch b
+hg commit -d '2 0' -u test -m "Adding b branch"
+
+echo 'bh1' >bh1
+hg add bh1
+hg commit -d '3 0' -u test -m "Adding b branch head 1"
+
+hg update -C 2
+echo 'bh2' >bh2
+hg add bh2
+hg commit -d '4 0' -u test -m "Adding b branch head 2"
+
+echo 'c' >c
+hg add c
+hg branch c
+hg commit -d '5 0' -u test -m "Adding c branch"
+
+hg branches
+echo '-------'
+hg branches -a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-branches.out	Thu Jun 21 18:05:14 2007 -0500
@@ -0,0 +1,12 @@
+marked working directory as branch a
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+marked working directory as branch b
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+marked working directory as branch c
+c                              5:5ca481e59b8c
+a                              1:dd6b440dd85a
+b                              4:22df7444f7c1 (inactive)
+default                        0:19709c5a4e75 (inactive)
+-------
+c                              5:5ca481e59b8c
+a                              1:dd6b440dd85a
--- a/tests/test-encoding.out	Thu Jun 21 18:02:03 2007 -0500
+++ b/tests/test-encoding.out	Thu Jun 21 18:05:14 2007 -0500
@@ -127,13 +127,13 @@
 é                                  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:      é
--- a/tests/test-newbranch.out	Thu Jun 21 18:02:03 2007 -0500
+++ b/tests/test-newbranch.out	Thu Jun 21 18:05:14 2007 -0500
@@ -48,8 +48,8 @@
 summary:     initial
 
 foo                            5:5f8fb06e083e
-default                        3:bf1bc2f45e83
-bar                            2:67ec16bde7f1
+default                        3:bf1bc2f45e83 (inactive)
+bar                            2:67ec16bde7f1 (inactive)
 foo
 default
 bar