diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1022,9 +1022,10 @@ class hunk(object): class binhunk(object): 'A binary patch file. Only understands literals so far.' - def __init__(self, lr): + def __init__(self, lr, fname): self.text = None self.hunk = ['GIT binary patch\n'] + self._fname = fname self._read(lr) def complete(self): @@ -1040,7 +1041,8 @@ class binhunk(object): line = lr.readline() self.hunk.append(line) if not line: - raise PatchError(_('could not extract binary patch')) + raise PatchError(_('could not extract "%s" binary data') + % self._fname) size = int(line[8:].rstrip()) dec = [] line = lr.readline() @@ -1054,14 +1056,14 @@ class binhunk(object): try: dec.append(base85.b85decode(line[1:-1])[:l]) except ValueError, e: - raise PatchError(_('could not decode binary patch: %s') - % str(e)) + raise PatchError(_('could not decode "%s" binary patch: %s') + % (self._fname, str(e))) line = lr.readline() self.hunk.append(line) text = zlib.decompress(''.join(dec)) if len(text) != size: - raise PatchError(_('binary patch is %d bytes, not %d') % - len(text), size) + raise PatchError(_('"%s" length is %d bytes, should be %d') + % (self._fname, len(text), size)) self.text = text def parsefilename(str): @@ -1200,7 +1202,7 @@ def iterhunks(fp): gitpatches[-1].ispatching(afile, bfile)): gp = gitpatches.pop() if x.startswith('GIT binary patch'): - h = binhunk(lr) + h = binhunk(lr, gp.path) else: if context is None and x.startswith('***************'): context = True diff --git a/tests/test-import-git.t b/tests/test-import-git.t --- a/tests/test-import-git.t +++ b/tests/test-import-git.t @@ -364,6 +364,7 @@ Move text file and patch as binary R text2 Invalid base85 content + $ hg rollback repository tip rolled back to revision 15 (undo import) working directory now based on revision 15 @@ -379,8 +380,38 @@ Invalid base85 content > > EOF applying patch from stdin - abort: could not decode binary patch: bad base85 character at position 6 + abort: could not decode "binary2" binary patch: bad base85 character at position 6 [255] + + $ hg revert -aq + $ hg import -d "1000000 0" -m rename-as-binary - <<"EOF" + > diff --git a/text2 b/binary2 + > rename from text2 + > rename to binary2 + > index 78981922613b2afb6025042ff6bd878ac1994e85..10efcb362e9f3b3420fcfbfc0e37f3dc16e29757 + > GIT binary patch + > literal 6 + > Mc$`b*O5$Pw00T?_*Z=?k + > + > EOF + applying patch from stdin + abort: "binary2" length is 5 bytes, should be 6 + [255] + + $ hg revert -aq + $ hg import -d "1000000 0" -m rename-as-binary - <<"EOF" + > diff --git a/text2 b/binary2 + > rename from text2 + > rename to binary2 + > index 78981922613b2afb6025042ff6bd878ac1994e85..10efcb362e9f3b3420fcfbfc0e37f3dc16e29757 + > GIT binary patch + > Mc$`b*O5$Pw00T?_*Z=?k + > + > EOF + applying patch from stdin + abort: could not extract "binary2" binary data + [255] + $ cd .. Consecutive import with renames (issue2459)