Mercurial > hg
comparison mercurial/bundle2.py @ 34637:5f79f5f8487a
bundle2: immediate exit for ctrl+c (issue5692)
21c2df59a regressed bundle2 by catching all exceptions and trying to handle
them. The old behavior was to allow KeyboardInterrupts to throw and not have
graceful cleanup, which allowed it to exit immediately. Let's go back to that
behavior.
Differential Revision: https://phab.mercurial-scm.org/D960
author | Durham Goode <durham@fb.com> |
---|---|
date | Wed, 11 Oct 2017 10:36:59 -0700 |
parents | 6c7aaf59b21e |
children | a95067b1dca6 |
comparison
equal
deleted
inserted
replaced
34636:31c6c4d27be7 | 34637:5f79f5f8487a |
---|---|
368 | 368 |
369 def __exit__(self, type, exc, tb): | 369 def __exit__(self, type, exc, tb): |
370 if not self.iterator: | 370 if not self.iterator: |
371 return | 371 return |
372 | 372 |
373 if exc: | 373 # Only gracefully abort in a normal exception situation. User aborts |
374 # If exiting or interrupted, do not attempt to seek the stream in | 374 # like Ctrl+C throw a KeyboardInterrupt which is not a base Exception, |
375 # the finally block below. This makes abort faster. | 375 # and should not gracefully cleanup. |
376 if (self.current and | 376 if isinstance(exc, Exception): |
377 not isinstance(exc, (SystemExit, KeyboardInterrupt))): | |
378 # consume the part content to not corrupt the stream. | |
379 self.current.seek(0, 2) | |
380 | |
381 # Any exceptions seeking to the end of the bundle at this point are | 377 # Any exceptions seeking to the end of the bundle at this point are |
382 # almost certainly related to the underlying stream being bad. | 378 # almost certainly related to the underlying stream being bad. |
383 # And, chances are that the exception we're handling is related to | 379 # And, chances are that the exception we're handling is related to |
384 # getting in that bad state. So, we swallow the seeking error and | 380 # getting in that bad state. So, we swallow the seeking error and |
385 # re-raise the original error. | 381 # re-raise the original error. |
386 seekerror = False | 382 seekerror = False |
387 try: | 383 try: |
384 if self.current: | |
385 # consume the part content to not corrupt the stream. | |
386 self.current.seek(0, 2) | |
387 | |
388 for part in self.iterator: | 388 for part in self.iterator: |
389 # consume the bundle content | 389 # consume the bundle content |
390 part.seek(0, 2) | 390 part.seek(0, 2) |
391 except Exception: | 391 except Exception: |
392 seekerror = True | 392 seekerror = True |