Skip to content

grep: rewind seekable stdin when -m stops the search early - #101

Merged
sylvestre merged 1 commit into
uutils:mainfrom
sylvestre:grep-max-count-rewind
Aug 8, 2026
Merged

grep: rewind seekable stdin when -m stops the search early#101
sylvestre merged 1 commit into
uutils:mainfrom
sylvestre:grep-max-count-rewind

Conversation

@sylvestre

Copy link
Copy Markdown
Contributor

No description provided.

@codspeed-hq

codspeed-hq Bot commented Aug 8, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 10 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing sylvestre:grep-max-count-rewind (93a8a61) with main (dc3cddf)

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

GNU grep testsuite comparison:

Test results comparison:
  Current:   TOTAL: 128 / PASSED: 76 / FAILED: 31 / SKIPPED: 21
  Reference: TOTAL: 128 / PASSED: 75 / FAILED: 32 / SKIPPED: 21

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + max-count-overread

@sylvestre

Copy link
Copy Markdown
Contributor Author

trivial, auto merge for the next release

@sylvestre
sylvestre merged commit 54a846c into uutils:main Aug 8, 2026
22 checks passed
@sylvestre
sylvestre deleted the grep-max-count-rewind branch August 8, 2026 22:46
Comment thread src/searcher.rs
Comment on lines +120 to +126
// `-m` stops mid-input, but we have read further than the last selected
// line. Rewind so whoever reads standard input next sees the rest of it,
// as GNU does. A pipe cannot seek; there is nothing to hand back then.
if !self.session_can_match()
&& let Ok(start) = start_offset
{
let _ = stdin.seek(SeekFrom::Start(start + self.session_last_match_end));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work if stdin cannot seek?

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