Patchwork [08,of,10,V2] bundle2: use compressstream compression engine API

login
register
mail settings
Submitter Gregory Szorc
Date Nov. 8, 2016, 3:13 a.m.
Message ID <fc931794a250e605717c.1478574836@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/17386/
State Accepted
Headers show

Comments

Gregory Szorc - Nov. 8, 2016, 3:13 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1478573197 28800
#      Mon Nov 07 18:46:37 2016 -0800
# Node ID fc931794a250e605717cc066f26512c0dcc81224
# Parent  fa24595b79b603ff7be6f32b849c07ddfdee3da4
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.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -571,13 +571,8 @@  class bundle20(object):
         yield _pack(_fstreamparamsize, len(param))
         if param:
             yield param
-        # starting compression
-        compressor = self._compengine.compressorobj()
-        for chunk in self._getcorechunk():
-            data = compressor.compress(chunk)
-            if data:
-                yield data
-        yield compressor.flush()
+        for chunk in self._compengine.compressstream(self._getcorechunk()):
+            yield chunk
 
     def _paramchunk(self):
         """return a encoded version of all stream parameters"""
@@ -1323,15 +1318,10 @@  def writebundle(ui, cg, filename, bundle
             raise error.Abort(_('unknown stream compression type: %s')
                               % comp)
         compengine = util.compengines.forbundletype(comp)
-        compressor = compengine.compressorobj()
-        subchunkiter = cg.getchunks()
         def chunkiter():
             yield header
-            for chunk in subchunkiter:
-                data = compressor.compress(chunk)
-                if data:
-                    yield data
-            yield compressor.flush()
+            for chunk in compengine.compressstream(cg.getchunks()):
+                yield chunk
         chunkiter = chunkiter()
 
     # parse the changegroup data, otherwise we will block