Support F (output filename) command - #528
Conversation
This also requires storing input_name as PathBuf to avoid lossy conversions when outputting an OS-specific byte sequence representing the file name.
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds support for sed’s non-POSIX F command (print current input filename), including switching runtime tracking of the current input name to PathBuf to avoid lossy string conversions.
Changes:
- Implement
Fcommand execution in the sed processor by writing the current input filename bytes + newline. - Change
ProcessingContext.input_namefrom a quotedStringto aPathBuf, and update error formatting accordingly. - Add/extend tests and fixtures to cover filename output for files, stdin (
-), non-ASCII filenames, and--posixrejection.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/fixtures/sed/output/filename_file | Adds expected output fixture for running F over input/lines1. |
| tests/by-util/test_sed.rs | Adds test cases for F (file, non-ASCII filename, stdin, and --posix). |
| src/sed/processor.rs | Implements F command behavior; updates file iteration so PathBuf can be moved into context. |
| src/sed/mod.rs | Initializes input_name as PathBuf (- for stdin). |
| src/sed/error_handling.rs | Updates runtime error formatting to quote PathBuf input names. |
| src/sed/compiler.rs | Allows F only in non-POSIX mode. |
| src/sed/command.rs | Changes ProcessingContext.input_name type to PathBuf. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/sed/processor.rs:744
- This allocates a new
Vec<u8>for everyFexecution (per input line), which can be expensive on large inputs. Consider avoiding allocation by writing the filename bytes and the trailing newline as separate writes (or via an API that appends a newline without cloning), while keeping the non-lossyas_encoded_bytes()behavior.
'F' => {
// Output current input file name.
let mut bytes = context.input_name.as_os_str().as_encoded_bytes().to_vec();
bytes.push(b'\n');
output.write_bytes(&bytes)?;
}
src/sed/mod.rs:251
- Switching the default stdin name from
\"<stdin>\"to\"-\"is a visible behavior change beyond the newFcommand. Sincecontext.input_nameis also used in runtime error messages (now via.quote()), diagnostics for stdin will change accordingly. If onlyFshould emit-while diagnostics should remain\"<stdin>\", consider keeping a separate display string for errors vs. the rawPathBufused forFoutput.
input_name: PathBuf::from("-"),
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #528 +/- ##
==========================================
- Coverage 83.27% 83.18% -0.09%
==========================================
Files 13 13
Lines 6994 7001 +7
Branches 397 398 +1
==========================================
Hits 5824 5824
- Misses 1167 1174 +7
Partials 3 3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 6.17%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | number_fix |
1.4 s | 1.5 s | -6.17% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing dspinellis:F-command (8b4ed6d) with main (d837ddf)
This also requires storing input_name as PathBuf to avoid lossy conversions when outputting an OS-specific byte sequence representing the file name.