diff mercurial/bundle2.py @ 34326:5779d096a696

phases: move binary encoding into a reusable function We want to use binary phases for pushing and pulling. We extract the encoding function out of the bundle2 module first.
author Boris Feld <boris.feld@octobus.net>
date Tue, 19 Sep 2017 22:01:31 +0200
parents 4fbbdd9b04f1
children 12c42bcd4133
line wrap: on
line diff
--- a/mercurial/bundle2.py	Tue Sep 19 22:08:09 2017 +0200
+++ b/mercurial/bundle2.py	Tue Sep 19 22:01:31 2017 +0200
@@ -179,8 +179,6 @@
 _fpayloadsize = '>i'
 _fpartparamcount = '>BB'
 
-_fphasesentry = struct.Struct('>i20s')
-
 preferedchunksize = 4096
 
 _parttypeforbidden = re.compile('[^a-zA-Z0-9_:-]')
@@ -1480,11 +1478,8 @@
 
     if opts.get('phases', False):
         headsbyphase = phases.subsetphaseheads(repo, outgoing.missing)
-        phasedata = []
-        for phase in phases.allphases:
-            for head in headsbyphase[phase]:
-                phasedata.append(_fphasesentry.pack(phase, head))
-        bundler.newpart('phase-heads', data=''.join(phasedata))
+        phasedata = phases.binaryencode(headsbyphase)
+        bundler.newpart('phase-heads', data=phasedata)
 
 def addparttagsfnodescache(repo, bundler, outgoing):
     # we include the tags fnode cache for the bundle changeset
@@ -1843,14 +1838,14 @@
 
 def _readphaseheads(inpart):
     headsbyphase = [[] for i in phases.allphases]
-    entrysize = _fphasesentry.size
+    entrysize = phases._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 = _fphasesentry.unpack(entry)
+        phase, node = phases._fphasesentry.unpack(entry)
         headsbyphase[phase].append(node)
     return headsbyphase