##// END OF EJS Templates
bundle2: move processpart stream maintenance into part iterator...
Durham Goode -
r34259:e71890f2 default
parent child Browse files
Show More
@@ -354,13 +354,17 b' class partiterator(object):'
354 self.unbundler = unbundler
354 self.unbundler = unbundler
355 self.iterator = None
355 self.iterator = None
356 self.count = 0
356 self.count = 0
357 self.current = None
357
358
358 def __enter__(self):
359 def __enter__(self):
359 def func():
360 def func():
360 itr = enumerate(self.unbundler.iterparts())
361 itr = enumerate(self.unbundler.iterparts())
361 for count, p in itr:
362 for count, p in itr:
362 self.count = count
363 self.count = count
364 self.current = p
363 yield p
365 yield p
366 p.seek(0, 2)
367 self.current = None
364 self.iterator = func()
368 self.iterator = func()
365 return self.iterator
369 return self.iterator
366
370
@@ -369,6 +373,13 b' class partiterator(object):'
369 return
373 return
370
374
371 if exc:
375 if exc:
376 # If exiting or interrupted, do not attempt to seek the stream in
377 # the finally block below. This makes abort faster.
378 if (self.current and
379 not isinstance(exc, (SystemExit, KeyboardInterrupt))):
380 # consume the part content to not corrupt the stream.
381 self.current.seek(0, 2)
382
372 # Any exceptions seeking to the end of the bundle at this point are
383 # Any exceptions seeking to the end of the bundle at this point are
373 # almost certainly related to the underlying stream being bad.
384 # almost certainly related to the underlying stream being bad.
374 # And, chances are that the exception we're handling is related to
385 # And, chances are that the exception we're handling is related to
@@ -455,7 +466,6 b' def _processpart(op, part):'
455 The part is guaranteed to have been fully consumed when the function exits
466 The part is guaranteed to have been fully consumed when the function exits
456 (even if an exception is raised)."""
467 (even if an exception is raised)."""
457 status = 'unknown' # used by debug output
468 status = 'unknown' # used by debug output
458 hardabort = False
459 try:
469 try:
460 try:
470 try:
461 handler = parthandlermapping.get(part.type)
471 handler = parthandlermapping.get(part.type)
@@ -511,15 +521,8 b' def _processpart(op, part):'
511 mandatory=False)
521 mandatory=False)
512 outpart.addparam(
522 outpart.addparam(
513 'in-reply-to', pycompat.bytestr(part.id), mandatory=False)
523 'in-reply-to', pycompat.bytestr(part.id), mandatory=False)
514 # If exiting or interrupted, do not attempt to seek the stream in the
515 # finally block below. This makes abort faster.
516 except (SystemExit, KeyboardInterrupt):
517 hardabort = True
518 raise
519 finally:
524 finally:
520 # consume the part content to not corrupt the stream.
525 pass
521 if not hardabort:
522 part.seek(0, 2)
523
526
524
527
525 def decodecaps(blob):
528 def decodecaps(blob):
@@ -1147,7 +1150,15 b' class interrupthandler(unpackermixin):'
1147 return
1150 return
1148 part = unbundlepart(self.ui, headerblock, self._fp)
1151 part = unbundlepart(self.ui, headerblock, self._fp)
1149 op = interruptoperation(self.ui)
1152 op = interruptoperation(self.ui)
1150 _processpart(op, part)
1153 hardabort = False
1154 try:
1155 _processpart(op, part)
1156 except (SystemExit, KeyboardInterrupt):
1157 hardabort = True
1158 raise
1159 finally:
1160 if not hardabort:
1161 part.seek(0, 2)
1151 self.ui.debug('bundle2-input-stream-interrupt:'
1162 self.ui.debug('bundle2-input-stream-interrupt:'
1152 ' closing out of band context\n')
1163 ' closing out of band context\n')
1153
1164
General Comments 0
You need to be logged in to leave comments. Login now