Show More
@@ -8,7 +8,7 b' of the GNU General Public License, incor' | |||
|
8 | 8 | """ |
|
9 | 9 | from i18n import gettext as _ |
|
10 | 10 | from demandload import * |
|
11 | demandload(globals(), "struct os bz2 util tempfile") | |
|
11 | demandload(globals(), "struct os bz2 zlib util tempfile") | |
|
12 | 12 | |
|
13 | 13 | def getchunk(source): |
|
14 | 14 | """get a chunk from a changegroup""" |
@@ -47,7 +47,14 b' class nocompress(object):' | |||
|
47 | 47 | def flush(self): |
|
48 | 48 | return "" |
|
49 | 49 | |
|
50 | def writebundle(cg, filename, compress): | |
|
50 | bundletypes = { | |
|
51 | "": nocompress, | |
|
52 | "HG10UN": nocompress, | |
|
53 | "HG10": lambda: bz2.BZ2Compressor(9), | |
|
54 | "HG10GZ": zlib.compressobj, | |
|
55 | } | |
|
56 | ||
|
57 | def writebundle(cg, filename, type): | |
|
51 | 58 | """Write a bundle file and return its filename. |
|
52 | 59 | |
|
53 | 60 | Existing files will not be overwritten. |
@@ -68,12 +75,9 b' def writebundle(cg, filename, compress):' | |||
|
68 | 75 | fh = os.fdopen(fd, "wb") |
|
69 | 76 | cleanup = filename |
|
70 | 77 | |
|
71 | if compress: | |
|
72 | fh.write("HG10") | |
|
73 | z = bz2.BZ2Compressor(9) | |
|
74 | else: | |
|
75 | fh.write("HG10UN") | |
|
76 | z = nocompress() | |
|
78 | fh.write(type) | |
|
79 | z = bundletypes[type]() | |
|
80 | ||
|
77 | 81 | # parse the changegroup data, otherwise we will block |
|
78 | 82 | # in case of sshrepo because we don't know the end of the stream |
|
79 | 83 |
@@ -332,7 +332,7 b' def bundle(ui, repo, fname, dest=None, *' | |||
|
332 | 332 | cg = repo.changegroupsubset(o, revs, 'bundle') |
|
333 | 333 | else: |
|
334 | 334 | cg = repo.changegroup(o, 'bundle') |
|
335 |
changegroup.writebundle(cg, fname, |
|
|
335 | changegroup.writebundle(cg, fname, "HG10") | |
|
336 | 336 | |
|
337 | 337 | def cat(ui, repo, file1, *pats, **opts): |
|
338 | 338 | """output the latest or given revisions of files |
@@ -1292,7 +1292,8 b' def incoming(ui, repo, source="default",' | |||
|
1292 | 1292 | if fname or not other.local(): |
|
1293 | 1293 | # create a bundle (uncompressed if other repo is not local) |
|
1294 | 1294 | cg = other.changegroup(incoming, "incoming") |
|
1295 | fname = cleanup = changegroup.writebundle(cg, fname, other.local()) | |
|
1295 | type = other.local() and "HG10" or "HG10UN" | |
|
1296 | fname = cleanup = changegroup.writebundle(cg, fname, type) | |
|
1296 | 1297 | # keep written bundle? |
|
1297 | 1298 | if opts["bundle"]: |
|
1298 | 1299 | cleanup = None |
@@ -11,7 +11,7 b' from remoterepo import *' | |||
|
11 | 11 | from i18n import gettext as _ |
|
12 | 12 | from demandload import * |
|
13 | 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 | 16 | class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm): |
|
17 | 17 | def __init__(self, ui): |
@@ -326,47 +326,18 b' class httprepository(remoterepository):' | |||
|
326 | 326 | # have to stream bundle to a temp file because we do not have |
|
327 | 327 | # http 1.1 chunked transfer. |
|
328 | 328 | |
|
329 | # XXX duplication from commands.py | |
|
330 | class nocompress(object): | |
|
331 | def compress(self, x): | |
|
332 | return x | |
|
333 | def flush(self): | |
|
334 |
|
|
|
335 | ||
|
336 | unbundleversions = self.capable('unbundle') | |
|
337 | try: | |
|
338 | unbundleversions = unbundleversions.split(',') | |
|
339 | except AttributeError: | |
|
340 | unbundleversions = [""] | |
|
329 | type = "" | |
|
330 | types = self.capable('unbundle') | |
|
331 | if types: | |
|
332 | for x in types.split(','): | |
|
333 | if x in changegroup.bundletypes: | |
|
334 | type = x | |
|
335 | break | |
|
341 | 336 | |
|
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+') | |
|
337 | tempname = changegroup.writebundle(cg, None, type) | |
|
338 | fp = file(tempname, "rb") | |
|
364 | 339 | 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() | |
|
340 | length = os.stat(tempname).st_size | |
|
370 | 341 | try: |
|
371 | 342 | rfp = self.do_cmd( |
|
372 | 343 | 'unbundle', data=fp, |
General Comments 0
You need to be logged in to leave comments.
Login now