equal
deleted
inserted
replaced
6 This software may be used and distributed according to the terms |
6 This software may be used and distributed according to the terms |
7 of the GNU General Public License, incorporated herein by reference. |
7 of the GNU General Public License, incorporated herein by reference. |
8 """ |
8 """ |
9 from i18n import gettext as _ |
9 from i18n import gettext as _ |
10 from demandload import * |
10 from demandload import * |
11 demandload(globals(), "struct os bz2 util tempfile") |
11 demandload(globals(), "struct os bz2 zlib util tempfile") |
12 |
12 |
13 def getchunk(source): |
13 def getchunk(source): |
14 """get a chunk from a changegroup""" |
14 """get a chunk from a changegroup""" |
15 d = source.read(4) |
15 d = source.read(4) |
16 if not d: |
16 if not d: |
45 def compress(self, x): |
45 def compress(self, x): |
46 return x |
46 return x |
47 def flush(self): |
47 def flush(self): |
48 return "" |
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 """Write a bundle file and return its filename. |
58 """Write a bundle file and return its filename. |
52 |
59 |
53 Existing files will not be overwritten. |
60 Existing files will not be overwritten. |
54 If no filename is specified, a temporary file is created. |
61 If no filename is specified, a temporary file is created. |
55 bz2 compression can be turned off. |
62 bz2 compression can be turned off. |
66 else: |
73 else: |
67 fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg") |
74 fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg") |
68 fh = os.fdopen(fd, "wb") |
75 fh = os.fdopen(fd, "wb") |
69 cleanup = filename |
76 cleanup = filename |
70 |
77 |
71 if compress: |
78 fh.write(type) |
72 fh.write("HG10") |
79 z = bundletypes[type]() |
73 z = bz2.BZ2Compressor(9) |
80 |
74 else: |
|
75 fh.write("HG10UN") |
|
76 z = nocompress() |
|
77 # parse the changegroup data, otherwise we will block |
81 # parse the changegroup data, otherwise we will block |
78 # in case of sshrepo because we don't know the end of the stream |
82 # in case of sshrepo because we don't know the end of the stream |
79 |
83 |
80 # an empty chunkiter is the end of the changegroup |
84 # an empty chunkiter is the end of the changegroup |
81 empty = False |
85 empty = False |