##// 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 self.count = count
363 self.count = count
364 self.current = p
364 self.current = p
365 yield p
365 yield p
366 p.seek(0, os.SEEK_END)
366 p.consume()
367 self.current = None
367 self.current = None
368 self.iterator = func()
368 self.iterator = func()
369 return self.iterator
369 return self.iterator
@@ -385,11 +385,11 b' class partiterator(object):'
385 try:
385 try:
386 if self.current:
386 if self.current:
387 # consume the part content to not corrupt the stream.
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 for part in self.iterator:
390 for part in self.iterator:
391 # consume the bundle content
391 # consume the bundle content
392 part.seek(0, os.SEEK_END)
392 part.consume()
393 except Exception:
393 except Exception:
394 seekerror = True
394 seekerror = True
395
395
@@ -856,10 +856,11 b' class unbundle20(unpackermixin):'
856 while headerblock is not None:
856 while headerblock is not None:
857 part = seekableunbundlepart(self.ui, headerblock, self._fp)
857 part = seekableunbundlepart(self.ui, headerblock, self._fp)
858 yield part
858 yield part
859 # Seek to the end of the part to force it's consumption so the next
859 # Ensure part is fully consumed so we can start reading the next
860 # part can be read. But then seek back to the beginning so the
860 # part.
861 # code consuming this generator has a part that starts at 0.
861 part.consume()
862 part.seek(0, os.SEEK_END)
862 # But then seek back to the beginning so the code consuming this
863 # generator has a part that starts at 0.
863 part.seek(0, os.SEEK_SET)
864 part.seek(0, os.SEEK_SET)
864 headerblock = self._readpartheader()
865 headerblock = self._readpartheader()
865 indebug(self.ui, 'end of bundle2 stream')
866 indebug(self.ui, 'end of bundle2 stream')
@@ -1165,7 +1166,7 b' class interrupthandler(unpackermixin):'
1165 raise
1166 raise
1166 finally:
1167 finally:
1167 if not hardabort:
1168 if not hardabort:
1168 part.seek(0, os.SEEK_END)
1169 part.consume()
1169 self.ui.debug('bundle2-input-stream-interrupt:'
1170 self.ui.debug('bundle2-input-stream-interrupt:'
1170 ' closing out of band context\n')
1171 ' closing out of band context\n')
1171
1172
@@ -1300,6 +1301,20 b' class unbundlepart(unpackermixin):'
1300 """Generator of decoded chunks in the payload."""
1301 """Generator of decoded chunks in the payload."""
1301 return decodepayloadchunks(self.ui, self._fp)
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 def read(self, size=None):
1318 def read(self, size=None):
1304 """read payload data"""
1319 """read payload data"""
1305 if not self._initialized:
1320 if not self._initialized:
General Comments 0
You need to be logged in to leave comments. Login now