Patchwork [05,of,11] bundle2: use compression engines API to obtain decompressor

login
register
mail settings
Submitter Gregory Szorc
Date Nov. 2, 2016, 12:08 a.m.
Message ID <859682e2187c46bb7ab6.1478045318@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/17249/
State Superseded
Headers show

Comments

Gregory Szorc - Nov. 2, 2016, 12:08 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1477158197 25200
#      Sat Oct 22 10:43:17 2016 -0700
# Node ID 859682e2187c46bb7ab68aedd7dcbab5266d878e
# Parent  b32a9f8f72bcaea41d23165cc26583b0dcfb0fc6
bundle2: use compression engines API to obtain decompressor

Like the recent change for the compressor side, this too is
relatively straightforward. We now store a compression engine
on the instance instead of a low-level decompressor. This will
allow us to transition to a new decompression API when one is
ready.
via Mercurial-devel - Nov. 17, 2016, 9:55 p.m.
On Tue, Nov 1, 2016 at 5:08 PM, Gregory Szorc <gregory.szorc@gmail.com> wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1477158197 25200
> #      Sat Oct 22 10:43:17 2016 -0700
> # Node ID 859682e2187c46bb7ab68aedd7dcbab5266d878e
> # Parent  b32a9f8f72bcaea41d23165cc26583b0dcfb0fc6
> bundle2: use compression engines API to obtain decompressor
>
> Like the recent change for the compressor side, this too is
> relatively straightforward. We now store a compression engine
> on the instance instead of a low-level decompressor. This will
> allow us to transition to a new decompression API when one is
> ready.
>
> diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
> --- a/mercurial/bundle2.py
> +++ b/mercurial/bundle2.py
> @@ -676,17 +676,17 @@ class unbundle20(unpackermixin):
>      This class is fed with a binary stream and yields parts through its
>      `iterparts` methods."""
>
>      _magicstring = 'HG20'
>
>      def __init__(self, ui, fp):
>          """If header is specified, we do not read it out of the stream."""
>          self.ui = ui
> -        self._decompressor = util.decompressors[None]
> +        self._compengine = util.compressionengines.forbundletype('UN')
>          self._compressed = None
>          super(unbundle20, self).__init__(fp)
>
>      @util.propertycache
>      def params(self):
>          """dictionary of stream level parameters"""
>          indebug(self.ui, 'reading bundle2 stream parameters')
>          params = {}
> @@ -750,19 +750,19 @@ class unbundle20(unpackermixin):
>          if paramssize < 0:
>              raise error.BundleValueError('negative bundle param size: %i'
>                                           % paramssize)
>          yield _pack(_fstreamparamsize, paramssize)
>          if paramssize:
>              params = self._readexact(paramssize)
>              self._processallparams(params)
>              yield params
> -            assert self._decompressor is util.decompressors[None]
> +            assert self._compengine.bundletype == 'UN'

Should be bundletype()[0], right? Any idea why your version passes? I
haven't even looked at what this code is doing, but it's unfortunate
that we don't seem to have a test for it.

>          # From there, payload might need to be decompressed
> -        self._fp = self._decompressor(self._fp)
> +        self._fp = self._compengine.decompressorreader(self._fp)
>          emptycount = 0
>          while emptycount < 2:
>              # so we can brainlessly loop
>              assert _fpartheadersize == _fpayloadsize
>              size = self._unpack(_fpartheadersize)[0]
>              yield _pack(_fpartheadersize, size)
>              if size:
>                  emptycount = 0
> @@ -776,17 +776,17 @@ class unbundle20(unpackermixin):
>              yield self._readexact(size)
>
>
>      def iterparts(self):
>          """yield all parts contained in the stream"""
>          # make sure param have been loaded
>          self.params
>          # From there, payload need to be decompressed
> -        self._fp = self._decompressor(self._fp)
> +        self._fp = self._compengine.decompressorreader(self._fp)
>          indebug(self.ui, 'start extraction of bundle2 parts')
>          headerblock = self._readpartheader()
>          while headerblock is not None:
>              part = unbundlepart(self.ui, headerblock, self._fp)
>              yield part
>              part.seek(0, 2)
>              headerblock = self._readpartheader()
>          indebug(self.ui, 'end of bundle2 stream')
> @@ -818,20 +818,20 @@ def b2streamparamhandler(name):
>          assert name not in formatmap
>          b2streamparamsmap[name] = func
>          return func
>      return decorator
>
>  @b2streamparamhandler('compression')
>  def processcompression(unbundler, param, value):
>      """read compression parameter and install payload decompression"""
> -    if value not in util.decompressors:
> +    if value not in util.compressionengines.supportedbundletypes:
>          raise error.BundleUnknownFeatureError(params=(param,),
>                                                values=(value,))
> -    unbundler._decompressor = util.decompressors[value]
> +    unbundler._compengine = util.compressionengines.forbundletype(value)
>      if value is not None:
>          unbundler._compressed = True
>
>  class bundlepart(object):
>      """A bundle2 part contains application level payload
>
>      The part `type` is used to route the part to the application level
>      handler.
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -676,17 +676,17 @@  class unbundle20(unpackermixin):
     This class is fed with a binary stream and yields parts through its
     `iterparts` methods."""
 
     _magicstring = 'HG20'
 
     def __init__(self, ui, fp):
         """If header is specified, we do not read it out of the stream."""
         self.ui = ui
-        self._decompressor = util.decompressors[None]
+        self._compengine = util.compressionengines.forbundletype('UN')
         self._compressed = None
         super(unbundle20, self).__init__(fp)
 
     @util.propertycache
     def params(self):
         """dictionary of stream level parameters"""
         indebug(self.ui, 'reading bundle2 stream parameters')
         params = {}
@@ -750,19 +750,19 @@  class unbundle20(unpackermixin):
         if paramssize < 0:
             raise error.BundleValueError('negative bundle param size: %i'
                                          % paramssize)
         yield _pack(_fstreamparamsize, paramssize)
         if paramssize:
             params = self._readexact(paramssize)
             self._processallparams(params)
             yield params
-            assert self._decompressor is util.decompressors[None]
+            assert self._compengine.bundletype == 'UN'
         # From there, payload might need to be decompressed
-        self._fp = self._decompressor(self._fp)
+        self._fp = self._compengine.decompressorreader(self._fp)
         emptycount = 0
         while emptycount < 2:
             # so we can brainlessly loop
             assert _fpartheadersize == _fpayloadsize
             size = self._unpack(_fpartheadersize)[0]
             yield _pack(_fpartheadersize, size)
             if size:
                 emptycount = 0
@@ -776,17 +776,17 @@  class unbundle20(unpackermixin):
             yield self._readexact(size)
 
 
     def iterparts(self):
         """yield all parts contained in the stream"""
         # make sure param have been loaded
         self.params
         # From there, payload need to be decompressed
-        self._fp = self._decompressor(self._fp)
+        self._fp = self._compengine.decompressorreader(self._fp)
         indebug(self.ui, 'start extraction of bundle2 parts')
         headerblock = self._readpartheader()
         while headerblock is not None:
             part = unbundlepart(self.ui, headerblock, self._fp)
             yield part
             part.seek(0, 2)
             headerblock = self._readpartheader()
         indebug(self.ui, 'end of bundle2 stream')
@@ -818,20 +818,20 @@  def b2streamparamhandler(name):
         assert name not in formatmap
         b2streamparamsmap[name] = func
         return func
     return decorator
 
 @b2streamparamhandler('compression')
 def processcompression(unbundler, param, value):
     """read compression parameter and install payload decompression"""
-    if value not in util.decompressors:
+    if value not in util.compressionengines.supportedbundletypes:
         raise error.BundleUnknownFeatureError(params=(param,),
                                               values=(value,))
-    unbundler._decompressor = util.decompressors[value]
+    unbundler._compengine = util.compressionengines.forbundletype(value)
     if value is not None:
         unbundler._compressed = True
 
 class bundlepart(object):
     """A bundle2 part contains application level payload
 
     The part `type` is used to route the part to the application level
     handler.