Mercurial > hg
comparison mercurial/hgweb/hgweb_mod.py @ 3610:44cd1eb72fd7
hgweb: introduce a new capability for sending a compressed bundle
the header of the bundle is the same as a on-disk bundle
HG10UN: uncompressed
HG10BZ: bz2
HG10GZ: gzip
no header means uncompressed (old client)
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Wed, 01 Nov 2006 22:06:24 +0100 |
parents | f8589028a7fa |
children | 967f1d00f521 |
comparison
equal
deleted
inserted
replaced
3609:a969e81631ce | 3610:44cd1eb72fd7 |
---|---|
9 import os | 9 import os |
10 import os.path | 10 import os.path |
11 import mimetypes | 11 import mimetypes |
12 from mercurial.demandload import demandload | 12 from mercurial.demandload import demandload |
13 demandload(globals(), "re zlib ConfigParser mimetools cStringIO sys tempfile") | 13 demandload(globals(), "re zlib ConfigParser mimetools cStringIO sys tempfile") |
14 demandload(globals(), 'urllib') | 14 demandload(globals(), 'urllib bz2') |
15 demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,streamclone,patch") | 15 demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,streamclone,patch") |
16 demandload(globals(), "mercurial:revlog,templater") | 16 demandload(globals(), "mercurial:revlog,templater") |
17 demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile,style_map") | 17 demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile,style_map") |
18 from mercurial.node import * | 18 from mercurial.node import * |
19 from mercurial.i18n import gettext as _ | 19 from mercurial.i18n import gettext as _ |
1019 untrusted=False) | 1019 untrusted=False) |
1020 req.write(staticfile(static, fname, req) | 1020 req.write(staticfile(static, fname, req) |
1021 or self.t("error", error="%r not found" % fname)) | 1021 or self.t("error", error="%r not found" % fname)) |
1022 | 1022 |
1023 def do_capabilities(self, req): | 1023 def do_capabilities(self, req): |
1024 caps = ['unbundle', 'lookup', 'changegroupsubset'] | 1024 caps = ['unbundle', 'lookup', 'changegroupsubset', 'standardbundle'] |
1025 if self.configbool('server', 'uncompressed'): | 1025 if self.configbool('server', 'uncompressed'): |
1026 caps.append('stream=%d' % self.repo.revlogversion) | 1026 caps.append('stream=%d' % self.repo.revlogversion) |
1027 resp = ' '.join(caps) | 1027 resp = ' '.join(caps) |
1028 req.httphdr("application/mercurial-0.1", length=len(resp)) | 1028 req.httphdr("application/mercurial-0.1", length=len(resp)) |
1029 req.write(resp) | 1029 req.write(resp) |
1099 req.write('0\n') | 1099 req.write('0\n') |
1100 req.write(_('unsynced changes\n')) | 1100 req.write(_('unsynced changes\n')) |
1101 return | 1101 return |
1102 | 1102 |
1103 fp.seek(0) | 1103 fp.seek(0) |
1104 header = fp.read(6) | |
1105 print repr(header) | |
1106 if not header.startswith("HG"): | |
1107 # old client with uncompressed bundle | |
1108 def generator(f): | |
1109 yield header | |
1110 for chunk in f: | |
1111 yield chunk | |
1112 elif not header.startswith("HG10"): | |
1113 req.write("0\n") | |
1114 req.write(_("unknown bundle version\n")) | |
1115 return | |
1116 elif header == "HG10GZ": | |
1117 def generator(f): | |
1118 zd = zlib.decompressobj() | |
1119 for chunk in f: | |
1120 yield zd.decompress(chunk) | |
1121 elif header == "HG10BZ": | |
1122 def generator(f): | |
1123 zd = bz2.BZ2Decompressor() | |
1124 zd.decompress("BZ") | |
1125 for chunk in f: | |
1126 yield zd.decompress(chunk) | |
1127 elif header == "HG10UN": | |
1128 def generator(f): | |
1129 for chunk in f: | |
1130 yield chunk | |
1131 else: | |
1132 req.write("0\n") | |
1133 req.write(_("unknown bundle compression type\n")) | |
1134 return | |
1135 gen = generator(util.filechunkiter(fp, 4096)) | |
1104 | 1136 |
1105 # send addchangegroup output to client | 1137 # send addchangegroup output to client |
1106 | 1138 |
1107 old_stdout = sys.stdout | 1139 old_stdout = sys.stdout |
1108 sys.stdout = cStringIO.StringIO() | 1140 sys.stdout = cStringIO.StringIO() |
1109 | 1141 |
1110 try: | 1142 try: |
1111 url = 'remote:%s:%s' % (proto, | 1143 url = 'remote:%s:%s' % (proto, |
1112 req.env.get('REMOTE_HOST', '')) | 1144 req.env.get('REMOTE_HOST', '')) |
1113 ret = self.repo.addchangegroup(fp, 'serve', url) | 1145 ret = self.repo.addchangegroup(util.chunkbuffer(gen), |
1146 'serve', url) | |
1114 finally: | 1147 finally: |
1115 val = sys.stdout.getvalue() | 1148 val = sys.stdout.getvalue() |
1116 sys.stdout = old_stdout | 1149 sys.stdout = old_stdout |
1117 req.write('%d\n' % ret) | 1150 req.write('%d\n' % ret) |
1118 req.write(val) | 1151 req.write(val) |