##// END OF EJS Templates
bundle2: support unbundling empty part...
Pierre-Yves David -
r20864:9a75d255 default
parent child Browse files
Show More
@@ -240,9 +240,31 b' class unbundle20(object):'
240
240
241 def _readpart(self):
241 def _readpart(self):
242 """return None when an end of stream markers is reach"""
242 """return None when an end of stream markers is reach"""
243 headersize = self._readexact(2)
243
244 assert headersize == '\0\0'
244 headersize = self._unpack(_fpartheadersize)[0]
245 return None
245 self.ui.debug('part header size: %i\n' % headersize)
246 if not headersize:
247 return None
248 headerblock = self._readexact(headersize)
249 # some utility to help reading from the header block
250 self._offset = 0 # layer violation to have something easy to understand
251 def fromheader(size):
252 """return the next <size> byte from the header"""
253 offset = self._offset
254 data = headerblock[offset:(offset + size)]
255 self._offset = offset + size
256 return data
257 typesize = _unpack(_fparttypesize, fromheader(1))[0]
258 parttype = fromheader(typesize)
259 self.ui.debug('part type: "%s"\n' % parttype)
260 current = part(parttype)
261 assert fromheader(2) == '\0\0' # no option for now
262 del self._offset # clean up layer, nobody saw anything.
263 self.ui.debug('part parameters: 0\n')
264 assert self._readexact(4) == '\0\0\0\0' #empty payload
265 self.ui.debug('payload chunk size: 0\n')
266 return current
267
246
268
247 class part(object):
269 class part(object):
248 """A bundle2 part contains application level payload
270 """A bundle2 part contains application level payload
@@ -251,8 +273,9 b' class part(object):'
251 handler.
273 handler.
252 """
274 """
253
275
254 def __init__(self, parttype):
276 def __init__(self, parttype, data=''):
255 self.type = parttype
277 self.type = parttype
278 self.data = data
256
279
257 def getchunks(self):
280 def getchunks(self):
258 ### header
281 ### header
@@ -60,6 +60,8 b' Create an extension to test bundle2 API'
60 > ui.write(' %s\n' % value)
60 > ui.write(' %s\n' % value)
61 > parts = list(unbundler)
61 > parts = list(unbundler)
62 > ui.write('parts count: %i\n' % len(parts))
62 > ui.write('parts count: %i\n' % len(parts))
63 > for p in parts:
64 > ui.write(' :%s:\n' % p.type)
63 > EOF
65 > EOF
64 $ cat >> $HGRCPATH << EOF
66 $ cat >> $HGRCPATH << EOF
65 > [extensions]
67 > [extensions]
@@ -206,6 +208,7 b' unbundling debug'
206 babar%#==tutu
208 babar%#==tutu
207 - simple
209 - simple
208 start extraction of bundle2 parts
210 start extraction of bundle2 parts
211 part header size: 0
209 end of bundle2 stream
212 end of bundle2 stream
210 parts count: 0
213 parts count: 0
211
214
@@ -243,3 +246,27 b' Test part'
243 test:empty\x00\x00\x00\x00\x00\x00\x00\x00 (no-eol) (esc)
246 test:empty\x00\x00\x00\x00\x00\x00\x00\x00 (no-eol) (esc)
244
247
245
248
249 $ hg unbundle2 < ../parts.hg2
250 options count: 0
251 parts count: 2
252 :test:empty:
253 :test:empty:
254
255 $ hg unbundle2 --debug < ../parts.hg2
256 start processing of HG20 stream
257 reading bundle2 stream parameters
258 options count: 0
259 start extraction of bundle2 parts
260 part header size: 13
261 part type: "test:empty"
262 part parameters: 0
263 payload chunk size: 0
264 part header size: 13
265 part type: "test:empty"
266 part parameters: 0
267 payload chunk size: 0
268 part header size: 0
269 end of bundle2 stream
270 parts count: 2
271 :test:empty:
272 :test:empty:
General Comments 0
You need to be logged in to leave comments. Login now