Repository navigation
fix(cat,head): stream optioned cat per-line; short-read head -n on pipe/console stdin - #1289
Merged
caomengxuan666 merged 1 commit intoOct 24, 2026
Conversation
- cat: re-apply D4 short ReadFile on live stdin for optioned path; flush after each completed line so cat -n/-A/-b/... stream with a dribbling producer (was withheld until 64KiB or EOF). - head: output_first_records short-ReadFile live pipe/console stdin so head -n N emits as soon as N delimiters arrive (xsgetn filled a 64KiB request before returning). - Disk/ifstream paths keep the fill loop; head -c / all-but-last semantics unchanged.
Member
|
Following up your own #1286 with the optioned path and |
This was referenced Oct 25, 2026
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.
Summary
After #1286 fixed bare
catstreaming (shortReadFilein fast_passthrough), two related pipeline-tail shapes still withheld output until EOF on a dribbling producer:cat(-n/-A/-b/-e/-T/-v/-s): the option path already read viaistream::get(streamable), butoutwas only flushed at 64KiB or EOF — sopython lines.py | cat -nprinted nothing until the producer exited.head -n N:output_first_recordsusedistream::read(64KiB). MSVCxsgetnfills the request or EOF, sohead -n 1waited for the whole stream before emitting the first line.Shell-independent repro (python parent + this
cat.exe/head.exe, 1 line / 0.4s): both were BUFFER (~last-line time) before, STREAM (~0.03s) after; Git Bash streams the same shapes.Changes
std::cinand the handle type isFILE_TYPE_PIPE/FILE_TYPE_CHAR, use a single shortReadFileand feed the state machine; flush after each completed line (append_outputstill coalesces mid-line up to 64KiB). Diskifstreamkeeps the filled loop.output_first_recordsuses a single shortReadFileon live pipe/console stdin and returns as soon as N delimiters have been emitted (remaining bytes are discarded, matching GNUhead). File/stdin-not-pipe paths unchanged.head -cand all-but-last semantics unchanged.Pairs with the merged #1286 (bare
cat) and rubash pipeline streaming (unixwin/rubash#1445). Follow-up to niubash defect log D4; this is R2 inniubash-remaining-defects-2026-10-24.Test plan (Windows 11, WinuxCmd 1.1.20 + this patch, installed and build-tree binaries)
python lines.py | cat(D4 regression)python lines.py | cat -n/-A/-e/-b/-spython lines.py | head -n 1/-n 2python lines.py | head -c 3cat -n/-b/-A/-e,head -n 2/-c 2byte-exactyes | head -3→ PIPESTATUS 141 0niu -c 'python … | cat -n'/| head -n 1Note: default
head(10 lines) with a short producer now emits lines as they arrive and only closes at EOF — same as GNU.head -n +Nkeeps WinuxCmd's existing "first N lines" semantics (covered bytests/unit/head).cherry-picked from local
14ed026.