Mercurial > public > mercurial-scm > hg
diff mercurial/patch.py @ 16524:ed6a74312176 stable
patch: be more tolerant with EOLs in binary diffs (issue2870)
The only place where an trailing CR could be meaningful is in the "diff --git"
line as part of a filename, and existing code already rule out this
possibility. Extend the CR/LF filtering to the whole binary hunk.
author | Patrick Mezard <patrick@mezard.eu> |
---|---|
date | Thu, 26 Apr 2012 21:44:02 +0200 |
parents | 727068417b95 |
children | aef3d0d4631c fcb97d9a26cd |
line wrap: on
line diff
--- a/mercurial/patch.py Thu Apr 26 21:44:00 2012 +0200 +++ b/mercurial/patch.py Thu Apr 26 21:44:02 2012 +0200 @@ -1035,18 +1035,20 @@ return [self.text] def _read(self, lr): - line = lr.readline() - self.hunk.append(line) + def getline(lr, hunk): + l = lr.readline() + hunk.append(l) + return l.rstrip('\r\n') + + line = getline(lr, self.hunk) while line and not line.startswith('literal '): - line = lr.readline() - self.hunk.append(line) + line = getline(lr, self.hunk) if not line: raise PatchError(_('could not extract "%s" binary data') % self._fname) size = int(line[8:].rstrip()) dec = [] - line = lr.readline() - self.hunk.append(line) + line = getline(lr, self.hunk) while len(line) > 1: l = line[0] if l <= 'Z' and l >= 'A': @@ -1054,12 +1056,11 @@ else: l = ord(l) - ord('a') + 27 try: - dec.append(base85.b85decode(line[1:-1])[:l]) + dec.append(base85.b85decode(line[1:])[:l]) except ValueError, e: raise PatchError(_('could not decode "%s" binary patch: %s') % (self._fname, str(e))) - line = lr.readline() - self.hunk.append(line) + line = getline(lr, self.hunk) text = zlib.decompress(''.join(dec)) if len(text) != size: raise PatchError(_('"%s" length is %d bytes, should be %d') @@ -1213,7 +1214,7 @@ yield 'file', (afile, bfile, h, gp and gp.copy() or None) yield 'hunk', h elif x.startswith('diff --git'): - m = gitre.match(x) + m = gitre.match(x.rstrip(' \r\n')) if not m: continue if gitpatches is None: