bundle2: allow compression options to be passed to compressor
authorGregory Szorc <gregory.szorc@gmail.com>
Tue, 10 Jan 2017 11:19:37 -0800
changeset 30757 511a4bf52754
parent 30756 1f9684fe94cc
child 30758 76104a4899ad
bundle2: allow compression options to be passed to compressor Compression engines allow options to be passed to them to control behavior. This patch exposes an argument to bundle2.writebundle() that passes options to the compression engine when writing compressed bundles. The argument is honored for both bundle1 and bundle2, the latter requiring a bit of plumbing to pass the value around.
mercurial/bundle2.py
--- a/mercurial/bundle2.py	Wed Jan 11 23:39:24 2017 +0800
+++ b/mercurial/bundle2.py	Tue Jan 10 11:19:37 2017 -0800
@@ -512,14 +512,16 @@
         self._parts = []
         self.capabilities = dict(capabilities)
         self._compengine = util.compengines.forbundletype('UN')
+        self._compopts = None
 
-    def setcompression(self, alg):
+    def setcompression(self, alg, compopts=None):
         """setup core part compression to <alg>"""
         if alg in (None, 'UN'):
             return
         assert not any(n.lower() == 'Compression' for n, v in self._params)
         self.addparam('Compression', alg)
         self._compengine = util.compengines.forbundletype(alg)
+        self._compopts = compopts
 
     @property
     def nbparts(self):
@@ -571,7 +573,8 @@
         yield _pack(_fstreamparamsize, len(param))
         if param:
             yield param
-        for chunk in self._compengine.compressstream(self._getcorechunk()):
+        for chunk in self._compengine.compressstream(self._getcorechunk(),
+                                                     self._compopts):
             yield chunk
 
     def _paramchunk(self):
@@ -1289,7 +1292,8 @@
     obscaps = caps.get('obsmarkers', ())
     return [int(c[1:]) for c in obscaps if c.startswith('V')]
 
-def writebundle(ui, cg, filename, bundletype, vfs=None, compression=None):
+def writebundle(ui, cg, filename, bundletype, vfs=None, compression=None,
+                compopts=None):
     """Write a bundle file and return its filename.
 
     Existing files will not be overwritten.
@@ -1300,7 +1304,7 @@
 
     if bundletype == "HG20":
         bundle = bundle20(ui)
-        bundle.setcompression(compression)
+        bundle.setcompression(compression, compopts)
         part = bundle.newpart('changegroup', data=cg.getchunks())
         part.addparam('version', cg.version)
         if 'clcount' in cg.extras:
@@ -1320,7 +1324,7 @@
         compengine = util.compengines.forbundletype(comp)
         def chunkiter():
             yield header
-            for chunk in compengine.compressstream(cg.getchunks()):
+            for chunk in compengine.compressstream(cg.getchunks(), compopts):
                 yield chunk
         chunkiter = chunkiter()