[PATCH] Active branches fix (Issue 1104)

Stefano Tortarolo stefano at inventati.org
Sun Apr 27 15:25:05 CDT 2008


# HG changeset patch
# User Stefano Tortarolo <stefano at inventati.org>
# Date 1209326564 -7200
# Node ID 17006b75611fc1d8b3ae50b1d2460067004beabd
# Parent  626cb86a6523c9e8b453719314dd31fa4d61ced3
imported patch issue1104_active_branch.patch

diff -r 626cb86a6523 -r 17006b75611f mercurial/commands.py
--- a/mercurial/commands.py	Thu Apr 24 17:16:02 2008 +0200
+++ b/mercurial/commands.py	Sun Apr 27 22:02:44 2008 +0200
@@ -376,26 +376,20 @@
 
     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()]
-    l.sort()
-    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:
-            hexfunc = ui.debugflag and hex or short
+    branchact = [repo.changectx(n).branch() for n in repo.heads()]
+    hexfunc = ui.debugflag and hex or short
+
+    for tag, node in repo.branchtags().items():
+        isactive = tag in branchact
+        if (not active) or isactive:
             if ui.quiet:
-                ui.write("%s\n" % t)
+                ui.write("%s\n" % tag)
             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))
+                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),
+                                isinactive))
 
 def bundle(ui, repo, fname, dest=None, **opts):
     """create a changegroup file


More information about the Mercurial-devel mailing list