Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 18090:9abc55ef85b5
revlog: move ancestor generation out to a new class
This refactoring is to prepare for implementing lazy membership.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Tue, 18 Dec 2012 10:14:01 -0800 |
parents | 717c692fa449 |
children | b280f3bfc8a0 |
comparison
equal
deleted
inserted
replaced
18089:0127366df8fe | 18090:9abc55ef85b5 |
---|---|
343 | 343 |
344 def ancestors(self, revs, stoprev=0, inclusive=False): | 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 If inclusive is False, yield a sequence of revision numbers starting | 348 See the documentation for ancestor.lazyancestors for more details.""" |
349 with the parents of each revision in revs, i.e., each revision is *not* | 349 |
350 considered an ancestor of itself. Results are in breadth-first order: | 350 return ancestor.lazyancestors(self, revs, stoprev=stoprev, |
351 parents of each rev in revs, then parents of those, etc. | 351 inclusive=inclusive) |
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.""" | |
359 visit = util.deque(revs) | |
360 seen = set([nullrev]) | |
361 if inclusive: | |
362 for rev in revs: | |
363 yield rev | |
364 seen.update(revs) | |
365 while visit: | |
366 for parent in self.parentrevs(visit.popleft()): | |
367 if parent < stoprev: | |
368 continue | |
369 if parent not in seen: | |
370 visit.append(parent) | |
371 seen.add(parent) | |
372 yield parent | |
373 | 352 |
374 def descendants(self, revs): | 353 def descendants(self, revs): |
375 """Generate the descendants of 'revs' in revision order. | 354 """Generate the descendants of 'revs' in revision order. |
376 | 355 |
377 Yield a sequence of revision numbers starting with a child of | 356 Yield a sequence of revision numbers starting with a child of |