Skip to content

pr: indent the page header with -o like GNU - #16707

Open
shivangithaker-0510 wants to merge 4 commits into
uutils:mainfrom
shivangithaker-0510:fix/16211-pr-indent-header
Open

shivangithaker-0510 wants to merge 4 commits into
uutils:mainfrom
shivangithaker-0510:fix/16211-pr-indent-header

Conversation

@shivangithaker-0510

Copy link
Copy Markdown

With -o MARGIN, the margin was only written before body lines. Also write it before the first blank line of the header and before the header text line, like GNU pr does.

Closes #16211

Comment thread src/uu/pr/src/pr.rs Outdated
for x in header {
writer.write_all(&x)?;
for (index, x) in header.iter().enumerate() {
// Like GNU, the left margin goes on the first blank line and on the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Like GNU, the left margin goes on the first blank line and on the
// The left margin goes on the first blank line and on the

Comment thread src/uu/pr/src/pr.rs Outdated
for (index, x) in header.iter().enumerate() {
// The left margin goes on the first blank line and on the
// header text line, but not on the other blank header lines.
if index == 0 || index == 2 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these 0 and 2 depend on the vec layout in header_content, could the margin be added there instead?

Comment thread src/uu/pr/src/pr.rs Outdated
vec![Vec::new(), Vec::new(), header_line, Vec::new(), Vec::new()]
// The left margin goes on the first blank line and on the header text
// line, but not on the other blank header lines.
let margin = vec![b' '; options.offset_spaces];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this allocates the whole margin (twice) on every page, -o 999999999 without -t now needs ~2GB
could the margin still be streamed with write_offset_spaces, e.g. header_content only returns the text line and write_page lays out the 5 lines?

Comment thread tests/by-util/test_pr.rs
.pipe_in("line\n")
.succeeds()
.stdout_only(format!("{header} line\n\x0c"));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please also run test_offset_large_value_does_not_abort_under_memory_limit without -t, so the header path is covered

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/tail/follow-name is no longer failing!
Congrats! The gnu test tests/tail/pid-pipe is no longer failing!

@codspeed

codspeed Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 14.88%

1 warning, 1 note

⚠️ 119 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 9 improved benchmarks
✅ 404 untouched benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation file_custom_format 15.8 ms 11.5 ms +38.18%
⚡ CPU Simulation file_iso_dates 17.7 ms 13.4 ms +32.32%
⚡ CPU Simulation file_localized_names 27.1 ms 22.7 ms +19.31%
⚡ CPU Simulation false_consecutive_calls 350.2 ns 294.7 ns +18.85%
⚡ CPU Simulation split_number_chunks_round_robin 32.8 ms 28.9 ms +13.4%
⚡ CPU Simulation file_tz_abbreviations 18.1 ms 16.8 ms +7.74%
⚡ CPU Simulation dd_copy_8k_blocks 1.9 ms 1.9 ms +3.4%
⚡ CPU Simulation dd_copy_with_seek 5 ms 4.9 ms +3.19%
⚡ CPU Simulation dd_copy_with_skip 4.9 ms 4.8 ms +3.14%

Tip

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


Comparing shivangithaker-0510:fix/16211-pr-indent-header (2a90d33) with main (9d6c862)2

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (f2d7c59) during the generation of this report, so 9d6c862 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

With -o MARGIN, the margin was only written before body lines. Also write it before the first blank line of the header and before the header text line, like GNU pr does.

Closes uutils#16211
@sylvestre
sylvestre force-pushed the fix/16211-pr-indent-header branch from 2a90d33 to 1b192d3 Compare November 20, 2026 10:29

This branch has not been deployed

No deployments
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.

pr: -o/--indent does not pad the header line

3 participants