Mercurial > hg
comparison mercurial/bundle2.py @ 30357:5925bda42dbd
bundle2: use compressstream compression engine API
Compression engines now have an API for compressing a stream of
chunks. Switch to it and make low-level compression code disappear.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 07 Nov 2016 18:46:37 -0800 |
parents | d045b4091197 |
children | 71b368e3b590 |
comparison
equal
deleted
inserted
replaced
30356:c86109eface7 | 30357:5925bda42dbd |
---|---|
569 param = self._paramchunk() | 569 param = self._paramchunk() |
570 outdebug(self.ui, 'bundle parameter: %s' % param) | 570 outdebug(self.ui, 'bundle parameter: %s' % param) |
571 yield _pack(_fstreamparamsize, len(param)) | 571 yield _pack(_fstreamparamsize, len(param)) |
572 if param: | 572 if param: |
573 yield param | 573 yield param |
574 # starting compression | 574 for chunk in self._compengine.compressstream(self._getcorechunk()): |
575 compressor = self._compengine.compressorobj() | 575 yield chunk |
576 for chunk in self._getcorechunk(): | |
577 data = compressor.compress(chunk) | |
578 if data: | |
579 yield data | |
580 yield compressor.flush() | |
581 | 576 |
582 def _paramchunk(self): | 577 def _paramchunk(self): |
583 """return a encoded version of all stream parameters""" | 578 """return a encoded version of all stream parameters""" |
584 blocks = [] | 579 blocks = [] |
585 for par, value in self._params: | 580 for par, value in self._params: |
1321 header, comp = bundletypes[bundletype] | 1316 header, comp = bundletypes[bundletype] |
1322 if comp not in util.compengines.supportedbundletypes: | 1317 if comp not in util.compengines.supportedbundletypes: |
1323 raise error.Abort(_('unknown stream compression type: %s') | 1318 raise error.Abort(_('unknown stream compression type: %s') |
1324 % comp) | 1319 % comp) |
1325 compengine = util.compengines.forbundletype(comp) | 1320 compengine = util.compengines.forbundletype(comp) |
1326 compressor = compengine.compressorobj() | |
1327 subchunkiter = cg.getchunks() | |
1328 def chunkiter(): | 1321 def chunkiter(): |
1329 yield header | 1322 yield header |
1330 for chunk in subchunkiter: | 1323 for chunk in compengine.compressstream(cg.getchunks()): |
1331 data = compressor.compress(chunk) | 1324 yield chunk |
1332 if data: | |
1333 yield data | |
1334 yield compressor.flush() | |
1335 chunkiter = chunkiter() | 1325 chunkiter = chunkiter() |
1336 | 1326 |
1337 # parse the changegroup data, otherwise we will block | 1327 # parse the changegroup data, otherwise we will block |
1338 # in case of sshrepo because we don't know the end of the stream | 1328 # in case of sshrepo because we don't know the end of the stream |
1339 return changegroup.writechunks(ui, chunkiter, filename, vfs=vfs) | 1329 return changegroup.writechunks(ui, chunkiter, filename, vfs=vfs) |