hgweb: if the server supports it, send a compressed bundle
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Wed, 01 Nov 2006 22:01:30 +0100
changeset 3609 a969e81631ce
parent 3608 802da51cab5b
child 3610 44cd1eb72fd7
hgweb: if the server supports it, send a compressed bundle
mercurial/httprepo.py
--- a/mercurial/httprepo.py	Wed Nov 01 14:53:11 2006 -0300
+++ b/mercurial/httprepo.py	Wed Nov 01 22:01:30 2006 +0100
@@ -337,11 +337,31 @@
         # have to stream bundle to a temp file because we do not have
         # http 1.1 chunked transfer.
 
+        use_compress = 'standardbundle' in self.capabilities
+
+        # XXX duplication from commands.py
+        class nocompress(object):
+            def compress(self, x):
+                return x
+            def flush(self):
+                return ""
+
+        if use_compress:
+            header = "HG10GZ"
+            z = zlib.compressobj()
+        else:
+            self.ui.note(_("server has no compression support, "
+                           "sending uncompressed"))
+            header = ""
+            z = nocompress()
+
         fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-')
         fp = os.fdopen(fd, 'wb+')
         try:
+            fp.write(header)
             for chunk in util.filechunkiter(cg):
-                fp.write(chunk)
+                fp.write(z.compress(chunk))
+            fp.write(z.flush())
             length = fp.tell()
             try:
                 rfp = self.do_cmd(