filter-repo: avoid applying --replace-text to binary files

--replace-text is meant to replace _text_ throughout the repository, not
binary data.  Use the same scheme as the lint-history script uses to
avoid applying the changes to binary blob data.

Reported-by: Tobias Gruetzmacher <tobias-git@23.gs>
Signed-off-by: Elijah Newren <newren@gmail.com>
This commit is contained in:
Elijah Newren 2020-06-06 10:23:22 -07:00
parent 859e66ae1c
commit 31f00a9ff8

View File

@ -3231,7 +3231,8 @@ class RepoFilter(object):
if blob.original_id in self._args.strip_blobs_with_ids:
blob.skip()
if self._args.replace_text:
if self._args.replace_text and \
not any(x == b"0" for x in blob.data[0:8192]):
for literal, replacement in self._args.replace_text['literals']:
blob.data = blob.data.replace(literal, replacement)
for regex, replacement in self._args.replace_text['regexes']: