335 |
335 |
336 def unbundle(self, cg, heads, source): |
336 def unbundle(self, cg, heads, source): |
337 # have to stream bundle to a temp file because we do not have |
337 # have to stream bundle to a temp file because we do not have |
338 # http 1.1 chunked transfer. |
338 # http 1.1 chunked transfer. |
339 |
339 |
|
340 use_compress = 'standardbundle' in self.capabilities |
|
341 |
|
342 # XXX duplication from commands.py |
|
343 class nocompress(object): |
|
344 def compress(self, x): |
|
345 return x |
|
346 def flush(self): |
|
347 return "" |
|
348 |
|
349 if use_compress: |
|
350 header = "HG10GZ" |
|
351 z = zlib.compressobj() |
|
352 else: |
|
353 self.ui.note(_("server has no compression support, " |
|
354 "sending uncompressed")) |
|
355 header = "" |
|
356 z = nocompress() |
|
357 |
340 fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-') |
358 fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-') |
341 fp = os.fdopen(fd, 'wb+') |
359 fp = os.fdopen(fd, 'wb+') |
342 try: |
360 try: |
|
361 fp.write(header) |
343 for chunk in util.filechunkiter(cg): |
362 for chunk in util.filechunkiter(cg): |
344 fp.write(chunk) |
363 fp.write(z.compress(chunk)) |
|
364 fp.write(z.flush()) |
345 length = fp.tell() |
365 length = fp.tell() |
346 try: |
366 try: |
347 rfp = self.do_cmd( |
367 rfp = self.do_cmd( |
348 'unbundle', data=fp, |
368 'unbundle', data=fp, |
349 headers={'content-length': str(length), |
369 headers={'content-length': str(length), |