changeset 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 dda41da069a4
files mercurial/bundle2.py tests/test-bundle2.t
diffstat 2 files changed, 18 insertions(+), 10 deletions(-) [+]
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')
--- a/tests/test-bundle2.t	Thu Apr 10 12:33:20 2014 -0700
+++ b/tests/test-bundle2.t	Fri Apr 11 08:04:16 2014 -0700
@@ -66,11 +66,11 @@
   >             headcommon  = [c.node() for c in repo.set('parents(%ld) - %ld', revs, revs)]
   >             outgoing = discovery.outgoing(repo.changelog, headcommon, headmissing)
   >             cg = changegroup.getlocalbundle(repo, 'test:bundle2', outgoing, None)
-  >             assert cg is not None
-  >             # make me lazy later
-  >             tempname = changegroup.writebundle(cg, None, 'HG10UN')
-  >             data = open(tempname).read()
-  >             part = bundle2.part('changegroup', data=data)
+  >             def cgchunks(cg=cg):
+  >                 yield 'HG10UN'
+  >                 for c in cg.getchunks():
+  >                    yield c
+  >             part = bundle2.part('changegroup', data=cgchunks())
   >             bundler.addpart(part)
   > 
   >     if opts['parts']:
@@ -585,6 +585,10 @@
   9520eea781bcca16c1e15acc0ba14335a0e8e5ba
   eea13746799a9e0bfd88f29d3c2e9dc9389f524f
   02de42196ebee42ef284b6780a87cdc96e8eaab6
+  start emission of HG20 stream
+  bundle parameter: 
+  start of parts
+  bundle part: "changegroup"
   bundling: 1/4 changesets (25.00%)
   bundling: 2/4 changesets (50.00%)
   bundling: 3/4 changesets (75.00%)
@@ -596,10 +600,6 @@
   bundling: D 1/3 files (33.33%)
   bundling: E 2/3 files (66.67%)
   bundling: H 3/3 files (100.00%)
-  start emission of HG20 stream
-  bundle parameter: 
-  start of parts
-  bundle part: "changegroup"
   end of bundle
 
   $ cat ../rev.hg2