[PATCH 8 of 8] changelog: exclude abandoned changesets from heads

Martin Geisler mg at lazybytes.net
Wed Jun 1 11:42:54 CDT 2011


# HG changeset patch
# User Martin Geisler <mg at lazybytes.net>
# Date 1306946536 -7200
# Node ID cdb30508594ea84cc81a1ab3c6adf7c9b17e6691
# Parent  ff0d35c68b063db94e29809ac52281f099b9e365
changelog: exclude abandoned changesets from heads

This effectively cuts off the abandoned changesets from the changelog
graph.

  Issues: Tests are not yet updated to match new output as I'm unsure
  this is the right way to go.

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -311,8 +311,9 @@
             if 'DEBUG' in os.environ:
                 print 'found no cache on disk, rebuilding'
             # no suitable cache found on disk, recompute
+            heads = [self.node(r) for r in self.headrevs()]
             abandoned = {}
-            for head in self.heads():
+            for head in heads:
                 extra = self.read(head)[5]
                 if 'abandon' in extra:
                     for node in extra['abandon'].split(' '):
@@ -320,7 +321,7 @@
                     abandoned[head] = head
 
             for node in abandoned.copy():
-                for head in self.heads():
+                for head in heads:
                     if (head not in abandoned and self.ancestor(head, node) == node):
                         del abandoned[node]
 
@@ -329,6 +330,15 @@
         self._abandonedcache = abandoned
         self._abandonedtip = tip
 
+    def heads(self, start=None, stop=None, abandoned=False):
+        if not abandoned:
+            stop = self.allabandoned().keys()
+        return revlog.revlog.heads(self, start, stop)
+
+    def allabandoned(self):
+        self.updateabandonedcache()
+        return self._abandonedcache
+
     def abandoned(self, node):
         self.updateabandonedcache()
         return self._abandonedcache.get(node)
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2502,6 +2502,7 @@
     ('t', 'topo', False, _('show topological heads only')),
     ('a', 'active', False, _('show active branchheads only (DEPRECATED)')),
     ('c', 'closed', False, _('show normal and closed branch heads')),
+    ('', 'abandoned', False, _('show abandoned heads')),
     ] + templateopts,
     _('[-ac] [-r STARTREV] [REV]...'))
 def heads(ui, repo, *branchrevs, **opts):
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1367,8 +1367,8 @@
             l.sort()
         return r
 
-    def heads(self, start=None):
-        heads = self.changelog.heads(start)
+    def heads(self, start=None, abandoned=False):
+        heads = self.changelog.heads(start, abandoned=abandoned)
         # sort the output in rev descending order
         return sorted(heads, key=self.changelog.rev, reverse=True)
 
diff --git a/tests/test-abandoned.t b/tests/test-abandoned.t
--- a/tests/test-abandoned.t
+++ b/tests/test-abandoned.t
@@ -50,6 +50,10 @@
   1 0b00c28422ee x
   0 54dbcd775ef0 init
 
+abandoned changesets are hidden in heads
+
+  $ hg heads
+
 new revset keyword
 
   $ hg log --abandoned -r 'abandoned()'


More information about the Mercurial-devel mailing list