revlog: put graph related functions together
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Tue, 13 Apr 2010 22:06:17 +0200
changeset 10897 adb6a291bbdb
parent 10895 217557b26bc7
child 10898 5589110e9170
revlog: put graph related functions together
mercurial/revlog.py
--- a/mercurial/revlog.py	Mon Apr 12 17:41:32 2010 -0700
+++ b/mercurial/revlog.py	Tue Apr 13 22:06:17 2010 +0200
@@ -845,6 +845,32 @@
                 c.append(self.node(r))
         return c
 
+    def descendant(self, start, end):
+        for i in self.descendants(start):
+            if i == end:
+                return True
+            elif i > end:
+                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))
+        if self.descendant(start, end):
+            return self.node(start)
+
+        def parents(rev):
+            return [p for p in self.parentrevs(rev) if p != nullrev]
+
+        c = ancestor.ancestor(a, b, parents)
+        if c is None:
+            return nullid
+
+        return self.node(c)
+
     def _match(self, id):
         if isinstance(id, (long, int)):
             # rev
@@ -1119,32 +1145,6 @@
             self._cache = (node, curr, text)
         return node
 
-    def descendant(self, start, end):
-        for i in self.descendants(start):
-            if i == end:
-                return True
-            elif i > end:
-                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))
-        if self.descendant(start, end):
-            return self.node(start)
-
-        def parents(rev):
-            return [p for p in self.parentrevs(rev) if p != nullrev]
-
-        c = ancestor.ancestor(a, b, parents)
-        if c is None:
-            return nullid
-
-        return self.node(c)
-
     def group(self, nodelist, lookup, infocollect=None):
         """Calculate a delta group, yielding a sequence of changegroup chunks
         (strings).