##// END OF EJS Templates
bundle2: implement consume() API on unbundlepart...
Gregory Szorc -
r35111:db503852 default
parent child Browse files
Show More
@@ -363,7 +363,7 b' class partiterator(object):'
363 363 self.count = count
364 364 self.current = p
365 365 yield p
366 p.seek(0, os.SEEK_END)
366 p.consume()
367 367 self.current = None
368 368 self.iterator = func()
369 369 return self.iterator
@@ -385,11 +385,11 b' class partiterator(object):'
385 385 try:
386 386 if self.current:
387 387 # consume the part content to not corrupt the stream.
388 self.current.seek(0, os.SEEK_END)
388 self.current.consume()
389 389
390 390 for part in self.iterator:
391 391 # consume the bundle content
392 part.seek(0, os.SEEK_END)
392 part.consume()
393 393 except Exception:
394 394 seekerror = True
395 395
@@ -856,10 +856,11 b' class unbundle20(unpackermixin):'
856 856 while headerblock is not None:
857 857 part = seekableunbundlepart(self.ui, headerblock, self._fp)
858 858 yield part
859 # Seek to the end of the part to force it's consumption so the next
860 # part can be read. But then seek back to the beginning so the
861 # code consuming this generator has a part that starts at 0.
862 part.seek(0, os.SEEK_END)
859 # Ensure part is fully consumed so we can start reading the next
860 # part.
861 part.consume()
862 # But then seek back to the beginning so the code consuming this
863 # generator has a part that starts at 0.
863 864 part.seek(0, os.SEEK_SET)
864 865 headerblock = self._readpartheader()
865 866 indebug(self.ui, 'end of bundle2 stream')
@@ -1165,7 +1166,7 b' class interrupthandler(unpackermixin):'
1165 1166 raise
1166 1167 finally:
1167 1168 if not hardabort:
1168 part.seek(0, os.SEEK_END)
1169 part.consume()
1169 1170 self.ui.debug('bundle2-input-stream-interrupt:'
1170 1171 ' closing out of band context\n')
1171 1172
@@ -1300,6 +1301,20 b' class unbundlepart(unpackermixin):'
1300 1301 """Generator of decoded chunks in the payload."""
1301 1302 return decodepayloadchunks(self.ui, self._fp)
1302 1303
1304 def consume(self):
1305 """Read the part payload until completion.
1306
1307 By consuming the part data, the underlying stream read offset will
1308 be advanced to the next part (or end of stream).
1309 """
1310 if self.consumed:
1311 return
1312
1313 chunk = self.read(32768)
1314 while chunk:
1315 self._pos += len(chunk)
1316 chunk = self.read(32768)
1317
1303 1318 def read(self, size=None):
1304 1319 """read payload data"""
1305 1320 if not self._initialized:
General Comments 0
You need to be logged in to leave comments. Login now