Patchwork D12143: rank: compute property incrementally

login
register
mail settings
Submitter phabricator
Date Feb. 7, 2022, 5:26 p.m.
Message ID <differential-rev-PHID-DREV-wrshdj2m7bek2txlezvr-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50478/
State New
Headers show

Comments

phabricator - Feb. 7, 2022, 5:26 p.m.
pacien created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This replace the naive rank computation with a more efficient incremental
  method, avoiding computing the whole ancestor set when possible.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12143

AFFECTED FILES
  mercurial/revlog.py

CHANGE DETAILS




To: pacien, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -2491,7 +2491,16 @@ 
         # maybe the index.append should compute it when applicable instead
         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,