Show More
@@ -721,8 +721,9 b' class patchfile(object):' | |||
|
721 | 721 | if self.remove: |
|
722 | 722 | self.backend.unlink(self.fname) |
|
723 | 723 | else: |
|
724 |
|
|
|
725 |
self. |
|
|
724 | l = h.new(self.lines) | |
|
725 | self.lines[:] = l | |
|
726 | self.offset += len(l) | |
|
726 | 727 | self.dirty = True |
|
727 | 728 | return 0 |
|
728 | 729 | |
@@ -1016,9 +1017,10 b' class hunk(object):' | |||
|
1016 | 1017 | return old, oldstart, new, newstart |
|
1017 | 1018 | |
|
1018 | 1019 | class binhunk(object): |
|
1019 |
'A binary patch file. |
|
|
1020 | 'A binary patch file.' | |
|
1020 | 1021 | def __init__(self, lr, fname): |
|
1021 | 1022 | self.text = None |
|
1023 | self.delta = False | |
|
1022 | 1024 | self.hunk = ['GIT binary patch\n'] |
|
1023 | 1025 | self._fname = fname |
|
1024 | 1026 | self._read(lr) |
@@ -1026,7 +1028,9 b' class binhunk(object):' | |||
|
1026 | 1028 | def complete(self): |
|
1027 | 1029 | return self.text is not None |
|
1028 | 1030 | |
|
1029 | def new(self): | |
|
1031 | def new(self, lines): | |
|
1032 | if self.delta: | |
|
1033 | return [applybindelta(self.text, ''.join(lines))] | |
|
1030 | 1034 | return [self.text] |
|
1031 | 1035 | |
|
1032 | 1036 | def _read(self, lr): |
@@ -1035,14 +1039,19 b' class binhunk(object):' | |||
|
1035 | 1039 | hunk.append(l) |
|
1036 | 1040 | return l.rstrip('\r\n') |
|
1037 | 1041 | |
|
1042 | size = 0 | |
|
1038 | 1043 | while True: |
|
1039 | 1044 | line = getline(lr, self.hunk) |
|
1040 | 1045 | if not line: |
|
1041 | 1046 | raise PatchError(_('could not extract "%s" binary data') |
|
1042 | 1047 | % self._fname) |
|
1043 | 1048 | if line.startswith('literal '): |
|
1049 | size = int(line[8:].rstrip()) | |
|
1044 | 1050 | break |
|
1045 | size = int(line[8:].rstrip()) | |
|
1051 | if line.startswith('delta '): | |
|
1052 | size = int(line[6:].rstrip()) | |
|
1053 | self.delta = True | |
|
1054 | break | |
|
1046 | 1055 | dec = [] |
|
1047 | 1056 | line = getline(lr, self.hunk) |
|
1048 | 1057 | while len(line) > 1: |
@@ -1265,6 +1274,62 b' def iterhunks(fp):' | |||
|
1265 | 1274 | gp = gitpatches.pop() |
|
1266 | 1275 | yield 'file', ('a/' + gp.path, 'b/' + gp.path, None, gp.copy()) |
|
1267 | 1276 | |
|
1277 | def applybindelta(binchunk, data): | |
|
1278 | """Apply a binary delta hunk | |
|
1279 | The algorithm used is the algorithm from git's patch-delta.c | |
|
1280 | """ | |
|
1281 | def deltahead(binchunk): | |
|
1282 | i = 0 | |
|
1283 | for c in binchunk: | |
|
1284 | i += 1 | |
|
1285 | if not (ord(c) & 0x80): | |
|
1286 | return i | |
|
1287 | return i | |
|
1288 | out = "" | |
|
1289 | s = deltahead(binchunk) | |
|
1290 | binchunk = binchunk[s:] | |
|
1291 | s = deltahead(binchunk) | |
|
1292 | binchunk = binchunk[s:] | |
|
1293 | i = 0 | |
|
1294 | while i < len(binchunk): | |
|
1295 | cmd = ord(binchunk[i]) | |
|
1296 | i += 1 | |
|
1297 | if (cmd & 0x80): | |
|
1298 | offset = 0 | |
|
1299 | size = 0 | |
|
1300 | if (cmd & 0x01): | |
|
1301 | offset = ord(binchunk[i]) | |
|
1302 | i += 1 | |
|
1303 | if (cmd & 0x02): | |
|
1304 | offset |= ord(binchunk[i]) << 8 | |
|
1305 | i += 1 | |
|
1306 | if (cmd & 0x04): | |
|
1307 | offset |= ord(binchunk[i]) << 16 | |
|
1308 | i += 1 | |
|
1309 | if (cmd & 0x08): | |
|
1310 | offset |= ord(binchunk[i]) << 24 | |
|
1311 | i += 1 | |
|
1312 | if (cmd & 0x10): | |
|
1313 | size = ord(binchunk[i]) | |
|
1314 | i += 1 | |
|
1315 | if (cmd & 0x20): | |
|
1316 | size |= ord(binchunk[i]) << 8 | |
|
1317 | i += 1 | |
|
1318 | if (cmd & 0x40): | |
|
1319 | size |= ord(binchunk[i]) << 16 | |
|
1320 | i += 1 | |
|
1321 | if size == 0: | |
|
1322 | size = 0x10000 | |
|
1323 | offset_end = offset + size | |
|
1324 | out += data[offset:offset_end] | |
|
1325 | elif cmd != 0: | |
|
1326 | offset_end = i + cmd | |
|
1327 | out += binchunk[i:offset_end] | |
|
1328 | i += cmd | |
|
1329 | else: | |
|
1330 | raise PatchError(_('unexpected delta opcode 0')) | |
|
1331 | return out | |
|
1332 | ||
|
1268 | 1333 | def applydiff(ui, fp, backend, store, strip=1, eolmode='strict'): |
|
1269 | 1334 | """Reads a patch from fp and tries to apply it. |
|
1270 | 1335 |
@@ -320,6 +320,115 b' Multiple binary files:' | |||
|
320 | 320 | 045c85ba38952325e126c70962cc0f9d9077bc67 644 mbinary1 |
|
321 | 321 | a874b471193996e7cb034bb301cac7bdaf3e3f46 644 mbinary2 |
|
322 | 322 | |
|
323 | Binary file and delta hunk: | |
|
324 | ||
|
325 | $ hg import -d "1000000 0" -m delta - <<'EOF' | |
|
326 | > diff --git a/delta b/delta | |
|
327 | > new file mode 100644 | |
|
328 | > index 0000000000000000000000000000000000000000..8c9b7831b231c2600843e303e66b521353a200b3 | |
|
329 | > GIT binary patch | |
|
330 | > literal 3749 | |
|
331 | > zcmV;W4qEYvP)<h;3K|Lk000e1NJLTq006iE002D*0ssI2kt{U(0000PbVXQnQ*UN; | |
|
332 | > zcVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBU=M@d9MRCwC#oC!>o#}>x{(W-y~UN*tK | |
|
333 | > z%A%sxiUy2Ys)0Vm#ueArYKoYqX;GuiqZpgirM6nCVoYk?YNAz3G~z;BZ~@~&OQEe4 | |
|
334 | > zmGvS5isFJI;Pd_7J+EKxyHZeu`^t4r2>F;h-+VK3{_{WoGv8dSpFDYDrA%3UX03pt | |
|
335 | > zOaVoi0*W#P6lDr1$`nwPDWE7*rhuYM0Y#YtiZTThWeO<D6i}2YpqR<%$s>bRRaI42 | |
|
336 | > zS3iFIxJ8Q=EnBv1Z7?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JGruV&1cL6VGK2?+_YQr4`+EY8;Sm$9U$uuGRN=uj3k7?O9b+R~J7t_y*K64ZnI | |
|
392 | > zM+{aE<b(v?vSmw;9zFP!aE266zHIhlmdI@^xa6o2jwdRk54a$>pcRbC29ZyG!Cfdp | |
|
393 | > zutFf`Q`vljgo!(wHf=)F#m2_MIuj;L(2ja2YsQRX+rswV{d<H`Ar;(@%aNa9VPU8Z | |
|
394 | > z;tq*`y}dm#NDJHKlV}uTIm!_vAq5E7!X-p{P=Z=Sh668>PuVS1*6e}OwOiMc;u3OQ | |
|
395 | > z@Bs)w3=lzfKoufH$SFuPG@uZ4NOnM#+=8LnQ2Q4zUd+nM+OT26;lqbN{P07dhH{jH | |
|
396 | > zManE8^dLms-Q2;1kB<*Q1a3f8kZr;xX=!Qro@`~@xN*Qj>gx;i;0Z24!~i2uLb`}v | |
|
397 | > zA?R$|wvC+m^Ups=*(4lDh*=UN8{5h(A?p#D^2N$8u4Z55!q?ZAh(iEEng9_Zi>IgO | |
|
398 | > z#~**JC8hE4@n{hO&8btT5F*?nC_%LhA3i)PDhh-pB_&1wGrDIl^*=8x3n&;akBf^- | |
|
399 | > zJd&86kq$%%907v^tgWoQdwI`|oNK%VvU~S#C<o^F?6c48?Cjj#-4P<>HFD%&|Ni~t | |
|
400 | > zKJ(|#H`$<5W+6ZkBb213rXonKZLB+X>^L}J@W6osP3piLD_5?R!`S}*{xLBzFiL4@ | |
|
401 | > zX+}l{`A%?f@T5tT%ztu60p;)be`fWC`tP@WpO=?cpf8Xuf1OSj6d3f@Ki(ovDYq%0 | |
|
402 | > z{4ZSe`kOay5@=lAT!}vFzxyemC{sXDrhuYM0Y#ZI1r%ipD9W11{w=@&xgJ}t2x;ep | |
|
403 | > P00000NkvXXu0mjfZ5|Er | |
|
404 | > | |
|
405 | > literal 0 | |
|
406 | > HcmV?d00001 | |
|
407 | > | |
|
408 | > EOF | |
|
409 | applying patch from stdin | |
|
410 | ||
|
411 | $ hg manifest --debug | grep delta | |
|
412 | 9600f98bb60ce732634d126aaa4ac1ec959c573e 644 delta | |
|
413 | ||
|
414 | $ hg import -d "1000000 0" -m delta - <<'EOF' | |
|
415 | > diff --git a/delta b/delta | |
|
416 | > index 8c9b7831b231c2600843e303e66b521353a200b3..0021dd95bc0dba53c39ce81377126d43731d68df 100644 | |
|
417 | > GIT binary patch | |
|
418 | > delta 49 | |
|
419 | > zcmZ1~yHs|=21Z8J$r~9bFdA-lVv=EEw4WT$qRf2QSa5SIOAHI6(&k4T8H|kLo4vWB | |
|
420 | > FSO9ZT4bA`n | |
|
421 | > | |
|
422 | > delta 49 | |
|
423 | > zcmV-10M7rV9i<(xumJ(}ld%Di0Xefm0vrMXpOaq%BLm9I%d>?9Tm%6Vv*HM70RcC& | |
|
424 | > HOA1;9yU-AD | |
|
425 | > | |
|
426 | > EOF | |
|
427 | applying patch from stdin | |
|
428 | ||
|
429 | $ hg manifest --debug | grep delta | |
|
430 | 56094bbea136dcf8dbd4088f6af469bde1a98b75 644 delta | |
|
431 | ||
|
323 | 432 | Filenames with spaces: |
|
324 | 433 | |
|
325 | 434 | $ sed 's,EOL$,,g' <<EOF | hg import -d "1000000 0" -m spaces - |
@@ -334,7 +443,7 b' Filenames with spaces:' | |||
|
334 | 443 | applying patch from stdin |
|
335 | 444 | |
|
336 | 445 | $ hg tip -q |
|
337 | 12:47500ce1614e | |
|
446 | 14:4b79479c9a6d | |
|
338 | 447 | |
|
339 | 448 | $ cat "foo bar" |
|
340 | 449 | foo |
@@ -357,7 +466,7 b' Copy then modify the original file:' | |||
|
357 | 466 | applying patch from stdin |
|
358 | 467 | |
|
359 | 468 | $ hg tip -q |
|
360 | 13:6757efb07ea9 | |
|
469 | 15:9cbe44af4ae9 | |
|
361 | 470 | |
|
362 | 471 | $ cat foo3 |
|
363 | 472 | foo |
@@ -392,8 +501,8 b' Move text file and patch as binary' | |||
|
392 | 501 | Invalid base85 content |
|
393 | 502 | |
|
394 | 503 | $ hg rollback |
|
395 |
repository tip rolled back to revision 1 |
|
|
396 |
working directory now based on revision |
|
|
504 | repository tip rolled back to revision 16 (undo import) | |
|
505 | working directory now based on revision 16 | |
|
397 | 506 | $ hg revert -aq |
|
398 | 507 | $ hg import -d "1000000 0" -m invalid-binary - <<"EOF" |
|
399 | 508 | > diff --git a/text2 b/binary2 |
General Comments 0
You need to be logged in to leave comments.
Login now