Handle binary data in diffs

Even though we won't usually display it, binary data may show up
in a diff.  We can't decode it to display it, so just replace it
with a placeholder string so we don't crash.

Change-Id: I4794e707745ed8315afec00c1981e239ec98ef0e
This commit is contained in:
James E. Blair 2020-02-20 09:45:34 -08:00
parent a8487746e7
commit 64b8d6dc6c
1 changed files with 4 additions and 1 deletions

View File

@ -544,7 +544,10 @@ class Repo(object):
if isinstance(line, six.string_types):
f.addContextLine(line)
else:
f.addContextLine(line.decode('utf8'))
try:
f.addContextLine(line.decode('utf8'))
except:
f.addContextLine("<binary data>")
f.finalize()
return files