file-search: emit "Binary file <path> matches" for binary content - #9742
Open
BackSlasher wants to merge 1 commit into
Open
file-search: emit "Binary file <path> matches" for binary content#9742BackSlasher wants to merge 1 commit into
BackSlasher wants to merge 1 commit into
Conversation
BackSlasher
force-pushed
the
file-search-binary-files
branch
from
July 2, 2026 15:48
ed9c61b to
8ed06e6
Compare
Contributor
|
I generally don't think we should follow Git's patterns in our implementation of the equivalent features, they're more like a suggestion of what we shouldn't do or should learn from. |
Contributor
Author
|
Thanks for looking |
BackSlasher
force-pushed
the
file-search-binary-files
branch
3 times, most recently
from
July 6, 2026 14:13
3bdf038 to
54711c8
Compare
BackSlasher
force-pushed
the
file-search-binary-files
branch
3 times, most recently
from
July 16, 2026 13:51
fb1bc81 to
61f6c65
Compare
6 tasks
BackSlasher
force-pushed
the
file-search-binary-files
branch
from
July 17, 2026 12:38
61f6c65 to
db10589
Compare
BackSlasher
marked this pull request as ready for review
July 17, 2026 12:42
Files with a null byte in the first 8KB are treated as binary and match output collapses to `Binary file <path> matches` instead of raw bytes, mirroring `git grep`'s default. `-a`/`--text` forces text treatment, `-I`/`--no-binary` skips binary files entirely.
BackSlasher
force-pushed
the
file-search-binary-files
branch
from
July 25, 2026 08:11
db10589 to
5cef02f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows up on #9740 (merged).
Behavior
Mirrors
git grep.A file is considered binary if any of the first 8KB is
\0.Binary file <path> matches(no per-line output).--name-onlystill prints just the path.-a/--text: bypass the check; treat all files as text and emit raw bytes for matches.-I/--no-binary: skip binary files entirely, even if they contain matches.-aand-Iare mutually exclusive (clap-enforced).The heuristic is a local inline check for now (
content.iter().take(8192).any(|b| *b == 0)).Will follow up with unifying with
jj_lib::eol::is_binaryandlib/src/diff_presentation/mod.rs:71.Conflicts: if any add-side of a conflict looks binary, the whole file is treated as binary and follows the same three modes above. Per-side awareness is left as a follow-up alongside the existing conflict-side
TODOin the code.Testing
Binary file <path> matches.--name-onlyon binary match prints just the path.-abypasses the check and emits raw bytes.-Iskips binary files entirely.-acombined with-Ierrors out (clap-enforced).Binary file <path> matches.--name-onlyon binary conflict prints just the path.-Ion binary conflict skips it entirely.Not in scope
read_alls the whole file into memory before the 8KB binary probe runs, so-Idoesn't save any I/O. A streaming reader could probe the first 8KB and short-circuit without reading the rest. Deferred to keep this PR small.is_binaryacross the codebase (eol,diff_presentation, and now this file)..gitattributesbinary/-textsupport. Depends on a wider stack of.gitattributesPRs (design: cornerstone for gitattributes features #7164, Gitattributes filter design #8144, Gitattributes EOL conversion support #8266, gitattributes filter support #8719, git-lfs: add ability to ignore files based on git attributes #9635) that haven't landed.Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,demos/)cli/src/config-schema.json)how it works, how it's organized), including any code drafted by an LLM.
an eye towards deleting anything that is irrelevant, clarifying anything
that is confusing, and adding details that are relevant. This includes,
for example, commit descriptions, PR descriptions, and code comments.