Patchwork [1,of,2] bundle2: allow compression options to be passed to compressor

login
register
mail settings
Submitter Gregory Szorc
Date Jan. 10, 2017, 7:34 p.m.
Message ID <82e5f4db873e2e4e01bb.1484076890@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/18174/
State Accepted
Headers show

Comments

Gregory Szorc - Jan. 10, 2017, 7:34 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1484075977 28800
#      Tue Jan 10 11:19:37 2017 -0800
# Node ID 82e5f4db873e2e4e01bb5264a5b2cc22781fc4b3
# Parent  9cb0bb0f29f06fa88ac4f41d8743871b33c48548
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.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -512,14 +512,16 @@  class bundle20(object):
         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 @@  class bundle20(object):
         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 @@  def obsmarkersversion(caps):
     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 @@  def writebundle(ui, cg, filename, bundle
 
     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 @@  def writebundle(ui, cg, filename, bundle
         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()