diff mercurial/bundle2.py @ 21001:c93bb6a08fa1

bundle2: support chunk iterator as part data When the `part.data` attribute is an iterator, we assume it is an iterator of chunks and use it. We use a chunkbuffer to yield chunks of 4096 bytes. The tests are updated to use this feature.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 11 Apr 2014 08:04:16 -0700
parents 4cae06ae1562
children 27ab4b8d2503
line wrap: on
line diff
--- a/mercurial/bundle2.py	Thu Apr 10 12:33:20 2014 -0700
+++ b/mercurial/bundle2.py	Fri Apr 11 08:04:16 2014 -0700
@@ -161,6 +161,8 @@
 _fpayloadsize = '>I'
 _fpartparamcount = '>BB'
 
+preferedchunksize = 4096
+
 def _makefpartparamsizes(nbparams):
     """return a struct format to read part parameter sizes
 
@@ -561,7 +563,13 @@
         Exists to handle the different methods to provide data to a part."""
         # we only support fixed size data now.
         # This will be improved in the future.
-        if len(self.data):
+        if util.safehasattr(self.data, 'next'):
+            buff = util.chunkbuffer(self.data)
+            chunk = buff.read(preferedchunksize)
+            while chunk:
+                yield chunk
+                chunk = buff.read(preferedchunksize)
+        elif len(self.data):
             yield self.data
 
 @parthandler('changegroup')