comparison mercurial/patch.py @ 16522:a8065323c003 stable

patch: display a nice error for invalid base85 data Before, import was terminating with a traceback. Now it says: $ hg import --no-commit ../bad.patch applying ../bad.patch abort: could not decode binary patch: bad base85 character at position 66
author Patrick Mezard <patrick@mezard.eu>
date Sat, 21 Apr 2012 19:58:18 +0200
parents fc4e0fecf403
children 727068417b95
comparison
equal deleted inserted replaced
16521:592701c8eac6 16522:a8065323c003
1049 l = line[0] 1049 l = line[0]
1050 if l <= 'Z' and l >= 'A': 1050 if l <= 'Z' and l >= 'A':
1051 l = ord(l) - ord('A') + 1 1051 l = ord(l) - ord('A') + 1
1052 else: 1052 else:
1053 l = ord(l) - ord('a') + 27 1053 l = ord(l) - ord('a') + 27
1054 dec.append(base85.b85decode(line[1:-1])[:l]) 1054 try:
1055 dec.append(base85.b85decode(line[1:-1])[:l])
1056 except ValueError, e:
1057 raise PatchError(_('could not decode binary patch: %s')
1058 % str(e))
1055 line = lr.readline() 1059 line = lr.readline()
1056 self.hunk.append(line) 1060 self.hunk.append(line)
1057 text = zlib.decompress(''.join(dec)) 1061 text = zlib.decompress(''.join(dec))
1058 if len(text) != size: 1062 if len(text) != size:
1059 raise PatchError(_('binary patch is %d bytes, not %d') % 1063 raise PatchError(_('binary patch is %d bytes, not %d') %