changeset 48765:580660518459

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
author pacien <pacien.trangirard@pacien.net>
date Fri, 28 Jan 2022 11:54:44 +0100
parents f7d7facd7b9f
children d9a7131648a3
files mercurial/revlog.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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,