# HG changeset patch # User Pierre-Yves David # Date 2015-09-16 00:53:28 # Node ID eca468b8fae459ceff42fe72dc46c179861afa3a # Parent 1e042e31bd0ce66d89431dea1ac594228e66ee01 compression: use 'None' for no-compression This seems more idiomatic and clearer. We still support both None and 'UN' for now because no user are migrated. diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -158,6 +158,8 @@ class cg1unpacker(object): deltaheadersize = struct.calcsize(deltaheader) version = '01' def __init__(self, fh, alg): + if alg == 'UN': + alg = None # get more modern without breaking too much if not alg in util.decompressors: raise util.Abort(_('unknown stream compression type: %s') % alg) @@ -165,7 +167,7 @@ class cg1unpacker(object): self._type = alg self.callback = None def compressed(self): - return self._type != 'UN' + return self._type is not None def read(self, l): return self._stream.read(l) def seek(self, pos): diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -2349,11 +2349,13 @@ class nocompress(object): return "" compressors = { - 'UN': nocompress, + None: nocompress, # lambda to prevent early import 'BZ': lambda: bz2.BZ2Compressor(), 'GZ': lambda: zlib.compressobj(), } +# also support the old form by courtesies +compressors['UN'] = compressors[None] def _makedecompressor(decompcls): def generator(f): @@ -2371,10 +2373,12 @@ def _bz2(): d.decompress('BZ') return d -decompressors = {'UN': lambda fh: fh, +decompressors = {None: lambda fh: fh, 'BZ': _makedecompressor(_bz2), 'GZ': _makedecompressor(lambda: zlib.decompressobj()), } +# also support the old form by courtesies +decompressors['UN'] = decompressors[None] # convenient shortcut dst = debugstacktrace