Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 38664:160da69ba1bf
revlog: replace descendant(b, a) by isdescendantrev(a, b) (API)
The "is" is to match "isancestor" and to make it clear that it doesn't
return a descendant. The "rev" is to make it clear that it's not about
nodeids (unlike e.g. isancestor()). The argument order change is just
seems more natural (and makes isancestor() less confusing).
Differential Revision: https://phab.mercurial-scm.org/D3929
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 11 Jul 2018 16:21:41 -0700 |
parents | 93d9690ff2b0 |
children | 6afa928033bd |
comparison
equal
deleted
inserted
replaced
38663:93d9690ff2b0 | 38664:160da69ba1bf |
---|---|
1643 c.append(self.node(r)) | 1643 c.append(self.node(r)) |
1644 elif p == nullrev: | 1644 elif p == nullrev: |
1645 c.append(self.node(r)) | 1645 c.append(self.node(r)) |
1646 return c | 1646 return c |
1647 | 1647 |
1648 def descendant(self, start, end): | 1648 def isdescendantrev(self, a, b): |
1649 """True if revision 'end' is an descendant of revision 'start' | 1649 """True if revision a is a descendant of revision b |
1650 | 1650 |
1651 A revision is considered as a descendant of itself. | 1651 A revision is considered a descendant of itself. |
1652 | 1652 |
1653 The implementation of this is trivial but the use of | 1653 The implementation of this is trivial but the use of |
1654 commonancestorsheads is not.""" | 1654 commonancestorsheads is not.""" |
1655 if start == nullrev: | 1655 if b == nullrev: |
1656 return True | 1656 return True |
1657 elif start == end: | 1657 elif a == b: |
1658 return True | 1658 return True |
1659 return start in self._commonancestorsheads(start, end) | 1659 return b in self._commonancestorsheads(a, b) |
1660 | 1660 |
1661 def commonancestorsheads(self, a, b): | 1661 def commonancestorsheads(self, a, b): |
1662 """calculate all the heads of the common ancestors of nodes a and b""" | 1662 """calculate all the heads of the common ancestors of nodes a and b""" |
1663 a, b = self.rev(a), self.rev(b) | 1663 a, b = self.rev(a), self.rev(b) |
1664 ancs = self._commonancestorsheads(a, b) | 1664 ancs = self._commonancestorsheads(a, b) |
1671 except (AttributeError, OverflowError): # C implementation failed | 1671 except (AttributeError, OverflowError): # C implementation failed |
1672 ancs = ancestor.commonancestorsheads(self.parentrevs, *revs) | 1672 ancs = ancestor.commonancestorsheads(self.parentrevs, *revs) |
1673 return ancs | 1673 return ancs |
1674 | 1674 |
1675 def isancestor(self, a, b): | 1675 def isancestor(self, a, b): |
1676 """return True if node a is an ancestor of node b""" | 1676 """return True if node a is an ancestor of node b |
1677 | |
1678 A revision is considered an ancestor of itself.""" | |
1677 a, b = self.rev(a), self.rev(b) | 1679 a, b = self.rev(a), self.rev(b) |
1678 return self.descendant(a, b) | 1680 return self.isdescendantrev(b, a) |
1679 | 1681 |
1680 def ancestor(self, a, b): | 1682 def ancestor(self, a, b): |
1681 """calculate the "best" common ancestor of nodes a and b""" | 1683 """calculate the "best" common ancestor of nodes a and b""" |
1682 | 1684 |
1683 a, b = self.rev(a), self.rev(b) | 1685 a, b = self.rev(a), self.rev(b) |