rank: compute property incrementally
This replaces the naive rank computation with a more efficient incremental
method, avoiding computing the whole ancestor set when possible.
Differential Revision: https://phab.mercurial-scm.org/D12143
--- a/mercurial/revlog.py Fri Jan 28 11:45:33 2022 +0100
+++ b/mercurial/revlog.py Fri Jan 28 11:54:44 2022 +0100
@@ -2464,7 +2464,16 @@
rank = RANK_UNKNOWN
if self._format_version == CHANGELOGV2:
- rank = len(list(self.ancestors([p1r, p2r], inclusive=True))) + 1
+ if (p1r, p2r) == (nullrev, nullrev):
+ rank = 1
+ elif p1r != nullrev and p2r == nullrev:
+ rank = 1 + self.fast_rank(p1r)
+ elif p1r == nullrev and p2r != nullrev:
+ rank = 1 + self.fast_rank(p2r)
+ else: # merge node
+ pmin, pmax = sorted((p1r, p2r))
+ rank = 1 + self.fast_rank(pmax)
+ rank += sum(1 for _ in self.findmissingrevs([pmax], [pmin]))
e = revlogutils.entry(
flags=flags,