Skip to content

File search: can print lines and line numbers - #9740

Merged
BackSlasher merged 2 commits into
jj-vcs:mainfrom
BackSlasher:file-search-print-lines
Jul 17, 2026
Merged

File search: can print lines and line numbers#9740
BackSlasher merged 2 commits into
jj-vcs:mainfrom
BackSlasher:file-search-print-lines

Conversation

@BackSlasher

@BackSlasher BackSlasher commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Closes #9399

Two commits:

  1. print matched lines, unless --name-only
  2. print line numbers if -n

As specced in #9399 by @martinvonz

Testing

  • Existing snapshots updated to reflect the new path:line default output.
  • --name-only restores path-only output.
  • -n / --line-number prefixes matches with 1-based line numbers.
  • --name-only combined with -n errors out (clap-enforced).
  • Multi-match files emit one line per match; --name-only collapses to one line per file.
  • Conflict files: --name-only deduplicates across matching add-sides.
  • Conflict files: -n numbers lines within each side independently.

Known issue: Binary files

Because we now emit matched-line contents (not just paths), a search that happens to match bytes in a binary file will dump raw bytes, potentially including terminal control codes, to stdout.

Addressed in the follow-up PR #9742 (mirrors git grep: Binary file <path> matches by default, -a/--text and -I/--no-binary overrides).

Not in scope

  • Templated output (--template): the bigger stretch goal on FR: Allow seeing the matched lines for file search command #9399.
  • Labelling which conflict side a match came from: existing TODO in the code.
  • Streaming the file reader: plain-file path currently uses read_all, which will inflate process memory on big files. Can be moved to streaming but wanted to keep this PR small.
  • Concurrent file reads: existing TODO in the code.

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 marked this pull request as ready for review July 2, 2026 14:43
@BackSlasher
BackSlasher requested a review from a team as a code owner July 2, 2026 14:43
@BackSlasher
BackSlasher force-pushed the file-search-print-lines branch from 9077ac3 to 7060002 Compare July 2, 2026 15:48
Comment thread cli/tests/test_file_search_command.rs
Comment thread cli/src/commands/file/search.rs Outdated
Comment thread cli/src/commands/file/search.rs Outdated
Comment thread cli/src/commands/file/search.rs Outdated
Comment thread cli/tests/test_file_search_command.rs Outdated
Comment thread cli/tests/test_file_search_command.rs Outdated
Comment thread cli/src/commands/file/search.rs Outdated
@BackSlasher
BackSlasher force-pushed the file-search-print-lines branch 3 times, most recently from 82571c9 to 10f9a34 Compare July 6, 2026 14:13
@BackSlasher
BackSlasher force-pushed the file-search-print-lines branch from 10f9a34 to 9e5f02a Compare July 14, 2026 15:53
@BackSlasher

Copy link
Copy Markdown
Contributor Author

Rebased because drifted from main. Anything I can do to help this land?

Comment thread cli/src/commands/file/search.rs Outdated
Comment thread cli/src/commands/file/search.rs Outdated
Default output changes from `<path>` to `<path>:<matched line>`, one
per match, matching `git grep`'s default. `-l`/`--files-with-matches`
restores path-only output.
Prefixes each match with its 1-based line number, matching `git grep -n`.
Mutually exclusive with `-l` (clap-enforced).
@BackSlasher
BackSlasher force-pushed the file-search-print-lines branch from 9e5f02a to 9bf647d Compare July 16, 2026 13:39
@BackSlasher
BackSlasher added this pull request to the merge queue Jul 17, 2026
Merged via the queue into jj-vcs:main with commit 9e297fa Jul 17, 2026
38 checks passed
@BackSlasher
BackSlasher deleted the file-search-print-lines branch July 17, 2026 09:31
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.

FR: Allow seeing the matched lines for file search command

4 participants