# HG changeset patch # User pacien # Date 2022-01-28 10:54:44 # Node ID 580660518459d90c52faa0be4be4a6bcec99c6f1 # Parent f7d7facd7b9f5fb3121a9a96ba38fd82400359a2 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 diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -2464,7 +2464,16 @@ class revlog(object): 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,