[PATCH] revlog: add optional stoprev arg to revlog.ancestors()
Joshua Redstone
joshua.redstone at fb.com
Fri Jun 1 17:47:27 CDT 2012
# HG changeset patch
# User Joshua Redstone <joshua.redstone at fb.com>
# Date 1338590653 25200
# Node ID d06296b22b1d2e93e836ea5742e06b37e4c09dbf
# Parent 82a0af4e593f0ce9f0bc189b09c3410471a01320
revlog: add optional stoprev arg to revlog.ancestors()
This will be used as a step in removing reachable() in a future diff.
Doing it now because bryano is in the process of rewriting ancestors in
C. This depends on bryano's patch to replace *revs with revs in the
declaration of revlog.ancestors.
diff -r 82a0af4e593f -r d06296b22b1d mercurial/revlog.py
--- a/mercurial/revlog.py Fri Jun 01 09:13:55 2012 -0700
+++ b/mercurial/revlog.py Fri Jun 01 15:44:13 2012 -0700
@@ -381,8 +381,9 @@
visit.append(p)
return reachable
- def ancestors(self, revs):
+ def ancestors(self, revs, stoprev=0):
"""Generate the ancestors of list of revs in reverse topological order.
+ Does not generate revs lower than stoprev.
Yield a sequence of revision numbers starting with the parents
of each revision in revs, i.e., each revision is *not* considered
@@ -393,6 +394,8 @@
seen = set([nullrev])
while visit:
for parent in self.parentrevs(visit.pop(0)):
+ if parent < stoprev:
+ continue
if parent not in seen:
visit.append(parent)
seen.add(parent)
diff -r 82a0af4e593f -r d06296b22b1d tests/test-revlog-ancestry.py
--- a/tests/test-revlog-ancestry.py Fri Jun 01 09:13:55 2012 -0700
+++ b/tests/test-revlog-ancestry.py Fri Jun 01 15:44:13 2012 -0700
@@ -58,6 +58,10 @@
for r in repo.changelog.ancestors([5, 4]):
print r,
+ print '\nAncestors of 7, stop at 6'
+ for r in repo.changelog.ancestors([7], 6):
+ print r,
+
# Descendants
print '\n\nDescendants of 5'
for r in repo.changelog.descendants(5):
diff -r 82a0af4e593f -r d06296b22b1d tests/test-revlog-ancestry.py.out
--- a/tests/test-revlog-ancestry.py.out Fri Jun 01 09:13:55 2012 -0700
+++ b/tests/test-revlog-ancestry.py.out Fri Jun 01 15:44:13 2012 -0700
@@ -4,6 +4,8 @@
3 4 2 1 0
Ancestors of 5 and 4
4 2 0
+Ancestors of 7, stop at 6
+6
Descendants of 5
7 8
More information about the Mercurial-devel
mailing list