changeset 10325:bc72e21f9dc8

revlog: add a fast path for checking ancestry
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Sat, 06 Feb 2010 11:27:22 +0100
parents 55d134ef8ab7
children 8b90e2966219
files mercurial/revlog.py
diffstat 1 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Sat Feb 06 10:23:18 2010 +0100
+++ b/mercurial/revlog.py	Sat Feb 06 11:27:22 2010 +0100
@@ -1137,17 +1137,22 @@
             self._cache = (node, curr, text)
         return node
 
+    def descendant(self, a, b):
+        if a > b:
+            return False
+        for i in self.descendants(a):
+            if i == b:
+                return True
+            elif i > b:
+                break
+        return False
+
     def ancestor(self, a, b):
         """calculate the least common ancestor of nodes a and b"""
 
-        # fast path, check if it is a descendant
-        a, b = self.rev(a), self.rev(b)
         start, end = sorted((a, b))
-        for i in self.descendants(start):
-            if i == end:
-                return self.node(start)
-            elif i > end:
-                break
+        if self.descendant(a, b):
+            return self.node(start)
 
         def parents(rev):
             return [p for p in self.parentrevs(rev) if p != nullrev]