From 97a1613f81c914900c27d7e22a9bb206e65b0f3d Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 29 Mar 2021 23:19:16 -0700 Subject: [PATCH] lint-history: fix binary blob detection We had a lingering issue in the conversion from python2 to python3; as reported by @thebrandre on GitHub: any(x==b'1' for x in b"123") # returns True in Python2 and False in Python3 because different # types are returned on iteration: [type(x) for x in b"123"] # Python2: [, , ] # Python3: [, , ] Replace the any(x==b"0" for x in blob.data[0:8192]) construct with b"\0" in blob.data[0:8192] to fix this. Suggested-by: @thebrandre on GitHub Signed-off-by: Elijah Newren --- contrib/filter-repo-demos/lint-history | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/filter-repo-demos/lint-history b/contrib/filter-repo-demos/lint-history index 4ec34ed..2f8d3e5 100755 --- a/contrib/filter-repo-demos/lint-history +++ b/contrib/filter-repo-demos/lint-history @@ -30,7 +30,7 @@ near the top of git-filter-repo. # Technically, if you are only running on all non-binary files and don't care # about filenames, then this program could be replaced by a "one-liner"; e.g. # git filter-repo --force --blob-callback ' -# if not any(x == b"0" for x in blob.data[0:8192]): +# if not b"\0" in blob.data[0:8192]: # filename = '.git/info/tmpfile' # with open(filename, "wb") as f: # f.write(blob.data) @@ -129,7 +129,7 @@ def lint_with_real_filenames(commit, metadata): change.blob_id = blob.id def lint_non_binary_blobs(blob, metadata): - if not any(x == b"0" for x in blob.data[0:8192]): + if not b"\0" in blob.data[0:8192]: filename = '.git/info/tmpfile' with open(filename, "wb") as f: f.write(blob.data)