D10306: revlog: move the "index header" struct inside revlog.utils.constants

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

D10306: revlog: move the "index header" struct inside revlog.utils.constants

marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: indygreg.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  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
@@ -15,6 +15,8 @@
 
 ### main revlog header
 
+INDEX_HEADER = struct.Struct(b">I")
+
 ## revlog version
 REVLOGV0 = 0
 REVLOGV1 = 1
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -43,6 +43,7 @@
     INDEX_ENTRY_V0,
     INDEX_ENTRY_V1,
     INDEX_ENTRY_V2,
+    INDEX_HEADER,
     REVLOGV0,
     REVLOGV1,
     REVLOGV1_FLAGS,
@@ -326,10 +327,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
@@ -347,7 +344,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
 
 
@@ -362,7 +359,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
 
 
@@ -578,7 +575,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



To: marmoute, indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel