revlog: move the "index header" struct inside revlog.utils.constants
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 05 Apr 2021 12:21:23 +0200
changeset 46859 c6e23fb4bfb4
parent 46858 85e3a630cad9
child 46860 1dc86c2a43ce
revlog: move the "index header" struct inside revlog.utils.constants The struct was previous called "version", but this is actually "version" + "flags". So header seems like a better name. The move to the `constants` module has the same motivation as the INDEX_ENTRY_V# ones. Differential Revision: https://phab.mercurial-scm.org/D10306
mercurial/revlog.py
mercurial/revlogutils/constants.py
--- a/mercurial/revlog.py	Mon Apr 05 12:21:12 2021 +0200
+++ b/mercurial/revlog.py	Mon Apr 05 12:21:23 2021 +0200
@@ -44,6 +44,7 @@
     INDEX_ENTRY_V0,
     INDEX_ENTRY_V1,
     INDEX_ENTRY_V2,
+    INDEX_HEADER,
     REVLOGV0,
     REVLOGV1,
     REVLOGV1_FLAGS,
@@ -327,10 +328,6 @@
         return INDEX_ENTRY_V0.pack(*e2)
 
 
-versionformat = struct.Struct(b">I")
-versionformat_pack = versionformat.pack
-versionformat_unpack = versionformat.unpack
-
 # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte
 # signed integer)
 _maxentrysize = 0x7FFFFFFF
@@ -348,7 +345,7 @@
     def packentry(self, entry, node, version, rev):
         p = INDEX_ENTRY_V1.pack(*entry)
         if rev == 0:
-            p = versionformat_pack(version) + p[4:]
+            p = INDEX_HEADER.pack(version) + p[4:]
         return p
 
 
@@ -363,7 +360,7 @@
     def packentry(self, entry, node, version, rev):
         p = INDEX_ENTRY_V2.pack(*entry)
         if rev == 0:
-            p = versionformat_pack(version) + p[4:]
+            p = INDEX_HEADER.pack(version) + p[4:]
         return p
 
 
@@ -579,7 +576,7 @@
                 else:
                     indexdata = f.read()
             if len(indexdata) > 0:
-                versionflags = versionformat_unpack(indexdata[:4])[0]
+                versionflags = INDEX_HEADER.unpack(indexdata[:4])[0]
                 self._initempty = False
             else:
                 versionflags = newversionflags
--- a/mercurial/revlogutils/constants.py	Mon Apr 05 12:21:12 2021 +0200
+++ b/mercurial/revlogutils/constants.py	Mon Apr 05 12:21:23 2021 +0200
@@ -15,6 +15,8 @@
 
 ### main revlog header
 
+INDEX_HEADER = struct.Struct(b">I")
+
 ## revlog version
 REVLOGV0 = 0
 REVLOGV1 = 1