##// END OF EJS Templates
bundle2: extract processing of part into its own function...
Pierre-Yves David -
r23008:d3137827 default
parent child Browse files
Show More
@@ -292,50 +292,8 b' def processbundle(repo, unbundler, trans'
292 part = None
292 part = None
293 try:
293 try:
294 for part in iterparts:
294 for part in iterparts:
295 parttype = part.type
295 _processpart(op, part)
296 # part key are matched lower case
297 key = parttype.lower()
298 try:
299 handler = parthandlermapping.get(key)
300 if handler is None:
301 raise error.BundleValueError(parttype=key)
302 op.ui.debug('found a handler for part %r\n' % parttype)
303 unknownparams = part.mandatorykeys - handler.params
304 if unknownparams:
305 unknownparams = list(unknownparams)
306 unknownparams.sort()
307 raise error.BundleValueError(parttype=key,
308 params=unknownparams)
309 except error.BundleValueError, exc:
310 if key != parttype: # mandatory parts
311 raise
312 op.ui.debug('ignoring unsupported advisory part %s\n' % exc)
313 # consuming the part
314 part.read()
315 continue
316
317
318 # handler is called outside the above try block so that we don't
319 # risk catching KeyErrors from anything other than the
320 # parthandlermapping lookup (any KeyError raised by handler()
321 # itself represents a defect of a different variety).
322 output = None
323 if op.reply is not None:
324 op.ui.pushbuffer(error=True)
325 output = ''
326 try:
327 handler(op, part)
328 finally:
329 if output is not None:
330 output = op.ui.popbuffer()
331 if output:
332 outpart = op.reply.newpart('b2x:output', data=output)
333 outpart.addparam('in-reply-to', str(part.id), mandatory=False)
334 part.read()
335 except Exception, exc:
296 except Exception, exc:
336 if part is not None:
337 # consume the bundle content
338 part.read()
339 for part in iterparts:
297 for part in iterparts:
340 # consume the bundle content
298 # consume the bundle content
341 part.read()
299 part.read()
@@ -348,6 +306,53 b' def processbundle(repo, unbundler, trans'
348 raise
306 raise
349 return op
307 return op
350
308
309 def _processpart(op, part):
310 """process a single part from a bundle
311
312 The part is guaranteed to have been fully consumed when the function exits
313 (even if an exception is raised)."""
314 try:
315 parttype = part.type
316 # part key are matched lower case
317 key = parttype.lower()
318 try:
319 handler = parthandlermapping.get(key)
320 if handler is None:
321 raise error.BundleValueError(parttype=key)
322 op.ui.debug('found a handler for part %r\n' % parttype)
323 unknownparams = part.mandatorykeys - handler.params
324 if unknownparams:
325 unknownparams = list(unknownparams)
326 unknownparams.sort()
327 raise error.BundleValueError(parttype=key,
328 params=unknownparams)
329 except error.BundleValueError, exc:
330 if key != parttype: # mandatory parts
331 raise
332 op.ui.debug('ignoring unsupported advisory part %s\n' % exc)
333 return # skip to part processing
334
335 # handler is called outside the above try block so that we don't
336 # risk catching KeyErrors from anything other than the
337 # parthandlermapping lookup (any KeyError raised by handler()
338 # itself represents a defect of a different variety).
339 output = None
340 if op.reply is not None:
341 op.ui.pushbuffer(error=True)
342 output = ''
343 try:
344 handler(op, part)
345 finally:
346 if output is not None:
347 output = op.ui.popbuffer()
348 if output:
349 outpart = op.reply.newpart('b2x:output', data=output)
350 outpart.addparam('in-reply-to', str(part.id), mandatory=False)
351 finally:
352 # consume the part content to not corrupt the stream.
353 part.read()
354
355
351 def decodecaps(blob):
356 def decodecaps(blob):
352 """decode a bundle2 caps bytes blob into a dictionnary
357 """decode a bundle2 caps bytes blob into a dictionnary
353
358
General Comments 0
You need to be logged in to leave comments. Login now