9 from node import * |
9 from node import * |
10 from remoterepo import * |
10 from remoterepo import * |
11 from i18n import gettext as _ |
11 from i18n import gettext as _ |
12 from demandload import * |
12 from demandload import * |
13 demandload(globals(), "hg os urllib urllib2 urlparse zlib util httplib") |
13 demandload(globals(), "hg os urllib urllib2 urlparse zlib util httplib") |
14 demandload(globals(), "errno keepalive tempfile socket") |
14 demandload(globals(), "errno keepalive tempfile socket changegroup") |
15 |
15 |
16 class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm): |
16 class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm): |
17 def __init__(self, ui): |
17 def __init__(self, ui): |
18 urllib2.HTTPPasswordMgrWithDefaultRealm.__init__(self) |
18 urllib2.HTTPPasswordMgrWithDefaultRealm.__init__(self) |
19 self.ui = ui |
19 self.ui = ui |
324 |
324 |
325 def unbundle(self, cg, heads, source): |
325 def unbundle(self, cg, heads, source): |
326 # have to stream bundle to a temp file because we do not have |
326 # have to stream bundle to a temp file because we do not have |
327 # http 1.1 chunked transfer. |
327 # http 1.1 chunked transfer. |
328 |
328 |
329 # XXX duplication from commands.py |
329 type = "" |
330 class nocompress(object): |
330 types = self.capable('unbundle') |
331 def compress(self, x): |
331 if types: |
332 return x |
332 for x in types.split(','): |
333 def flush(self): |
333 if x in changegroup.bundletypes: |
334 return "" |
334 type = x |
335 |
335 break |
336 unbundleversions = self.capable('unbundle') |
336 |
337 try: |
337 tempname = changegroup.writebundle(cg, None, type) |
338 unbundleversions = unbundleversions.split(',') |
338 fp = file(tempname, "rb") |
339 except AttributeError: |
339 try: |
340 unbundleversions = [""] |
340 length = os.stat(tempname).st_size |
341 |
|
342 while unbundleversions: |
|
343 header = unbundleversions[0] |
|
344 if header == "HG10GZ": |
|
345 self.ui.note(_("using zlib compression\n")) |
|
346 z = zlib.compressobj() |
|
347 break |
|
348 elif header == "HG10UN": |
|
349 self.ui.note(_("using no compression\n")) |
|
350 z = nocompress() |
|
351 break |
|
352 elif header == "": |
|
353 self.ui.note(_("old server without compression support," |
|
354 " sending uncompressed\n")) |
|
355 z = nocompress() |
|
356 break |
|
357 unbundleversions.pop(0) |
|
358 if not unbundleversions: |
|
359 raise util.Abort(_("The server doesn't accept any bundle format" |
|
360 " method we know.")) |
|
361 |
|
362 fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-') |
|
363 fp = os.fdopen(fd, 'wb+') |
|
364 try: |
|
365 fp.write(header) |
|
366 for chunk in util.filechunkiter(cg): |
|
367 fp.write(z.compress(chunk)) |
|
368 fp.write(z.flush()) |
|
369 length = fp.tell() |
|
370 try: |
341 try: |
371 rfp = self.do_cmd( |
342 rfp = self.do_cmd( |
372 'unbundle', data=fp, |
343 'unbundle', data=fp, |
373 headers={'content-length': str(length), |
344 headers={'content-length': str(length), |
374 'content-type': 'application/octet-stream'}, |
345 'content-type': 'application/octet-stream'}, |