[PATCH 2 of 2] Change revlog.heads to walk the revision graph using revision numbers

Alexis S. L. Carvalho alexis at cecm.usp.br
Tue Jun 20 14:10:03 CDT 2006


# HG changeset patch
# User Alexis S. L. Carvalho <alexis at cecm.usp.br>
# Date 1150826543 10800
# Node ID 75a63552af5ca00f69af7d63a3b717a57f0fe00e
# Parent  6f4d04f79b2da53783942cf141d65f9b1f93f02e
Change revlog.heads to walk the revision graph using revision numbers

On the kernel repo:
$ hg heads -q
           before    after
RevlogNG    1.11     0.52
Revlogv0    0.80     0.69

Since the current code for tags has to find all the heads of the repo,
this also helps there:
$ hg tags
           before    after
RevlogNG    2.35     1.76
Revlogv0    2.04     1.90

diff -r 6f4d04f79b2d -r 75a63552af5c mercurial/revlog.py
--- a/mercurial/revlog.py	Tue Jun 20 14:57:30 2006 -0300
+++ b/mercurial/revlog.py	Tue Jun 20 15:02:23 2006 -0300
@@ -713,19 +713,19 @@ class revlog(object):
         """
         if start is None:
             start = nullid
-        reachable = {start: 1}
-        heads = {start: 1}
         startrev = self.rev(start)
-
+        reachable = {startrev: 1}
+        heads = {startrev: 1}
+
+        parentrevs = self.parentrevs
         for r in xrange(startrev + 1, self.count()):
-            n = self.node(r)
-            for pn in self.parents(n):
-                if pn in reachable:
-                    reachable[n] = 1
-                    heads[n] = 1
-                if pn in heads:
-                    del heads[pn]
-        return heads.keys()
+            for p in parentrevs(r):
+                if p in reachable:
+                    reachable[r] = 1
+                    heads[r] = 1
+                if p in heads:
+                    del heads[p]
+        return [self.node(r) for r in heads]
 
     def children(self, node):
         """find the children of a given node"""


More information about the Mercurial mailing list