D583: commands: correctly show inactive multiheaded branches

the31k phabricator at mercurial-scm.org
Thu Aug 31 17:13:05 UTC 2017


the31k created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Issue being fixed here: 'hg branches' incorrectly renders inactive multiheaded
  branches as active if they have closed heads.
  
  Example:
  
  $ hg log -G --template '{rev} "{desc}" ({branch})\n'
  @    4 "merge" (default)
  
  | \                     |
  | o  3 "2" (somebranch) |
  |                       |
  |                       | _  2 "close" (somebranch) |
  |                       | /                         |
  | o  1 "1" (somebranch) |
  | /                     |
  |
  
  o  0 "initial" (default)
  
  $ hg branches
  default                        4:2e2fa7af8357
  somebranch                     3:7be622ae5832
  
  Branch 'somebranch' have two heads, the 1st one being closed (rev 2) and
  the other one being merged into default (rev 3). This branch should be shown as
  inactive one.
  
  This happens because we intersect branch heads with repo heads to check branch
  activity. In this case intersection in a set with one node (rev 2). This head
  is closed but the branch is marked as active nevertheless.
  
  Fix is to check branch activity by intersecting only open heads set.
  
  Fixed output:
  
  $ hg branches
  default                        4:2e2fa7af8357
  somebranch                     3:7be622ae5832 (inactive)

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D583

AFFECTED FILES
  mercurial/branchmap.py
  mercurial/commands.py

CHANGE DETAILS

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1077,7 +1077,10 @@
     allheads = set(repo.heads())
     branches = []
     for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
-        isactive = not isclosed and bool(set(heads) & allheads)
+        isactive = False
+        if not isclosed:
+            openheads = set(repo.branchmap().iteropen(heads))
+            isactive = bool(openheads & allheads)
         branches.append((tag, repo[tip], isactive, not isclosed))
     branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]),
                   reverse=True)
diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -211,10 +211,13 @@
         Raise KeyError for unknown branch.'''
         return self._branchtip(self[branch])[0]
 
+    def iteropen(self, nodes):
+        return (n for n in nodes if n not in self._closednodes)
+
     def branchheads(self, branch, closed=False):
         heads = self[branch]
         if not closed:
-            heads = [h for h in heads if h not in self._closednodes]
+            heads = list(self.iteropen(heads))
         return heads
 
     def iterbranches(self):



To: the31k, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list