changeset 1074:55bf5cfde69e

Add revlog.reachable to find a graph of ancestors for a given rev
author mason@suse.com
date Fri, 26 Aug 2005 19:19:35 -0700
parents 7b35a980b982
children e254bcbfe636
files mercurial/revlog.py
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 = []