diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -39,9 +39,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' @@ -122,7 +122,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 @@ -195,7 +195,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) @@ -454,7 +454,7 @@ remain the same. """ deltaheader = _CHANGEGROUPV2_DELTA_HEADER - deltaheadersize = struct.calcsize(deltaheader) + deltaheadersize = deltaheader.size version = '02' def _deltaheader(self, headertuple, prevnode): @@ -470,7 +470,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 @@ -1102,7 +1102,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 @@ -1158,7 +1158,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 @@ -1176,8 +1176,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)