rank: actually persist revision's rank in changelog-v2
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 15 Dec 2021 15:28:41 +0100
changeset 48500 c5d6c874766a
parent 48499 52034c42c09d
child 48501 4afb9627dc77
rank: actually persist revision's rank in changelog-v2 The changelog v2 format is now persisting whatever "rank" value is recorded. However keep in mind that for we do not record any value. Differential Revision: https://phab.mercurial-scm.org/D11937
mercurial/configitems.py
mercurial/pure/parsers.py
mercurial/revlogutils/constants.py
--- a/mercurial/configitems.py	Tue Dec 14 23:56:38 2021 +0100
+++ b/mercurial/configitems.py	Wed Dec 15 15:28:41 2021 +0100
@@ -1357,10 +1357,10 @@
 )
 # Experimental TODOs:
 #
-# * Same as for evlogv2 (but for the reduction of the number of files)
+# * Same as for revlogv2 (but for the reduction of the number of files)
+# * Actually computing the rank of changesets
 # * Improvement to investigate
 #   - storing .hgtags fnode
-#   - storing `rank` of changesets
 #   - storing branch related identifier
 
 coreconfigitem(
--- a/mercurial/pure/parsers.py	Tue Dec 14 23:56:38 2021 +0100
+++ b/mercurial/pure/parsers.py	Wed Dec 15 15:28:41 2021 +0100
@@ -880,6 +880,12 @@
 class IndexChangelogV2(IndexObject2):
     index_format = revlog_constants.INDEX_ENTRY_CL_V2
 
+    null_item = (
+        IndexObject2.null_item[: revlog_constants.ENTRY_RANK]
+        + (0,)  # rank of null is 0
+        + IndexObject2.null_item[revlog_constants.ENTRY_RANK :]
+    )
+
     def _unpack_entry(self, rev, data, r=True):
         items = self.index_format.unpack(data)
         return (
@@ -898,7 +904,7 @@
             items[revlog_constants.INDEX_ENTRY_V2_IDX_COMPRESSION_MODE] & 3,
             (items[revlog_constants.INDEX_ENTRY_V2_IDX_COMPRESSION_MODE] >> 2)
             & 3,
-            revlog_constants.RANK_UNKNOWN,
+            items[revlog_constants.INDEX_ENTRY_V2_IDX_RANK],
         )
 
     def _pack_entry(self, rev, entry):
@@ -919,6 +925,7 @@
             entry[revlog_constants.ENTRY_DATA_COMPRESSION_MODE] & 3
             | (entry[revlog_constants.ENTRY_SIDEDATA_COMPRESSION_MODE] & 3)
             << 2,
+            entry[revlog_constants.ENTRY_RANK],
         )
         return self.index_format.pack(*data)
 
--- a/mercurial/revlogutils/constants.py	Tue Dec 14 23:56:38 2021 +0100
+++ b/mercurial/revlogutils/constants.py	Wed Dec 15 15:28:41 2021 +0100
@@ -192,8 +192,9 @@
 #  8 bytes: sidedata offset
 #  4 bytes: sidedata compressed length
 #  1 bytes: compression mode (2 lower bit are data_compression_mode)
-#  27 bytes: Padding to align to 96 bytes (see RevlogV2Plan wiki page)
-INDEX_ENTRY_CL_V2 = struct.Struct(b">Qiiii20s12xQiB27x")
+#  4 bytes: changeset rank (i.e. `len(::REV)`)
+#  23 bytes: Padding to align to 96 bytes (see RevlogV2Plan wiki page)
+INDEX_ENTRY_CL_V2 = struct.Struct(b">Qiiii20s12xQiBi23x")
 assert INDEX_ENTRY_CL_V2.size == 32 * 3, INDEX_ENTRY_CL_V2.size
 INDEX_ENTRY_V2_IDX_OFFSET = 0
 INDEX_ENTRY_V2_IDX_COMPRESSED_LENGTH = 1
@@ -204,6 +205,7 @@
 INDEX_ENTRY_V2_IDX_SIDEDATA_OFFSET = 6
 INDEX_ENTRY_V2_IDX_SIDEDATA_COMPRESSED_LENGTH = 7
 INDEX_ENTRY_V2_IDX_COMPRESSION_MODE = 8
+INDEX_ENTRY_V2_IDX_RANK = 9
 
 # revlog index flags