##// END OF EJS Templates
phases: move binary encoding into a reusable function...
Boris Feld -
r34320:5779d096 default
parent child Browse files
Show More
@@ -179,8 +179,6 b' urlreq = util.urlreq'
179 179 _fpayloadsize = '>i'
180 180 _fpartparamcount = '>BB'
181 181
182 _fphasesentry = struct.Struct('>i20s')
183
184 182 preferedchunksize = 4096
185 183
186 184 _parttypeforbidden = re.compile('[^a-zA-Z0-9_:-]')
@@ -1480,11 +1478,8 b' def _addpartsfromopts(ui, repo, bundler,'
1480 1478
1481 1479 if opts.get('phases', False):
1482 1480 headsbyphase = phases.subsetphaseheads(repo, outgoing.missing)
1483 phasedata = []
1484 for phase in phases.allphases:
1485 for head in headsbyphase[phase]:
1486 phasedata.append(_fphasesentry.pack(phase, head))
1487 bundler.newpart('phase-heads', data=''.join(phasedata))
1481 phasedata = phases.binaryencode(headsbyphase)
1482 bundler.newpart('phase-heads', data=phasedata)
1488 1483
1489 1484 def addparttagsfnodescache(repo, bundler, outgoing):
1490 1485 # we include the tags fnode cache for the bundle changeset
@@ -1843,14 +1838,14 b' def handlepushkey(op, inpart):'
1843 1838
1844 1839 def _readphaseheads(inpart):
1845 1840 headsbyphase = [[] for i in phases.allphases]
1846 entrysize = _fphasesentry.size
1841 entrysize = phases._fphasesentry.size
1847 1842 while True:
1848 1843 entry = inpart.read(entrysize)
1849 1844 if len(entry) < entrysize:
1850 1845 if entry:
1851 1846 raise error.Abort(_('bad phase-heads bundle part'))
1852 1847 break
1853 phase, node = _fphasesentry.unpack(entry)
1848 phase, node = phases._fphasesentry.unpack(entry)
1854 1849 headsbyphase[phase].append(node)
1855 1850 return headsbyphase
1856 1851
@@ -103,6 +103,7 b' Note: old client behave as a publishing '
103 103 from __future__ import absolute_import
104 104
105 105 import errno
106 import struct
106 107
107 108 from .i18n import _
108 109 from .node import (
@@ -119,6 +120,8 b' from . import ('
119 120 util,
120 121 )
121 122
123 _fphasesentry = struct.Struct('>i20s')
124
122 125 allphases = public, draft, secret = range(3)
123 126 trackedphases = allphases[1:]
124 127 phasenames = ['public', 'draft', 'secret']
@@ -154,6 +157,18 b' def _readroots(repo, phasedefaults=None)'
154 157 dirty = True
155 158 return roots, dirty
156 159
160 def binaryencode(phasemapping):
161 """encode a 'phase -> nodes' mapping into a binary stream
162
163 Since phases are integer the mapping is actually a python list:
164 [[PUBLIC_HEADS], [DRAFTS_HEADS], [SECRET_HEADS]]
165 """
166 binarydata = []
167 for phase, nodes in enumerate(phasemapping):
168 for head in nodes:
169 binarydata.append(_fphasesentry.pack(phase, head))
170 return ''.join(binarydata)
171
157 172 def _trackphasechange(data, rev, old, new):
158 173 """add a phase move the <data> dictionnary
159 174
General Comments 0
You need to be logged in to leave comments. Login now