Skip to content

file-search: emit "Binary file <path> matches" for binary content - #9742

Open
BackSlasher wants to merge 1 commit into
jj-vcs:mainfrom
BackSlasher:file-search-binary-files
Open

file-search: emit "Binary file <path> matches" for binary content#9742
BackSlasher wants to merge 1 commit into
jj-vcs:mainfrom
BackSlasher:file-search-binary-files

Conversation

@BackSlasher

@BackSlasher BackSlasher commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Follows up on #9740 (merged).

Behavior

Mirrors git grep.

A file is considered binary if any of the first 8KB is \0.

  • Default: match on a binary file emits Binary file <path> matches (no per-line output). --name-only still 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.

-a and -I are 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_binary and lib/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 TODO in the code.

Testing

  • Match on binary file emits Binary file <path> matches.
  • --name-only on binary match prints just the path.
  • No output when the pattern doesn't match, even on binary.
  • -a bypasses the check and emits raw bytes.
  • -I skips binary files entirely.
  • -a combined with -I errors out (clap-enforced).
  • Binary conflict (any add-side has a null byte) emits Binary file <path> matches.
  • --name-only on binary conflict prints just the path.
  • -I on binary conflict skips it entirely.

Not in scope

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added/updated tests to cover my changes
  • I fully understand the code that I am submitting (what it does,
    how it works, how it's organized), including any code drafted by an LLM.
  • For any prose generated by an LLM, I have proof-read and copy-edited with
    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.

@BackSlasher
BackSlasher force-pushed the file-search-binary-files branch from ed9c61b to 8ed06e6 Compare July 2, 2026 15:48
@PhilipMetzger

Copy link
Copy Markdown
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.

@BackSlasher

Copy link
Copy Markdown
Contributor Author

Thanks for looking
Figured copying from git is a good start as mentioned in #8318. If there's a strong preference for other behavior, happy to adapt

@BackSlasher
BackSlasher force-pushed the file-search-binary-files branch 3 times, most recently from 3bdf038 to 54711c8 Compare July 6, 2026 14:13
@BackSlasher
BackSlasher force-pushed the file-search-binary-files branch 3 times, most recently from fb1bc81 to 61f6c65 Compare July 16, 2026 13:51
@BackSlasher
BackSlasher force-pushed the file-search-binary-files branch from 61f6c65 to db10589 Compare July 17, 2026 12:38
@BackSlasher
BackSlasher marked this pull request as ready for review July 17, 2026 12:42
@BackSlasher
BackSlasher requested a review from a team as a code owner 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
BackSlasher force-pushed the file-search-binary-files branch from db10589 to 5cef02f Compare July 25, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants