Skip to content

Support F (output filename) command - #527

Closed
dspinellis wants to merge 0 commit into
uutils:mainfrom
dspinellis:main
Closed

Support F (output filename) command#527
dspinellis wants to merge 0 commit into
uutils:mainfrom
dspinellis:main

Conversation

@dspinellis

Copy link
Copy Markdown
Collaborator

This also requires storing input_name as PathBuf to avoid lossy conversions when outputting an OS-specific byte sequence representing the file name.

Copilot AI lite review requested due to automatic review settings August 19, 2026 07:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds support for GNU sed’s F command (print current input file name), including correct handling of non-ASCII file names by storing input_name as a PathBuf and emitting OS-encoded bytes for the filename.

Changes:

  • Implement F command execution in the sed processor.
  • Store ProcessingContext.input_name as PathBuf (and adjust initialization / error formatting accordingly).
  • Add fixtures and tests for F with regular files, non-ASCII file names, stdin, and --posix rejection.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/fixtures/sed/output/filename_αρχείο1 Expected output for F with a non-ASCII input filename (interleaved with normal printing).
tests/fixtures/sed/output/filename_file Expected output for F under -n (filename printed per line).
tests/fixtures/sed/input/αρχείο1 Non-ASCII input fixture used to validate filename handling.
tests/by-util/test_sed.rs New test coverage for F (file, non-ASCII path, stdin, and --posix behavior).
src/sed/processor.rs Runtime implementation of F and PathBuf propagation for input_name.
src/sed/mod.rs Initialize input_name as PathBuf for stdin (-).
src/sed/error_handling.rs Quote PathBuf input names in runtime error messages.
src/sed/compiler.rs Allow F only when not in --posix mode.
src/sed/command.rs Update ProcessingContext.input_name type to PathBuf.
Suppressed comments (1)

src/sed/processor.rs:744

  • This builds a Vec from the path bytes and then write_bytes immediately clones again internally, causing an extra allocation/copy per input line. You can avoid the first allocation by writing the path bytes directly and then writing a newline separately.
                    let mut bytes = context.input_name.as_os_str().as_encoded_bytes().to_vec();
                    bytes.push(b'\n');
                    output.write_bytes(&bytes)?;

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/sed/processor.rs Outdated
_ => panic!("invalid 'e' command data"),
},
'F' => {
// Ouput current input file name.
Comment thread src/sed/command.rs
pub null_data: bool,

// Other context
/// Currently processed input file name (not script) in quoted form
Copilot AI review requested due to automatic review settings August 19, 2026 08:21
@dspinellis dspinellis closed this Aug 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

@codspeed-hq

codspeed-hq Bot commented Aug 19, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 6.17%

❌ 1 regressed benchmark
✅ 10 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

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:main (d4cced3) with main (d837ddf)

Open in CodSpeed

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