[Request] [+- ] D10305: revlog: move the details of revlog "v2" index inside revlog.utils.constants

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Mon Apr 5 15:49:52 UTC 2021


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

REVISION SUMMARY
  the revlog module is quite large and this kind of format information would handy
  for other module. So let us start to gather this information about the format in
  a more appropriate place.
  
  We update various reference to this information to use the new "source of truth"
  in the process.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/pure/parsers.py
  mercurial/revlog.py
  mercurial/revlogutils/constants.py

CHANGE DETAILS

diff --git a/mercurial/revlogutils/constants.py b/mercurial/revlogutils/constants.py
--- a/mercurial/revlogutils/constants.py
+++ b/mercurial/revlogutils/constants.py
@@ -57,6 +57,21 @@
 INDEX_ENTRY_V1 = struct.Struct(b">Qiiiiii20s12x")
 assert INDEX_ENTRY_V1.size == 32 * 2
 
+#  6 bytes: offset
+#  2 bytes: flags
+#  4 bytes: compressed length
+#  4 bytes: uncompressed length
+#  4 bytes: base rev
+#  4 bytes: link rev
+#  4 bytes: parent 1 rev
+#  4 bytes: parent 2 rev
+# 32 bytes: nodeid
+#  8 bytes: sidedata offset
+#  4 bytes: sidedata compressed length
+#  20 bytes: Padding to align to 96 bytes (see RevlogV2Plan wiki page)
+INDEX_ENTRY_V2 = struct.Struct(b">Qiiiiii20s12xQi20x")
+assert INDEX_ENTRY_V2.size == 32 * 3
+
 # revlog index flags
 
 # For historical reasons, revlog's internal flags were exposed via the
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -42,6 +42,7 @@
     FLAG_INLINE_DATA,
     INDEX_ENTRY_V0,
     INDEX_ENTRY_V1,
+    INDEX_ENTRY_V2,
     REVLOGV0,
     REVLOGV1,
     REVLOGV1_FLAGS,
@@ -86,7 +87,6 @@
     storageutil,
     stringutil,
 )
-from .pure import parsers as pureparsers
 
 # blanked usage of all the name to prevent pyflakes constraints
 # We need these name available in the module for extensions.
@@ -351,20 +351,16 @@
         return p
 
 
-indexformatv2 = struct.Struct(pureparsers.Index2Mixin.index_format)
-indexformatv2_pack = indexformatv2.pack
-
-
 class revlogv2io(object):
     def __init__(self):
-        self.size = indexformatv2.size
+        self.size = INDEX_ENTRY_V2.size
 
     def parseindex(self, data, inline):
         index, cache = parsers.parse_index2(data, inline, revlogv2=True)
         return index, cache
 
     def packentry(self, entry, node, version, rev):
-        p = indexformatv2_pack(*entry)
+        p = INDEX_ENTRY_V2.pack(*entry)
         if rev == 0:
             p = versionformat_pack(version) + p[4:]
         return p
diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py
+++ b/mercurial/pure/parsers.py
@@ -243,21 +243,8 @@
 
 
 class Index2Mixin(object):
-    #  6 bytes: offset
-    #  2 bytes: flags
-    #  4 bytes: compressed length
-    #  4 bytes: uncompressed length
-    #  4 bytes: base rev
-    #  4 bytes: link rev
-    #  4 bytes: parent 1 rev
-    #  4 bytes: parent 2 rev
-    # 32 bytes: nodeid
-    #  8 bytes: sidedata offset
-    #  4 bytes: sidedata compressed length
-    #  20 bytes: Padding to align to 96 bytes (see RevlogV2Plan wiki page)
-    index_format = b">Qiiiiii20s12xQi20x"
-    index_size = struct.calcsize(index_format)
-    assert index_size == 96, index_size
+    index_format = revlog_constants.INDEX_ENTRY_V2.format
+    index_size = revlog_constants.INDEX_ENTRY_V2.size
     null_item = (0, 0, 0, -1, -1, -1, -1, nullid, 0, 0)
 
     def replace_sidedata_info(self, i, sidedata_offset, sidedata_length):



To: marmoute, indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20210405/c50e82e0/attachment-0001.html>


More information about the Mercurial-patches mailing list