Repository navigation
sed: write the newline a file's last line lacks before the next file's output, as GNU sed does - #596
DePasqualeOrg wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #596 +/- ##
==========================================
+ Coverage 94.85% 94.98% +0.13%
==========================================
Files 14 14
Lines 7230 7260 +30
Branches 432 433 +1
==========================================
+ Hits 6858 6896 +38
+ Misses 371 363 -8
Partials 1 1
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 regress 1 benchmark
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ |
access_log_append |
1 s | 1.1 s | -3.11% |
| ⚡ | access_log_translit |
1,019.5 ms | 987.7 ms | +3.22% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing DePasqualeOrg:fix-separator-between-files (e6e26f1) with main (3b464d1)
f23aa4b to
f00be9e
Compare
…s output, as GNU sed does
f00be9e to
d572850
Compare
|
|
||
| /// Copy the specified file to the output, leaving any deferred newline | ||
| /// for the next output, as GNU sed does for `0r`. | ||
| pub fn copy_file_before_pending_newline(&mut self, path: &PathBuf) -> io::Result<()> { |
There was a problem hiding this comment.
quite a long name :)
maybe a bool on copy_file instead, or a shorter name?
| fn begin_resolved(&mut self, file_name: &Path) -> UResult<&mut OutputBuffer> { | ||
| if !self.in_place { | ||
| self.output = OutputBuffer::new(Box::new(stdout())); | ||
| self.output = OutputBuffer::new(Box::new(stdout())).continuing(&self.output); |
There was a problem hiding this comment.
do we need a builder for this? setting pending_newline here seems simpler
| ) | ||
| .unwrap_err() | ||
| }) | ||
| let pending = std::mem::replace(&mut self.pending_newline, !newline); |
There was a problem hiding this comment.
this chain of if/and_then is hard to read
could you please use a small closure with ? and do the map_err once?
When an input file's last line has no final newline and another file follows, GNU sed writes the missing newline before the next output. uutils sed drops it, so the last line of one file runs into the first output of the next: with
printf a > 1andprintf 'b\n' > 2,sed '' 1 2printsabinstead ofaandbon separate lines. The same happens inwandWfiles.This PR carries the deferred newline from one file's output buffer to the next, and gives
NamedWriterthe same deferred newline forw,Wands///wfiles.Wnow passes its first line without the newline, so that the writer knows whether the line ended. With-i, each file keeps its own output, so nothing is carried between files.0rnow writes its file before a newline carried over from the previous file, which then comes before that file's first line, as in GNU sed.-zis still ignored, so with-zthe files also get a newline between them, as they do without it.