util: put compression code next to each other
ctxmanager was injecting itself between the compression and
decompression code. Let's restore some order.
--- a/mercurial/util.py Sat Jun 28 13:13:32 2014 +0900
+++ b/mercurial/util.py Sat Oct 15 17:24:01 2016 -0700
@@ -2794,32 +2794,6 @@
yield path[:pos]
pos = path.rfind('/', 0, pos)
-# compression utility
-
-class nocompress(object):
- def compress(self, x):
- return x
- def flush(self):
- return ""
-
-compressors = {
- 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):
- yield d.decompress(chunk)
- def func(fh):
- return chunkbuffer(generator(fh))
- return func
-
class ctxmanager(object):
'''A context manager for use in 'with' blocks to allow multiple
contexts to be entered at once. This is both safer and more
@@ -2880,6 +2854,32 @@
raise exc_val
return received and suppressed
+# compression utility
+
+class nocompress(object):
+ def compress(self, x):
+ return x
+ def flush(self):
+ return ""
+
+compressors = {
+ 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):
+ yield d.decompress(chunk)
+ def func(fh):
+ return chunkbuffer(generator(fh))
+ return func
+
def _bz2():
d = bz2.BZ2Decompressor()
# Bzip2 stream start with BZ, but we stripped it.