##// END OF EJS Templates
revlog.ancestors: add support for including revs...
Siddharth Agarwal -
r18081:f88c60e7 default
parent child Browse files
Show More
@@ -341,17 +341,27 b' class revlog(object):'
341 return len(t)
341 return len(t)
342 size = rawsize
342 size = rawsize
343
343
344 def ancestors(self, revs, stoprev=0):
344 def ancestors(self, revs, stoprev=0, inclusive=False):
345 """Generate the ancestors of 'revs' in reverse topological order.
345 """Generate the ancestors of 'revs' in reverse topological order.
346 Does not generate revs lower than stoprev.
346 Does not generate revs lower than stoprev.
347
347
348 Yield a sequence of revision numbers starting with the parents
348 If inclusive is False, yield a sequence of revision numbers starting
349 of each revision in revs, i.e., each revision is *not* considered
349 with the parents of each revision in revs, i.e., each revision is *not*
350 an ancestor of itself. Results are in breadth-first order:
350 considered an ancestor of itself. Results are in breadth-first order:
351 parents of each rev in revs, then parents of those, etc. Result
351 parents of each rev in revs, then parents of those, etc.
352 does not include the null revision."""
352
353 If inclusive is True, yield all the revs first (ignoring stoprev),
354 then yield all the ancestors of revs as when inclusive is False.
355 If an element in revs is an ancestor of a different rev it is not
356 yielded again.
357
358 Result does not include the null revision."""
353 visit = util.deque(revs)
359 visit = util.deque(revs)
354 seen = set([nullrev])
360 seen = set([nullrev])
361 if inclusive:
362 for rev in revs:
363 yield rev
364 seen.update(revs)
355 while visit:
365 while visit:
356 for parent in self.parentrevs(visit.popleft()):
366 for parent in self.parentrevs(visit.popleft()):
357 if parent < stoprev:
367 if parent < stoprev:
@@ -364,10 +374,7 b' class revlog(object):'
364 def incancestors(self, revs, stoprev=0):
374 def incancestors(self, revs, stoprev=0):
365 """Identical to ancestors() except it also generates the
375 """Identical to ancestors() except it also generates the
366 revisions, 'revs'"""
376 revisions, 'revs'"""
367 for rev in revs:
377 return self.ancestors(revs, stoprev, inclusive=True)
368 yield rev
369 for rev in self.ancestors(revs, stoprev):
370 yield rev
371
378
372 def descendants(self, revs):
379 def descendants(self, revs):
373 """Generate the descendants of 'revs' in revision order.
380 """Generate the descendants of 'revs' in revision order.
@@ -62,6 +62,14 b" if __name__ == '__main__':"
62 for r in repo.changelog.ancestors([7], 6):
62 for r in repo.changelog.ancestors([7], 6):
63 print r,
63 print r,
64
64
65 print '\nAncestors of 7, including revs'
66 for r in repo.changelog.ancestors([7], inclusive=True):
67 print r,
68
69 print '\nAncestors of 7, 5 and 3, including revs'
70 for r in repo.changelog.ancestors([7, 5, 3], inclusive=True):
71 print r,
72
65 # Descendants
73 # Descendants
66 print '\n\nDescendants of 5'
74 print '\n\nDescendants of 5'
67 for r in repo.changelog.descendants([5]):
75 for r in repo.changelog.descendants([5]):
@@ -6,6 +6,10 b' Ancestors of 5 and 4'
6 4 2 0
6 4 2 0
7 Ancestors of 7, stop at 6
7 Ancestors of 7, stop at 6
8 6
8 6
9 Ancestors of 7, including revs
10 7 6 5 3 4 2 1 0
11 Ancestors of 7, 5 and 3, including revs
12 7 5 3 6 4 2 1 0
9
13
10 Descendants of 5
14 Descendants of 5
11 7 8
15 7 8
General Comments 0
You need to be logged in to leave comments. Login now