Skip to content

Conversation

@karlmcdowall
Copy link
Contributor

@karlmcdowall karlmcdowall commented Mar 18, 2025

Fixes #7472.
Update to head app when printing all-but-last-n-lines of a file.
Code now checks if the last line of the input file is missing a terminating newline character, and if so prints an extra line in the output. This aligns with GNU-head behavior.

Also made a change to improve performance of this usecase by using an optimized iterator (memchr-iter) for searching through the input file (gives a ~25% improvement for head -n -100000 ./shakespeare.txt vs the current mainline tip).

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@karlmcdowall karlmcdowall marked this pull request as ready for review March 18, 2025 20:17
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test misc/stdbuf.log is no longer failing!
Congrats! The gnu test timeout/timeout.log is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/misc/stdbuf is no longer failing!

Fixes issue uutils#7472.
Update to head app when printing all-but-last-n-lines of a file.
Code now checks if the last line of the input file is missing a terminating
newline character, and if so prints an extra line.
This aligns with GNU-head behavior.
Also improved performance of this usecase by using an optimized iterator
(memchr-iter) for searching through the input file.
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)

@karlmcdowall karlmcdowall requested a review from sylvestre April 4, 2025 16:48
@RenjiSann RenjiSann merged commit 5936408 into uutils:main Jun 14, 2025
68 checks passed
@karlmcdowall karlmcdowall deleted the head_bug_bug_bug branch July 5, 2025 20:27
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.

head: printing all-but-last-n-lines discrepancy with GNU

3 participants