Show More
@@ -190,14 +190,18 def readgitpatch(patchname): | |||||
190 | def dogitpatch(patchname, gitpatches, cwd=None): |
|
190 | def dogitpatch(patchname, gitpatches, cwd=None): | |
191 | """Preprocess git patch so that vanilla patch can handle it""" |
|
191 | """Preprocess git patch so that vanilla patch can handle it""" | |
192 | def extractbin(fp): |
|
192 | def extractbin(fp): | |
193 | line = fp.readline().rstrip() |
|
193 | i = [0] # yuck | |
|
194 | def readline(): | |||
|
195 | i[0] += 1 | |||
|
196 | return fp.readline().rstrip() | |||
|
197 | line = readline() | |||
194 | while line and not line.startswith('literal '): |
|
198 | while line and not line.startswith('literal '): | |
195 |
line = |
|
199 | line = readline() | |
196 | if not line: |
|
200 | if not line: | |
197 | return |
|
201 | return None, i[0] | |
198 | size = int(line[8:]) |
|
202 | size = int(line[8:]) | |
199 | dec = [] |
|
203 | dec = [] | |
200 |
line = |
|
204 | line = readline() | |
201 | while line: |
|
205 | while line: | |
202 | l = line[0] |
|
206 | l = line[0] | |
203 | if l <= 'Z' and l >= 'A': |
|
207 | if l <= 'Z' and l >= 'A': | |
@@ -205,12 +209,12 def dogitpatch(patchname, gitpatches, cw | |||||
205 | else: |
|
209 | else: | |
206 | l = ord(l) - ord('a') + 27 |
|
210 | l = ord(l) - ord('a') + 27 | |
207 | dec.append(base85.b85decode(line[1:])[:l]) |
|
211 | dec.append(base85.b85decode(line[1:])[:l]) | |
208 |
line = |
|
212 | line = readline() | |
209 | text = zlib.decompress(''.join(dec)) |
|
213 | text = zlib.decompress(''.join(dec)) | |
210 | if len(text) != size: |
|
214 | if len(text) != size: | |
211 | raise util.Abort(_('binary patch is %d bytes, not %d') % |
|
215 | raise util.Abort(_('binary patch is %d bytes, not %d') % | |
212 | (len(text), size)) |
|
216 | (len(text), size)) | |
213 | return text |
|
217 | return text, i[0] | |
214 |
|
218 | |||
215 | pf = file(patchname) |
|
219 | pf = file(patchname) | |
216 | pfline = 1 |
|
220 | pfline = 1 | |
@@ -230,9 +234,10 def dogitpatch(patchname, gitpatches, cw | |||||
230 | pfline += 1 |
|
234 | pfline += 1 | |
231 |
|
235 | |||
232 | if p.binary: |
|
236 | if p.binary: | |
233 | text = extractbin(pf) |
|
237 | text, delta = extractbin(pf) | |
234 | if not text: |
|
238 | if not text: | |
235 | raise util.Abort(_('binary patch extraction failed')) |
|
239 | raise util.Abort(_('binary patch extraction failed')) | |
|
240 | pfline += delta | |||
236 | if not cwd: |
|
241 | if not cwd: | |
237 | cwd = os.getcwd() |
|
242 | cwd = os.getcwd() | |
238 | absdst = os.path.join(cwd, p.path) |
|
243 | absdst = os.path.join(cwd, p.path) |
@@ -162,3 +162,22 rename to foo2 | |||||
162 | EOF |
|
162 | EOF | |
163 | cat foo2 |
|
163 | cat foo2 | |
164 | hg manifest | grep binary |
|
164 | hg manifest | grep binary | |
|
165 | ||||
|
166 | echo % many binary files | |||
|
167 | hg import -m multibinary - <<EOF | |||
|
168 | diff --git a/mbinary1 b/mbinary1 | |||
|
169 | new file mode 100644 | |||
|
170 | index 0000000000000000000000000000000000000000..593f4708db84ac8fd0f5cc47c634f38c013fe9e4 | |||
|
171 | GIT binary patch | |||
|
172 | literal 4 | |||
|
173 | Lc\${NkU|;|M00aO5 | |||
|
174 | ||||
|
175 | diff --git a/mbinary2 b/mbinary2 | |||
|
176 | new file mode 100644 | |||
|
177 | index 0000000000000000000000000000000000000000..112363ac1917b417ffbd7f376ca786a1e5fa7490 | |||
|
178 | GIT binary patch | |||
|
179 | literal 5 | |||
|
180 | Mc\${NkU|\`?^000jF3jhEB | |||
|
181 | ||||
|
182 | EOF | |||
|
183 | hg manifest | grep mbinary |
@@ -58,3 +58,7 a | |||||
58 | applying patch from stdin |
|
58 | applying patch from stdin | |
59 | foo |
|
59 | foo | |
60 | 045c85ba38952325e126c70962cc0f9d9077bc67 644 binary |
|
60 | 045c85ba38952325e126c70962cc0f9d9077bc67 644 binary | |
|
61 | % many binary files | |||
|
62 | applying patch from stdin | |||
|
63 | 045c85ba38952325e126c70962cc0f9d9077bc67 644 mbinary1 | |||
|
64 | a874b471193996e7cb034bb301cac7bdaf3e3f46 644 mbinary2 |
General Comments 0
You need to be logged in to leave comments.
Login now