diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -190,14 +190,18 @@ def readgitpatch(patchname): def dogitpatch(patchname, gitpatches, cwd=None): """Preprocess git patch so that vanilla patch can handle it""" def extractbin(fp): - line = fp.readline().rstrip() + i = [0] # yuck + def readline(): + i[0] += 1 + return fp.readline().rstrip() + line = readline() while line and not line.startswith('literal '): - line = fp.readline().rstrip() + line = readline() if not line: - return + return None, i[0] size = int(line[8:]) dec = [] - line = fp.readline().rstrip() + line = readline() while line: l = line[0] if l <= 'Z' and l >= 'A': @@ -205,12 +209,12 @@ def dogitpatch(patchname, gitpatches, cw else: l = ord(l) - ord('a') + 27 dec.append(base85.b85decode(line[1:])[:l]) - line = fp.readline().rstrip() + line = readline() text = zlib.decompress(''.join(dec)) if len(text) != size: raise util.Abort(_('binary patch is %d bytes, not %d') % (len(text), size)) - return text + return text, i[0] pf = file(patchname) pfline = 1 @@ -230,9 +234,10 @@ def dogitpatch(patchname, gitpatches, cw pfline += 1 if p.binary: - text = extractbin(pf) + text, delta = extractbin(pf) if not text: raise util.Abort(_('binary patch extraction failed')) + pfline += delta if not cwd: cwd = os.getcwd() absdst = os.path.join(cwd, p.path) diff --git a/tests/test-git-import b/tests/test-git-import --- a/tests/test-git-import +++ b/tests/test-git-import @@ -162,3 +162,22 @@ rename to foo2 EOF cat foo2 hg manifest | grep binary + +echo % many binary files +hg import -m multibinary - <<EOF +diff --git a/mbinary1 b/mbinary1 +new file mode 100644 +index 0000000000000000000000000000000000000000..593f4708db84ac8fd0f5cc47c634f38c013fe9e4 +GIT binary patch +literal 4 +Lc\${NkU|;|M00aO5 + +diff --git a/mbinary2 b/mbinary2 +new file mode 100644 +index 0000000000000000000000000000000000000000..112363ac1917b417ffbd7f376ca786a1e5fa7490 +GIT binary patch +literal 5 +Mc\${NkU|\`?^000jF3jhEB + +EOF +hg manifest | grep mbinary diff --git a/tests/test-git-import.out b/tests/test-git-import.out --- a/tests/test-git-import.out +++ b/tests/test-git-import.out @@ -58,3 +58,7 @@ a applying patch from stdin foo 045c85ba38952325e126c70962cc0f9d9077bc67 644 binary +% many binary files +applying patch from stdin +045c85ba38952325e126c70962cc0f9d9077bc67 644 mbinary1 +a874b471193996e7cb034bb301cac7bdaf3e3f46 644 mbinary2