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 |
|
|
348 | If inclusive is False, yield a sequence of revision numbers starting | |
349 |
of each revision in revs, i.e., each revision is *not* |
|
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. |
|
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]): |
General Comments 0
You need to be logged in to leave comments.
Login now