pacien created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This stores the rank (size of the ancestor set of a revision, including 
itself)
  in a changelog field and allows this property to be retrieved.
  
  The value is computed in a naive way from the definition of the rank. This 
will
  be replaced by a more efficient version later on.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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,20 @@
 
         return len(self.revision(rev, raw=False))
 
+    def fast_rank(self, rev):
+        """The "rank" of the revision if available, None otherwise
+
+        The rank of a revision is the size of sub-graph it defines as a head.
+        In other words, the rank og X i sthe size of `ancestors(X)` (X
+        included).
+
+        Some variant of revlog persist this value and make it available.
+        """
+        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 +2488,11 @@
             # than ones we manually add.
             sidedata_offset = 0
 
+        # 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
+
         e = revlogutils.entry(
             flags=flags,
             data_offset=offset,
@@ -2486,6 +2507,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
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to