Add revlog.reachable to find a graph of ancestors for a given rev
authormason@suse.com
Fri, 26 Aug 2005 19:19:35 -0700
changeset 1074 55bf5cfde69e
parent 1073 7b35a980b982
child 1075 e254bcbfe636
Add revlog.reachable to find a graph of ancestors for a given rev
mercurial/revlog.py
--- a/mercurial/revlog.py	Fri Aug 26 19:08:25 2005 -0700
+++ b/mercurial/revlog.py	Fri Aug 26 19:19:35 2005 -0700
@@ -170,6 +170,28 @@
     def end(self, rev): return self.start(rev) + self.length(rev)
     def base(self, rev): return self.index[rev][2]
 
+    def reachable(self, rev, stop=None):
+        reachable = {}
+        visit = [rev]
+        reachable[rev] = 1
+        if stop:
+            stopn = self.rev(stop)
+        else:
+            stopn = 0
+        while visit:
+            n = visit.pop(0)
+            if n == stop:
+                continue
+            if n == nullid:
+                continue
+            for p in self.parents(n):
+                if self.rev(p) < stopn:
+                    continue
+                if p not in reachable:
+                    reachable[p] = 1
+                    visit.append(p)
+        return reachable
+
     def heads(self, stop=None):
         p = {}
         h = []