##// END OF EJS Templates
bundle2: move part iterator a separate class...
Durham Goode -
r34149:e9e0e114 default
parent child Browse files
Show More
@@ -347,6 +347,16 b' def applybundle(repo, unbundler, tr, sou'
347 _processchangegroup(op, unbundler, tr, source, url, **kwargs)
347 _processchangegroup(op, unbundler, tr, source, url, **kwargs)
348 return op
348 return op
349
349
350 class partiterator(object):
351 def __init__(self, unbundler):
352 self.unbundler = unbundler
353
354 def __enter__(self):
355 return enumerate(self.unbundler.iterparts())
356
357 def __exit__(self, type, value, tb):
358 pass
359
350 def processbundle(repo, unbundler, transactiongetter=None, op=None):
360 def processbundle(repo, unbundler, transactiongetter=None, op=None):
351 """This function process a bundle, apply effect to/from a repo
361 """This function process a bundle, apply effect to/from a repo
352
362
@@ -378,48 +388,49 b' def processbundle(repo, unbundler, trans'
378 msg.append(' with-transaction')
388 msg.append(' with-transaction')
379 msg.append('\n')
389 msg.append('\n')
380 repo.ui.debug(''.join(msg))
390 repo.ui.debug(''.join(msg))
381 iterparts = enumerate(unbundler.iterparts())
391
382 part = None
392 with partiterator(unbundler) as parts:
383 nbpart = 0
393 part = None
384 try:
394 nbpart = 0
385 for nbpart, part in iterparts:
386 _processpart(op, part)
387 except Exception as exc:
388 # Any exceptions seeking to the end of the bundle at this point are
389 # almost certainly related to the underlying stream being bad.
390 # And, chances are that the exception we're handling is related to
391 # getting in that bad state. So, we swallow the seeking error and
392 # re-raise the original error.
393 seekerror = False
394 try:
395 try:
395 for nbpart, part in iterparts:
396 for nbpart, part in parts:
396 # consume the bundle content
397 _processpart(op, part)
397 part.seek(0, 2)
398 except Exception as exc:
398 except Exception:
399 # Any exceptions seeking to the end of the bundle at this point are
399 seekerror = True
400 # almost certainly related to the underlying stream being bad.
401 # And, chances are that the exception we're handling is related to
402 # getting in that bad state. So, we swallow the seeking error and
403 # re-raise the original error.
404 seekerror = False
405 try:
406 for nbpart, part in parts:
407 # consume the bundle content
408 part.seek(0, 2)
409 except Exception:
410 seekerror = True
400
411
401 # Small hack to let caller code distinguish exceptions from bundle2
412 # Small hack to let caller code distinguish exceptions from bundle2
402 # processing from processing the old format. This is mostly
413 # processing from processing the old format. This is mostly needed
403 # needed to handle different return codes to unbundle according to the
414 # to handle different return codes to unbundle according to the type
404 # type of bundle. We should probably clean up or drop this return code
415 # of bundle. We should probably clean up or drop this return code
405 # craziness in a future version.
416 # craziness in a future version.
406 exc.duringunbundle2 = True
417 exc.duringunbundle2 = True
407 salvaged = []
418 salvaged = []
408 replycaps = None
419 replycaps = None
409 if op.reply is not None:
420 if op.reply is not None:
410 salvaged = op.reply.salvageoutput()
421 salvaged = op.reply.salvageoutput()
411 replycaps = op.reply.capabilities
422 replycaps = op.reply.capabilities
412 exc._replycaps = replycaps
423 exc._replycaps = replycaps
413 exc._bundle2salvagedoutput = salvaged
424 exc._bundle2salvagedoutput = salvaged
414
425
415 # Re-raising from a variable loses the original stack. So only use
426 # Re-raising from a variable loses the original stack. So only use
416 # that form if we need to.
427 # that form if we need to.
417 if seekerror:
428 if seekerror:
418 raise exc
429 raise exc
419 else:
430 else:
420 raise
431 raise
421 finally:
432 finally:
422 repo.ui.debug('bundle2-input-bundle: %i parts total\n' % nbpart)
433 repo.ui.debug('bundle2-input-bundle: %i parts total\n' % nbpart)
423
434
424 return op
435 return op
425
436
General Comments 0
You need to be logged in to leave comments. Login now