[Request] [+- ] D10304: revlog: move the details of revlog "v1" 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/D10304

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
@@ -44,6 +44,19 @@
 # 20 bytes: nodeid
 INDEX_ENTRY_V0 = struct.Struct(b">4l20s20s20s")
 
+## index v1
+#  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
+INDEX_ENTRY_V1 = struct.Struct(b">Qiiiiii20s12x")
+assert INDEX_ENTRY_V1.size == 32 * 2
+
 # 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
@@ -41,6 +41,7 @@
     FLAG_GENERALDELTA,
     FLAG_INLINE_DATA,
     INDEX_ENTRY_V0,
+    INDEX_ENTRY_V1,
     REVLOGV0,
     REVLOGV1,
     REVLOGV1_FLAGS,
@@ -325,18 +326,6 @@
         return INDEX_ENTRY_V0.pack(*e2)
 
 
-# index ng:
-#  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
-indexformatng = struct.Struct(b">Qiiiiii20s12x")
-indexformatng_pack = indexformatng.pack
 versionformat = struct.Struct(b">I")
 versionformat_pack = versionformat.pack
 versionformat_unpack = versionformat.unpack
@@ -348,7 +337,7 @@
 
 class revlogio(object):
     def __init__(self):
-        self.size = indexformatng.size
+        self.size = INDEX_ENTRY_V1.size
 
     def parseindex(self, data, inline):
         # call the C implementation to parse the index data
@@ -356,7 +345,7 @@
         return index, cache
 
     def packentry(self, entry, node, version, rev):
-        p = indexformatng_pack(*entry)
+        p = INDEX_ENTRY_V1.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
@@ -17,6 +17,7 @@
 )
 
 from ..revlogutils import nodemap as nodemaputil
+from ..revlogutils import constants as revlog_constants
 
 stringio = pycompat.bytesio
 
@@ -43,13 +44,13 @@
 
 class BaseIndexObject(object):
     # Format of an index entry according to Python's `struct` language
-    index_format = b">Qiiiiii20s12x"
+    index_format = revlog_constants.INDEX_ENTRY_V1.format
     # Size of a C unsigned long long int, platform independent
     big_int_size = struct.calcsize(b'>Q')
     # Size of a C long int, platform independent
     int_size = struct.calcsize(b'>i')
     # Size of the entire index format
-    index_size = struct.calcsize(index_format)
+    index_size = revlog_constants.INDEX_ENTRY_V1.size
     # An empty index entry, used as a default value to be overridden, or nullrev
     null_item = (0, 0, 0, -1, -1, -1, -1, nullid)
 



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/ced4660b/attachment-0001.html>


More information about the Mercurial-patches mailing list