Patchwork [1,of,5,more-in-stack] compression: use 'None' for no-compression

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 18, 2015, 12:18 a.m.
Message ID <fd2be097daf47c1d8f94.1442535522@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/10530/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 18, 2015, 12:18 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1442364808 25200
#      Tue Sep 15 17:53:28 2015 -0700
# Node ID fd2be097daf47c1d8f94f1c99084c5240bdb3f95
# 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.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -156,18 +156,20 @@  def writebundle(ui, cg, filename, bundle
 class cg1unpacker(object):
     deltaheader = _CHANGEGROUPV1_DELTA_HEADER
     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)
         self._stream = util.decompressors[alg](fh)
         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):
         return self._stream.seek(pos)
     def tell(self):
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2347,15 +2347,17 @@  class nocompress(object):
         return x
     def flush(self):
         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):
         d = decompcls()
         for chunk in filechunkiter(f):
@@ -2369,12 +2371,14 @@  def _bz2():
     # Bzip2 stream start with BZ, but we stripped it.
     # we put it back for good measure.
     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