phases: use a Struct object for binary encoding and decoding
authorBoris Feld <boris.feld@octobus.net>
Tue, 19 Sep 2017 22:08:09 +0200
changeset 34325 4fbbdd9b04f1
parent 34324 e45ec589f962
child 34326 5779d096a696
phases: use a Struct object for binary encoding and decoding We will move the binary encoding and decoding code to 'phases.py' in order to make it easier to reuse. First, let's cleanup it a bit.
mercurial/bundle2.py
--- a/mercurial/bundle2.py	Wed Sep 20 05:47:33 2017 +0200
+++ b/mercurial/bundle2.py	Tue Sep 19 22:08:09 2017 +0200
@@ -179,7 +179,7 @@
 _fpayloadsize = '>i'
 _fpartparamcount = '>BB'
 
-_fphasesentry = '>i20s'
+_fphasesentry = struct.Struct('>i20s')
 
 preferedchunksize = 4096
 
@@ -1483,7 +1483,7 @@
         phasedata = []
         for phase in phases.allphases:
             for head in headsbyphase[phase]:
-                phasedata.append(_pack(_fphasesentry, phase, head))
+                phasedata.append(_fphasesentry.pack(phase, head))
         bundler.newpart('phase-heads', data=''.join(phasedata))
 
 def addparttagsfnodescache(repo, bundler, outgoing):
@@ -1843,14 +1843,14 @@
 
 def _readphaseheads(inpart):
     headsbyphase = [[] for i in phases.allphases]
-    entrysize = struct.calcsize(_fphasesentry)
+    entrysize = _fphasesentry.size
     while True:
         entry = inpart.read(entrysize)
         if len(entry) < entrysize:
             if entry:
                 raise error.Abort(_('bad phase-heads bundle part'))
             break
-        phase, node = struct.unpack(_fphasesentry, entry)
+        phase, node = _fphasesentry.unpack(entry)
         headsbyphase[phase].append(node)
     return headsbyphase