##// END OF EJS Templates
improve changegroup.readbundle(), use it in hgweb
Dirkjan Ochtman -
r6154:ef1c5a3b default
parent child Browse files
Show More
@@ -108,22 +108,34 b' def writebundle(cg, filename, bundletype'
108 108 if cleanup is not None:
109 109 os.unlink(cleanup)
110 110
111 def readbundle(fh, fname):
112 header = fh.read(6)
113 if not header.startswith("HG"):
114 raise util.Abort(_("%s: not a Mercurial bundle file") % fname)
115 elif not header.startswith("HG10"):
116 raise util.Abort(_("%s: unknown bundle version") % fname)
117
118 if header == "HG10BZ":
111 def unbundle(header, fh):
112 if header == 'HG10UN':
113 return fh
114 elif not header.startswith('HG'):
115 # old client with uncompressed bundle
116 def generator(f):
117 yield header
118 for chunk in f:
119 yield chunk
120 elif header == 'HG10GZ':
121 def generator(f):
122 zd = zlib.decompressobj()
123 for chunk in f:
124 yield zd.decompress(chunk)
125 elif header == 'HG10BZ':
119 126 def generator(f):
120 127 zd = bz2.BZ2Decompressor()
121 128 zd.decompress("BZ")
122 129 for chunk in util.filechunkiter(f, 4096):
123 130 yield zd.decompress(chunk)
124 return util.chunkbuffer(generator(fh))
125 elif header == "HG10UN":
126 return fh
131 return util.chunkbuffer(generator(fh))
127 132
128 raise util.Abort(_("%s: unknown bundle compression type")
129 % fname)
133 def readbundle(fh, fname):
134 header = fh.read(6)
135 if not header.startswith('HG'):
136 raise util.Abort(_('%s: not a Mercurial bundle file') % fname)
137 if not header.startswith('HG10'):
138 raise util.Abort(_('%s: unknown bundle version') % fname)
139 elif header not in bundletypes:
140 raise util.Abort(_('%s: unknown bundle compression type') % fname)
141 return unbundle(header, fh)
@@ -9,6 +9,7 b' import cStringIO, zlib, bz2, tempfile, e'
9 9 from mercurial import util, streamclone
10 10 from mercurial.i18n import gettext as _
11 11 from mercurial.node import *
12 from mercurial import changegroup as changegroupmod
12 13 from common import HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
13 14
14 15 # __all__ is populated with the allowed commands. Be sure to add to it if
@@ -167,36 +168,11 b' def unbundle(web, req):'
167 168
168 169 fp.seek(0)
169 170 header = fp.read(6)
170 if not header.startswith("HG"):
171 # old client with uncompressed bundle
172 def generator(f):
173 yield header
174 for chunk in f:
175 yield chunk
176 elif not header.startswith("HG10"):
177 req.write("0\n")
178 req.write(_("unknown bundle version\n"))
179 return
180 elif header == "HG10GZ":
181 def generator(f):
182 zd = zlib.decompressobj()
183 for chunk in f:
184 yield zd.decompress(chunk)
185 elif header == "HG10BZ":
186 def generator(f):
187 zd = bz2.BZ2Decompressor()
188 zd.decompress("BZ")
189 for chunk in f:
190 yield zd.decompress(chunk)
191 elif header == "HG10UN":
192 def generator(f):
193 for chunk in f:
194 yield chunk
195 else:
196 req.write("0\n")
197 req.write(_("unknown bundle compression type\n"))
198 return
199 gen = generator(util.filechunkiter(fp, 4096))
171 if header.startswith('HG') and not header.startswith('HG10'):
172 raise ValueError('unknown bundle version')
173 elif header not in changegroupmod.bundletypes:
174 raise ValueError('unknown bundle compression type')
175 gen = changegroupmod.unbundle(header, fp)
200 176
201 177 # send addchangegroup output to client
202 178
@@ -207,8 +183,7 b' def unbundle(web, req):'
207 183 url = 'remote:%s:%s' % (proto,
208 184 req.env.get('REMOTE_HOST', ''))
209 185 try:
210 ret = web.repo.addchangegroup(
211 util.chunkbuffer(gen), 'serve', url)
186 ret = web.repo.addchangegroup(gen, 'serve', url)
212 187 except util.Abort, inst:
213 188 sys.stdout.write("abort: %s\n" % inst)
214 189 ret = 0
@@ -219,6 +194,9 b' def unbundle(web, req):'
219 194 req.write(val)
220 195 finally:
221 196 del lock
197 except ValueError, inst:
198 req.write('0\n')
199 req.write(str(inst) + '\n')
222 200 except (OSError, IOError), inst:
223 201 req.write('0\n')
224 202 filename = getattr(inst, 'filename', '')
General Comments 0
You need to be logged in to leave comments. Login now