Skip to content

sed: write appended text, R text and e output as GNU sed does - #589

Draft
DePasqualeOrg wants to merge 2 commits into
uutils:mainfrom
DePasqualeOrg:fix-r-separator-and-q-appends
Draft

DePasqualeOrg wants to merge 2 commits into
uutils:mainfrom
DePasqualeOrg:fix-r-separator-and-q-appends

Conversation

@DePasqualeOrg

@DePasqualeOrg DePasqualeOrg commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Please ignore this PR until it is marked as ready for review


This PR builds on #592, which fixes n; only its last commit is new. It now also includes the change from #590, because each needed the other.

When the last line of input has no final newline and the cycle ends with text queued by a, r or R, GNU sed first writes the missing newline and then the queued text, even when an r file is missing or empty. uutils sed joins them instead: printf a | sed 'r f' prints a immediately followed by the contents of f. This PR writes the missing newline before any text queued for the end of the cycle.

GNU sed copies the line that R reads, and the output of the e command form, exactly as they are. uutils sed treats them as lines and adds a newline when they lack one. With a file f that contains x and no newline, printf 'a\nb\n' | sed 'R f' prints x and b on separate lines, while GNU sed prints xb. Likewise, printf 'a\n' | sed '1e printf hi' prints hi on a line of its own, while GNU sed prints hia. This PR adds OutputBuffer::write_raw, which writes a newline that the previous output line lacks and then the bytes unchanged, and uses it for this text.

Q now discards text queued by a, r and R, as GNU sed does. Before, printf 'x\n' | sed -e 'a A' -e Q printed A. q still writes queued text. Finally, l now prints $ for an empty pattern space whose line lacked a newline.

codecov/patch and codecov/project fail only because CI does not count the coverage of tests that run the sed binary; they should pass after #591 is merged.

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 27.58621% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.79%. Comparing base (1113479) to head (ae5f8dc).

Files with missing lines Patch % Lines
src/sed/processor.rs 12.50% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #589      +/-   ##
==========================================
- Coverage   83.86%   83.79%   -0.08%     
==========================================
  Files          14       14              
  Lines        7203     7219      +16     
  Branches      424      428       +4     
==========================================
+ Hits         6041     6049       +8     
- Misses       1157     1165       +8     
  Partials        5        5              
Flag Coverage Δ
macos_latest 84.90% <27.58%> (-0.09%) ⬇️
ubuntu_latest 85.09% <27.58%> (-0.08%) ⬇️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 36.51%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 10 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ access_log_append 1.5 s 1.1 s +36.51%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing DePasqualeOrg:fix-r-separator-and-q-appends (ae5f8dc) with main (1113479)

Open in CodSpeed

@DePasqualeOrg
DePasqualeOrg force-pushed the fix-r-separator-and-q-appends branch from 3ab6bde to ae5f8dc Compare October 2, 2026 18:17
@DePasqualeOrg DePasqualeOrg changed the title sed: end a line that lacks its newline before appended text, and discard appended text on Q sed: write appended text, R text and e output as GNU sed does Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 18 / FAILED: 39 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 17 / FAILED: 40 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + distrib

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.

1 participant