Mercurial > hg
comparison mercurial/bundle2.py @ 34151:550343626bb2
bundle2: move part counter to partiterator
As part of moving the part iterator logic to a separate class, let's move the
part counting logic and the output for it.
Differential Revision: https://phab.mercurial-scm.org/D704
author | Durham Goode <durham@fb.com> |
---|---|
date | Wed, 13 Sep 2017 17:16:50 -0700 |
parents | e9e0e1143fc5 |
children | 21c2df59a1da |
comparison
equal
deleted
inserted
replaced
34150:e9e0e1143fc5 | 34151:550343626bb2 |
---|---|
346 op = bundleoperation(repo, lambda: tr) | 346 op = bundleoperation(repo, lambda: tr) |
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): | 350 class partiterator(object): |
351 def __init__(self, unbundler): | 351 def __init__(self, repo, unbundler): |
352 self.repo = repo | |
352 self.unbundler = unbundler | 353 self.unbundler = unbundler |
354 self.iterator = None | |
355 self.count = 0 | |
353 | 356 |
354 def __enter__(self): | 357 def __enter__(self): |
355 return enumerate(self.unbundler.iterparts()) | 358 def func(): |
359 itr = enumerate(self.unbundler.iterparts()) | |
360 for count, p in itr: | |
361 self.count = count | |
362 yield p | |
363 self.iterator = func() | |
364 return self.iterator | |
356 | 365 |
357 def __exit__(self, type, value, tb): | 366 def __exit__(self, type, value, tb): |
358 pass | 367 if not self.iterator: |
368 return | |
369 | |
370 self.repo.ui.debug('bundle2-input-bundle: %i parts total\n' % | |
371 self.count) | |
359 | 372 |
360 def processbundle(repo, unbundler, transactiongetter=None, op=None): | 373 def processbundle(repo, unbundler, transactiongetter=None, op=None): |
361 """This function process a bundle, apply effect to/from a repo | 374 """This function process a bundle, apply effect to/from a repo |
362 | 375 |
363 It iterates over each part then searches for and uses the proper handling | 376 It iterates over each part then searches for and uses the proper handling |
387 else: | 400 else: |
388 msg.append(' with-transaction') | 401 msg.append(' with-transaction') |
389 msg.append('\n') | 402 msg.append('\n') |
390 repo.ui.debug(''.join(msg)) | 403 repo.ui.debug(''.join(msg)) |
391 | 404 |
392 with partiterator(unbundler) as parts: | 405 with partiterator(repo, unbundler) as parts: |
393 part = None | 406 part = None |
394 nbpart = 0 | |
395 try: | 407 try: |
396 for nbpart, part in parts: | 408 for part in parts: |
397 _processpart(op, part) | 409 _processpart(op, part) |
398 except Exception as exc: | 410 except Exception as exc: |
399 # Any exceptions seeking to the end of the bundle at this point are | 411 # Any exceptions seeking to the end of the bundle at this point are |
400 # almost certainly related to the underlying stream being bad. | 412 # almost certainly related to the underlying stream being bad. |
401 # And, chances are that the exception we're handling is related to | 413 # 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 | 414 # getting in that bad state. So, we swallow the seeking error and |
403 # re-raise the original error. | 415 # re-raise the original error. |
404 seekerror = False | 416 seekerror = False |
405 try: | 417 try: |
406 for nbpart, part in parts: | 418 for part in parts: |
407 # consume the bundle content | 419 # consume the bundle content |
408 part.seek(0, 2) | 420 part.seek(0, 2) |
409 except Exception: | 421 except Exception: |
410 seekerror = True | 422 seekerror = True |
411 | 423 |
427 # that form if we need to. | 439 # that form if we need to. |
428 if seekerror: | 440 if seekerror: |
429 raise exc | 441 raise exc |
430 else: | 442 else: |
431 raise | 443 raise |
432 finally: | |
433 repo.ui.debug('bundle2-input-bundle: %i parts total\n' % nbpart) | |
434 | 444 |
435 return op | 445 return op |
436 | 446 |
437 def _processchangegroup(op, cg, tr, source, url, **kwargs): | 447 def _processchangegroup(op, cg, tr, source, url, **kwargs): |
438 ret = cg.apply(op.repo, tr, source, url, **kwargs) | 448 ret = cg.apply(op.repo, tr, source, url, **kwargs) |