Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
21000:4cae06ae1562 | 21001:c93bb6a08fa1 |
---|---|
158 _fpartheadersize = '>H' | 158 _fpartheadersize = '>H' |
159 _fparttypesize = '>B' | 159 _fparttypesize = '>B' |
160 _fpartid = '>I' | 160 _fpartid = '>I' |
161 _fpayloadsize = '>I' | 161 _fpayloadsize = '>I' |
162 _fpartparamcount = '>BB' | 162 _fpartparamcount = '>BB' |
163 | |
164 preferedchunksize = 4096 | |
163 | 165 |
164 def _makefpartparamsizes(nbparams): | 166 def _makefpartparamsizes(nbparams): |
165 """return a struct format to read part parameter sizes | 167 """return a struct format to read part parameter sizes |
166 | 168 |
167 The number parameters is variable so we need to build that format | 169 The number parameters is variable so we need to build that format |
559 """yield chunks of a the part payload | 561 """yield chunks of a the part payload |
560 | 562 |
561 Exists to handle the different methods to provide data to a part.""" | 563 Exists to handle the different methods to provide data to a part.""" |
562 # we only support fixed size data now. | 564 # we only support fixed size data now. |
563 # This will be improved in the future. | 565 # This will be improved in the future. |
564 if len(self.data): | 566 if util.safehasattr(self.data, 'next'): |
567 buff = util.chunkbuffer(self.data) | |
568 chunk = buff.read(preferedchunksize) | |
569 while chunk: | |
570 yield chunk | |
571 chunk = buff.read(preferedchunksize) | |
572 elif len(self.data): | |
565 yield self.data | 573 yield self.data |
566 | 574 |
567 @parthandler('changegroup') | 575 @parthandler('changegroup') |
568 def handlechangegroup(op, inpart): | 576 def handlechangegroup(op, inpart): |
569 """apply a changegroup part on the repo | 577 """apply a changegroup part on the repo |