Patchwork [09,of,10,V2] hgweb: use compression engine API for zlib compression

login
register
mail settings
Submitter Gregory Szorc
Date Nov. 8, 2016, 3:13 a.m.
Message ID <8e2ca8bfa2d0f7c02b6f.1478574837@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/17387/
State Accepted
Headers show

Comments

Gregory Szorc - Nov. 8, 2016, 3:13 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1478573675 28800
#      Mon Nov 07 18:54:35 2016 -0800
# Node ID 8e2ca8bfa2d0f7c02b6f58b36341b4c4cf7ec0f9
# Parent  fc931794a250e605717cc066f26512c0dcc81224
hgweb: use compression engine API for zlib compression

More low-level compression code elimination because we now have nice
APIs.

This patch also demonstrates why we needed and implemented the
"level" option on the "compressstream" API.

Patch

diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py
--- a/mercurial/hgweb/protocol.py
+++ b/mercurial/hgweb/protocol.py
@@ -88,14 +88,8 @@  class webproto(wireproto.abstractserverp
         # Don't allow untrusted settings because disabling compression or
         # setting a very high compression level could lead to flooding
         # the server's network or CPU.
-        z = zlib.compressobj(self.ui.configint('server', 'zliblevel', -1))
-        for chunk in chunks:
-            data = z.compress(chunk)
-            # Not all calls to compress() emit data. It is cheaper to inspect
-            # that here than to send it via the generator.
-            if data:
-                yield data
-        yield z.flush()
+        opts = {'level': self.ui.configint('server', 'zliblevel', -1)}
+        return util.compengines['zlib'].compressstream(chunks, opts)
 
     def _client(self):
         return 'remote:%s:%s:%s' % (