# HG changeset patch # User Patrick Mezard # Date 1335469440 -7200 # Node ID 727068417b955485e551c71d5dd0009d5d02e4f5 # Parent a8065323c003694874c718d2c1c35af2a3d8ecdb patch: include file name in binary patch error messages $ hg import --no-commit ../mercurial_1915035238540490516.patch applying ../mercurial_1915035238540490516.patch abort: could not extract binary data Becomes: abort: could not extract "binary2" binary data diff -r a8065323c003 -r 727068417b95 mercurial/patch.py --- a/mercurial/patch.py Sat Apr 21 19:58:18 2012 +0200 +++ b/mercurial/patch.py Thu Apr 26 21:44:00 2012 +0200 @@ -1022,9 +1022,10 @@ 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 @@ 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 @@ 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 @@ 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 -r a8065323c003 -r 727068417b95 tests/test-import-git.t --- a/tests/test-import-git.t Sat Apr 21 19:58:18 2012 +0200 +++ b/tests/test-import-git.t Thu Apr 26 21:44:00 2012 +0200 @@ -364,6 +364,7 @@ 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 @@ > > 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)