# HG changeset patch # User Joshua Redstone # Date 2012-06-01 22:44:13 # Node ID eb88ed4269c5f211837b5960040a7002c89718c6 # Parent 1093ad1e890348078fdffdc0dd0ee5791b16f3e6 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 --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -381,8 +381,9 @@ class revlog(object): visit.append(p) return reachable - def ancestors(self, revs): + def ancestors(self, revs, stoprev=0): """Generate the ancestors 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 @@ class revlog(object): seen = set([nullrev]) while visit: for parent in self.parentrevs(visit.popleft()): + if parent < stoprev: + continue if parent not in seen: visit.append(parent) seen.add(parent) diff --git a/tests/test-revlog-ancestry.py b/tests/test-revlog-ancestry.py --- a/tests/test-revlog-ancestry.py +++ b/tests/test-revlog-ancestry.py @@ -58,6 +58,10 @@ if __name__ == '__main__': 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 --git a/tests/test-revlog-ancestry.py.out b/tests/test-revlog-ancestry.py.out --- a/tests/test-revlog-ancestry.py.out +++ b/tests/test-revlog-ancestry.py.out @@ -4,6 +4,8 @@ Ancestors of 6 and 5 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