Skip to content

Commit b8ebda9

Browse files
committed
contrib: avoid applying --replace-text to binary files in bfg-ish
Signed-off-by: Elijah Newren <[email protected]>
1 parent 86569ee commit b8ebda9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

contrib/filter-repo-demos/bfg-ish

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,11 @@ class BFG_ish:
248248
# FIXME: This next line assumes the file fits in memory; though the way
249249
# fr.Blob works we kind of have that assumption baked in elsewhere too...
250250
contents = self.cat_file_proc.stdout.read(int(objsize))
251-
for literal, replacement in self.replacement_rules['literals']:
252-
contents = contents.replace(literal, replacement)
253-
for regex, replacement in self.replacement_rules['regexes']:
254-
contents = regex.sub(replacement, contents)
251+
if not any(x == b"0" for x in contents[0:8192]): # not binaries
252+
for literal, replacement in self.replacement_rules['literals']:
253+
contents = contents.replace(literal, replacement)
254+
for regex, replacement in self.replacement_rules['regexes']:
255+
contents = regex.sub(replacement, contents)
255256
self.cat_file_proc.stdout.read(1) # Read trailing newline
256257

257258
blob = fr.Blob(contents)

0 commit comments

Comments
 (0)