diff mercurial/revlog.py @ 1550:ccb9b62de892

add a -r/--rev option to heads to show only heads descendant from rev
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Wed, 16 Nov 2005 12:08:25 +0100
parents 7ae0ce7a3dc4
children e793cbc8be00
line wrap: on
line diff
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -409,25 +409,23 @@ class revlog:
         assert heads
         return (orderedout, roots, heads)
 
-    def heads(self, stop=None):
-        """return the list of all nodes that have no children"""
-        p = {}
-        h = []
-        stoprev = 0
-        if stop and stop in self.nodemap:
-            stoprev = self.rev(stop)
+    def heads(self, start=nullid):
+        """return the list of all nodes that have no children
+        if start is specified, only heads that are children of
+        start will be returned"""
+        reachable = {start: 1}
+        heads = {start: 1}
+        startrev = self.rev(start)
 
-        for r in range(self.count() - 1, -1, -1):
+        for r in xrange(startrev + 1, self.count()):
             n = self.node(r)
-            if n not in p:
-                h.append(n)
-            if n == stop:
-                break
-            if r < stoprev:
-                break
             for pn in self.parents(n):
-                p[pn] = 1
-        return h
+                if pn in reachable:
+                    reachable[n] = 1
+                    heads[n] = 1
+                if pn in heads:
+                    del heads[pn]
+        return heads.keys()
 
     def children(self, node):
         """find the children of a given node"""