Patchwork D4078: changegroup: make delta header struct formatters actual structs

login
register
mail settings
Submitter phabricator
Date Aug. 6, 2018, 6:57 a.m.
Message ID <3f68d4111e2bcefdafe004c894e1e0f6@localhost.localdomain>
Download mbox | patch
Permalink /patch/33298/
State Not Applicable
Headers show

Comments

phabricator - Aug. 6, 2018, 6:57 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG271854adc3a6: changegroup: make delta header struct formatters actual structs (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4078?vs=9840&id=9954

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

AFFECTED FILES
  mercurial/changegroup.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -40,9 +40,9 @@ 
     stringutil,
 )
 
-_CHANGEGROUPV1_DELTA_HEADER = "20s20s20s20s"
-_CHANGEGROUPV2_DELTA_HEADER = "20s20s20s20s20s"
-_CHANGEGROUPV3_DELTA_HEADER = ">20s20s20s20s20sH"
+_CHANGEGROUPV1_DELTA_HEADER = struct.Struct("20s20s20s20s")
+_CHANGEGROUPV2_DELTA_HEADER = struct.Struct("20s20s20s20s20s")
+_CHANGEGROUPV3_DELTA_HEADER = struct.Struct(">20s20s20s20s20sH")
 
 LFS_REQUIREMENT = 'lfs'
 
@@ -119,7 +119,7 @@ 
     bundlerepo and some debug commands - their use is discouraged.
     """
     deltaheader = _CHANGEGROUPV1_DELTA_HEADER
-    deltaheadersize = struct.calcsize(deltaheader)
+    deltaheadersize = deltaheader.size
     version = '01'
     _grouplistcount = 1 # One list of files after the manifests
 
@@ -192,7 +192,7 @@ 
         if not l:
             return {}
         headerdata = readexactly(self._stream, self.deltaheadersize)
-        header = struct.unpack(self.deltaheader, headerdata)
+        header = self.deltaheader.unpack(headerdata)
         delta = readexactly(self._stream, l - self.deltaheadersize)
         node, p1, p2, deltabase, cs, flags = self._deltaheader(header, prevnode)
         return (node, p1, p2, cs, deltabase, delta, flags)
@@ -451,7 +451,7 @@ 
     remain the same.
     """
     deltaheader = _CHANGEGROUPV2_DELTA_HEADER
-    deltaheadersize = struct.calcsize(deltaheader)
+    deltaheadersize = deltaheader.size
     version = '02'
 
     def _deltaheader(self, headertuple, prevnode):
@@ -467,7 +467,7 @@ 
     separating manifests and files.
     """
     deltaheader = _CHANGEGROUPV3_DELTA_HEADER
-    deltaheadersize = struct.calcsize(deltaheader)
+    deltaheadersize = deltaheader.size
     version = '03'
     _grouplistcount = 2 # One list of manifests and one list of files
 
@@ -1099,7 +1099,7 @@ 
     def builddeltaheader(self, node, p1n, p2n, basenode, linknode, flags):
         # do nothing with basenode, it is implicitly the previous one in HG10
         # do nothing with flags, it is implicitly 0 for cg1 and cg2
-        return struct.pack(self.deltaheader, node, p1n, p2n, linknode)
+        return self.deltaheader.pack(node, p1n, p2n, linknode)
 
 class cg2packer(cg1packer):
     deltaheader = _CHANGEGROUPV2_DELTA_HEADER
@@ -1155,7 +1155,7 @@ 
 
     def builddeltaheader(self, node, p1n, p2n, basenode, linknode, flags):
         # Do nothing with flags, it is implicitly 0 in cg1 and cg2
-        return struct.pack(self.deltaheader, node, p1n, p2n, basenode, linknode)
+        return self.deltaheader.pack(node, p1n, p2n, basenode, linknode)
 
 class cg3packer(cg2packer):
     deltaheader = _CHANGEGROUPV3_DELTA_HEADER
@@ -1173,8 +1173,7 @@ 
         return self.close()
 
     def builddeltaheader(self, node, p1n, p2n, basenode, linknode, flags):
-        return struct.pack(
-            self.deltaheader, node, p1n, p2n, basenode, linknode, flags)
+        return self.deltaheader.pack(node, p1n, p2n, basenode, linknode, flags)
 
 def _makecg1packer(repo, filematcher, bundlecaps):
     return cg1packer(repo, filematcher, b'01', bundlecaps=bundlecaps)