Repository navigation
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Piped stdin comes first, and a header with the file name comes before each file when there is more than one input. -F and -P still pick the first line written.
5548e57 to
b99643e
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
| let mut reader = BufReader::new(file); | ||
| let copied = skip_to_start(&mut reader, from_line, options.pattern.as_deref()) | ||
| .and_then(|start| out.write_all(&start)) | ||
| .and_then(|()| std::io::copy(&mut reader, &mut out)); |
There was a problem hiding this comment.
a write error on stdout (ENOSPC, EPIPE) ends up reported as <file>: ... and we carry on with the next file, no?
please keep the read and write errors apart
There was a problem hiding this comment.
created a helper copy_until_read_error to handle a write error and stop. currently util-linux does not print an error and exits 0 on write error, so our implementation is more complete
| if let Err(e) = copied { | ||
| show!(USimpleError::new( | ||
| 0, | ||
| format!("{}: {}", file_os.maybe_quote(), strip_errno(&e)) |
There was a problem hiding this comment.
could you please add a MoreError variant instead of the format!()?
There was a problem hiding this comment.
good point, added the enum variant
| continue; | ||
| }; | ||
| if show_header { | ||
| out.write_all(b"::::::::::::::\n")?; |
There was a problem hiding this comment.
this is the same separator as MULTI_FILE_TOP_PROMPT, could be shared?
There was a problem hiding this comment.
moved to a top-level const
Read errors are still reported per input, including piped stdin, and the next input is shown. Add a CannotRead error and share the header rule with the pager.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
musl says "I/O error" where glibc says "Input/output error", so build the expected message from the platform's strerror.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Merging this PR will improve performance by 4.57%1 warning
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
| 0, | ||
| translate!( | ||
| "more-error-cannot-read", | ||
| "path" => "standard input", |
There was a problem hiding this comment.
could use MoreError::CannotRead here too, no?
There was a problem hiding this comment.
yes, we could. would need some refactoring to generalize the inputs to the method. i opted for Option<&OsStr> for the enum variant field, where None refers to stdin.
| if reader.read_until(b'\n', &mut scanned)? == 0 { | ||
| return Ok(scanned); | ||
| } | ||
| if String::from_utf8_lossy(&scanned[line_start..]).contains(pattern) { |
There was a problem hiding this comment.
if the pattern is never found, the whole file ends up in memory, no?
There was a problem hiding this comment.
refactored to only keep at most one line in memory.
Searching for the pattern kept every line read, so a file without a match ended up in memory. Hold one line at a time and seek back to where the search started; a FIFO can't seek, so nothing is shown. Report stdin read errors with MoreError::CannotRead like files.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
When stdout isn't a terminal, write every input unchanged, the way less does, so the output can be used as data. The start line and pattern still apply when paging.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
…ttern" This reverts commit 1f1553d. util-linux applies the start line and pattern to piped output too, and compatibility with it comes first.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
When stdout isn't a terminal,
morestill ran the pager.more f > outwrote escape codes and~filler lines,more f | wc -lhung waiting for a key, and with no terminal at all it failed withmore: Would block.It now copies the input to stdout the way util-linux does:
::::::::::::::header;-Fapplies to the first input and-Pskips to the first match, as when paging;-sand-nare ignored.Added integration tests for these cases, including
-Pon a FIFO.Part of #16940