[Updated] D12139: rank: naive rank property computation and retrieval
pacien (Pacien)
phabricator at mercurial-scm.org
Mon Feb 14 17:07:23 UTC 2022
pacien edited the summary of this revision.
pacien updated this revision to Diff 32167.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D12139?vs=32086&id=32167
BRANCH
default
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D12139/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D12139
AFFECTED FILES
mercurial/revlog.py
CHANGE DETAILS
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -40,11 +40,13 @@
COMP_MODE_DEFAULT,
COMP_MODE_INLINE,
COMP_MODE_PLAIN,
+ ENTRY_RANK,
FEATURES_BY_VERSION,
FLAG_GENERALDELTA,
FLAG_INLINE_DATA,
INDEX_HEADER,
KIND_CHANGELOG,
+ RANK_UNKNOWN,
REVLOGV0,
REVLOGV1,
REVLOGV1_FLAGS,
@@ -872,6 +874,22 @@
return len(self.revision(rev, raw=False))
+ def fast_rank(self, rev):
+ """Return the rank of a revision if already known, or None otherwise.
+
+ The rank of a revision is the size of the sub-graph it defines as a
+ head. Equivalently, the rank of a revision `r` is the size of the set
+ `ancestors(r)`, `r` included.
+
+ This method returns the rank retrieved from the revlog in constant
+ time. It makes no attempt at computing unknown values for versions of
+ the revlog which do not persist the rank.
+ """
+ rank = self.index[rev][ENTRY_RANK]
+ if rank == RANK_UNKNOWN:
+ return None
+ return rank
+
def chainbase(self, rev):
base = self._chainbasecache.get(rev)
if base is not None:
@@ -2472,6 +2490,10 @@
# than ones we manually add.
sidedata_offset = 0
+ rank = RANK_UNKNOWN
+ if self._format_version == CHANGELOGV2:
+ rank = len(list(self.ancestors([p1r, p2r], inclusive=True))) + 1
+
e = revlogutils.entry(
flags=flags,
data_offset=offset,
@@ -2486,6 +2508,7 @@
sidedata_offset=sidedata_offset,
sidedata_compressed_length=len(serialized_sidedata),
sidedata_compression_mode=sidedata_compression_mode,
+ rank=rank,
)
self.index.append(e)
To: pacien, #hg-reviewers, Alphare
Cc: Alphare, marmoute, joerg.sonnenberger, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220214/6a59630c/attachment-0002.html>
More information about the Mercurial-patches
mailing list