Patchwork [11,of,11] util: remove compressorobj API from compression engines

login
register
mail settings
Submitter Gregory Szorc
Date Nov. 2, 2016, 12:08 a.m.
Message ID <4f491f7958229b370c59.1478045324@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/17254/
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 1477160459 25200
#      Sat Oct 22 11:20:59 2016 -0700
# Node ID 4f491f7958229b370c5929d2e2599b9ed69d8254
# Parent  fc426af4f25c3403703e913ccb4a6865865fcb02
util: remove compressorobj API from compression engines

It was quite low-level and there are no callers of it now that
everyone is using compressstream()

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2884,22 +2884,16 @@  class compressormanager(object):
 
         The passed compression engine is an object with attributes describing
         behavior and methods performing well-defined actions. The following
         attributes are recognized (all are optional):
 
         * bundletype -- Attribute containing the identifier of this compression
           format as used by bundles.
 
-        * compressorobj -- Method returning an object with ``compress(data)``
-          and ``flush()`` methods. This object and these methods are used to
-          incrementally feed data (presumably uncompressed) chunks into a
-          compressor. Calls to these methods return compressed bytes, which
-          may be 0-length if there is no output for the operation.
-
         * compressstream -- Compress an iterator of chunks and return an
           iterator of compressed chunks.
 
           Optionally accepts an argument defining how to perform compression.
           Each engine treats this argument differently.
 
         * decompressorreader -- Method that is used to perform decompression
           on a file object. Argument is an object with a ``read(size)`` method
@@ -2928,19 +2922,16 @@  class compressormanager(object):
 
 compressionengines = compressormanager()
 
 class _zlibengine(object):
     @property
     def bundletype(self):
         return 'GZ'
 
-    def compressorobj(self):
-        return zlib.compressobj()
-
     def compressstream(self, it, opts=None):
         opts = opts or {}
 
         z = zlib.compressobj(opts.get('level', -1))
         for chunk in it:
             data = z.compress(chunk)
             # Not all calls to compress emit data. It is cheaper to inspect
             # here than to feed empty chunks through generator.
@@ -2959,19 +2950,16 @@  class _zlibengine(object):
 
 compressionengines.register('zlib', _zlibengine())
 
 class _bz2engine(object):
     @property
     def bundletype(self):
         return 'BZ'
 
-    def compressorobj(self):
-        return bz2.BZ2Compressor()
-
     def compressstream(self, it, opts=None):
         opts = opts or {}
         z = bz2.BZ2Compressor(opts.get('level', 9))
         for chunk in it:
             data = z.compress(chunk)
             if data:
                 yield data
 
@@ -2987,45 +2975,35 @@  class _bz2engine(object):
 
 compressionengines.register('bz2', _bz2engine())
 
 class _truncatedbz2engine(object):
     @property
     def bundletype(self):
         return '_truncatedBZ'
 
-    # We don't implement compressorobj because it is hackily handled elsewhere.
+    # We don't implement compressstream because it is hackily handled elsewhere.
 
     def decompressorreader(self, fh):
         def gen():
             # The input stream doesn't have the 'BZ' header. So add it back.
             d = bz2.BZ2Decompressor()
             d.decompress('BZ')
             for chunk in filechunkiter(fh):
                 yield d.decompress(chunk)
 
         return chunkbuffer(gen())
 
 compressionengines.register('bz2truncated', _truncatedbz2engine())
 
-class nocompress(object):
-    def compress(self, x):
-        return x
-
-    def flush(self):
-        return ''
-
 class _noopengine(object):
     @property
     def bundletype(self):
         return 'UN'
 
-    def compressorobj(self):
-        return nocompress()
-
     def compressstream(self, it, opts=None):
         return it
 
     def decompressorreader(self, fh):
         return fh
 
 compressionengines.register('none', _noopengine())