Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 39999:0b24fcd88066
dagop: extract descendants() from revlog module
This method needs to be implemented in other storage backends and is
generic if we parameterize the functions for retrieving revision
numbers and parent revision numbers.
Let's extract it to dagop so backends don't need to reinvent the
wheel.
I'm not too worried about performance overhead of the extra function
call because I don't expect anyone to be calling descendants() in a
tight loop.
Differential Revision: https://phab.mercurial-scm.org/D4794
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 28 Sep 2018 10:03:32 -0700 |
parents | d70e620ee8c9 |
children | 8af835af0a85 |
comparison
equal
deleted
inserted
replaced
39998:44c98cbc665f | 39999:0b24fcd88066 |
---|---|
746 | 746 |
747 return ancestor.lazyancestors(self.parentrevs, revs, stoprev=stoprev, | 747 return ancestor.lazyancestors(self.parentrevs, revs, stoprev=stoprev, |
748 inclusive=inclusive) | 748 inclusive=inclusive) |
749 | 749 |
750 def descendants(self, revs): | 750 def descendants(self, revs): |
751 """Generate the descendants of 'revs' in revision order. | 751 return dagop.descendantrevs(revs, self.revs, self.parentrevs) |
752 | |
753 Yield a sequence of revision numbers starting with a child of | |
754 some rev in revs, i.e., each revision is *not* considered a | |
755 descendant of itself. Results are ordered by revision number (a | |
756 topological sort).""" | |
757 first = min(revs) | |
758 if first == nullrev: | |
759 for i in self: | |
760 yield i | |
761 return | |
762 | |
763 seen = set(revs) | |
764 for i in self.revs(start=first + 1): | |
765 for x in self.parentrevs(i): | |
766 if x != nullrev and x in seen: | |
767 seen.add(i) | |
768 yield i | |
769 break | |
770 | 752 |
771 def findcommonmissing(self, common=None, heads=None): | 753 def findcommonmissing(self, common=None, heads=None): |
772 """Return a tuple of the ancestors of common and the ancestors of heads | 754 """Return a tuple of the ancestors of common and the ancestors of heads |
773 that are not ancestors of common. In revset terminology, we return the | 755 that are not ancestors of common. In revset terminology, we return the |
774 tuple: | 756 tuple: |