Show More
@@ -13,7 +13,7 b' were part of the actual repository.' | |||||
13 |
|
13 | |||
14 | from node import nullid |
|
14 | from node import nullid | |
15 | from i18n import _ |
|
15 | from i18n import _ | |
16 |
import os, struct, |
|
16 | import os, struct, tempfile, shutil | |
17 | import changegroup, util, mdiff |
|
17 | import changegroup, util, mdiff | |
18 | import localrepo, changelog, manifest, filelog, revlog, error |
|
18 | import localrepo, changelog, manifest, filelog, revlog, error | |
19 |
|
19 | |||
@@ -172,43 +172,27 b' class bundlerepository(localrepo.localre' | |||||
172 |
|
172 | |||
173 | self.tempfile = None |
|
173 | self.tempfile = None | |
174 | self.bundlefile = open(bundlename, "rb") |
|
174 | self.bundlefile = open(bundlename, "rb") | |
175 |
|
|
175 | b = changegroup.readbundle(self.bundlefile, bundlename) | |
176 | if not header.startswith("HG"): |
|
176 | if b.compressed(): | |
177 | raise util.Abort(_("%s: not a Mercurial bundle file") % bundlename) |
|
|||
178 | elif not header.startswith("HG10"): |
|
|||
179 | raise util.Abort(_("%s: unknown bundle version") % bundlename) |
|
|||
180 | elif (header == "HG10BZ") or (header == "HG10GZ"): |
|
|||
181 | fdtemp, temp = tempfile.mkstemp(prefix="hg-bundle-", |
|
177 | fdtemp, temp = tempfile.mkstemp(prefix="hg-bundle-", | |
182 | suffix=".hg10un", dir=self.path) |
|
178 | suffix=".hg10un", dir=self.path) | |
183 | self.tempfile = temp |
|
179 | self.tempfile = temp | |
184 | fptemp = os.fdopen(fdtemp, 'wb') |
|
180 | fptemp = os.fdopen(fdtemp, 'wb') | |
185 | def generator(f): |
|
|||
186 | if header == "HG10BZ": |
|
|||
187 | zd = bz2.BZ2Decompressor() |
|
|||
188 | zd.decompress("BZ") |
|
|||
189 | elif header == "HG10GZ": |
|
|||
190 | zd = zlib.decompressobj() |
|
|||
191 | for chunk in f: |
|
|||
192 | yield zd.decompress(chunk) |
|
|||
193 | gen = generator(util.filechunkiter(self.bundlefile, 4096)) |
|
|||
194 |
|
181 | |||
195 | try: |
|
182 | try: | |
196 | fptemp.write("HG10UN") |
|
183 | fptemp.write("HG10UN") | |
197 |
|
|
184 | while 1: | |
|
185 | chunk = b.read(2**18) | |||
|
186 | if not chunk: | |||
|
187 | break | |||
198 | fptemp.write(chunk) |
|
188 | fptemp.write(chunk) | |
199 | finally: |
|
189 | finally: | |
200 | fptemp.close() |
|
190 | fptemp.close() | |
201 | self.bundlefile.close() |
|
191 | self.bundlefile.close() | |
202 |
|
192 | |||
203 | self.bundlefile = open(self.tempfile, "rb") |
|
193 | self.bundlefile = open(self.tempfile, "rb") | |
204 | # seek right after the header |
|
|||
205 | self.bundlefile.seek(6) |
|
194 | self.bundlefile.seek(6) | |
206 | elif header == "HG10UN": |
|
195 | ||
207 | # nothing to do |
|
|||
208 | pass |
|
|||
209 | else: |
|
|||
210 | raise util.Abort(_("%s: unknown bundle compression type") |
|
|||
211 | % bundlename) |
|
|||
212 | # dict with the mapping 'filename' -> position in the bundle |
|
196 | # dict with the mapping 'filename' -> position in the bundle | |
213 | self.bundlefilespos = {} |
|
197 | self.bundlefilespos = {} | |
214 |
|
198 |
@@ -141,6 +141,9 b' def decompressor(fh, alg):' | |||||
141 | class unbundle10(object): |
|
141 | class unbundle10(object): | |
142 | def __init__(self, fh, alg): |
|
142 | def __init__(self, fh, alg): | |
143 | self._stream = util.chunkbuffer(decompressor(fh, alg)) |
|
143 | self._stream = util.chunkbuffer(decompressor(fh, alg)) | |
|
144 | self._type = alg | |||
|
145 | def compressed(self): | |||
|
146 | return self._type != 'UN' | |||
144 | def read(self, l): |
|
147 | def read(self, l): | |
145 | return self._stream.read(l) |
|
148 | return self._stream.read(l) | |
146 |
|
149 |
@@ -87,7 +87,7 b' test garbage file' | |||||
87 | $ hg init tgarbage |
|
87 | $ hg init tgarbage | |
88 | $ cd tgarbage |
|
88 | $ cd tgarbage | |
89 | $ hg pull ../bgarbage |
|
89 | $ hg pull ../bgarbage | |
90 |
abort: ../bgarbage: not a Mercurial bundle |
|
90 | abort: ../bgarbage: not a Mercurial bundle | |
91 | $ cd .. |
|
91 | $ cd .. | |
92 |
|
92 | |||
93 | test invalid bundle type |
|
93 | test invalid bundle type |
General Comments 0
You need to be logged in to leave comments.
Login now