Skip to content

diff: place -y gutter marker at the middle of the gutter - #277

Open
nagendramohan wants to merge 2 commits into
uutils:mainfrom
nagendramohan:fix/sdiff-gutter-marker-column-269
Open

nagendramohan wants to merge 2 commits into
uutils:mainfrom
nagendramohan:fix/sdiff-gutter-marker-column-269

Conversation

@nagendramohan

Copy link
Copy Markdown

In side-by-side (-y) output the gutter marker was written wherever process_half_line stopped
padding the left half (one column past sdiff_half_width), not at separator_pos (the middle of
the gutter). Those agree only when the gutter is 3–4 columns wide, so the default
--width=130 --tabsize=8 (gutter 3) looked right while other widths/tab sizes drifted — e.g.
--width=40 placed < at column 17 instead of 19.

Pad from half_width + 1 up to separator_pos before writing the marker so it lands at the gutter
middle, matching GNU sdiff. format_tabs_and_spaces is a no-op when already at/past separator_pos,
so narrow gutters are unaffected. Added a regression test at --width=40.

Fixes #269.

In side-by-side output the gutter marker was written wherever
process_half_line stopped padding the left half (one column past
sdiff_half_width), not at separator_pos (the middle of the gutter).
Those agree only when the gutter is 3 or 4 columns wide, so the default
--width=130 --tabsize=8 (gutter 3) looked right while other widths/tab
sizes drifted (e.g. --width=40 placed '<' at column 17 instead of 19).

Pad from half_width + 1 up to separator_pos before writing the marker so
it lands at the gutter middle, matching GNU sdiff. format_tabs_and_spaces
is a no-op when already at/past separator_pos, so narrow gutters are
unaffected. Add a regression test at --width=40.

Fixes uutils#269
@github-actions

Copy link
Copy Markdown

GNU diffutils testsuite comparison:

Test results comparison:
  Current:   TOTAL: 33 / PASSED: 0 / FAILED: 33 / SKIPPED: 0
  Reference: TOTAL: 33 / PASSED: 8 / FAILED: 21 / SKIPPED: 4

Changes from main branch:
  TOTAL: +0
  PASSED: -8
  FAILED: +12

New test failures (12):
  - basic
  - bignum
  - brief-vs-stat-zero-kernel-lies
  - bug-64316
  - cmp
  - diff3
  - help-version
  - large-subopt
  - strcoll-0-names
  - strip-trailing-cr
  - timezone
  - y2038-vs-32bit

Comment thread src/side_diff.rs Outdated
// `process_half_line` left the cursor one column past the half width. The gutter marker
// belongs at the middle of the gutter (`separator_pos`), which is only `half_width + 1`
// when the gutter is 3 or 4 columns wide; pad up to it for wider gutters so the marker
// doesn't drift (see #269). `format_tabs_and_spaces` is a no-op when already at/past it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

4 lines of comment for a one-liner, could you please make it shorter? :)

Comment thread src/side_diff.rs Outdated
// Regression test for #269: the `-y` gutter marker must sit at the middle of the gutter
// (separator_pos) regardless of gutter width. At the default width (gutter 3) the marker
// was already correct; at other widths it drifted. Here width=40 yields a wider gutter, so
// the marker must land at column 19 (matching GNU), not the old `half_width + 1`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here, please make it shorter

Comment thread src/side_diff.rs
// (separator_pos) regardless of gutter width. At the default width (gutter 3) the marker
// was already correct; at other widths it drifted. Here width=40 yields a wider gutter, so
// the marker must land at column 19 (matching GNU), not the old `half_width + 1`.
#[test]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please also add a test in tests/integration.rs with -y --width=40

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks! Shortened both comments and added an integration test covering -y --width=40 in both --expand-tabs and the default (tab-path) modes, asserting the marker sits at the gutter middle.

Comment thread src/side_diff.rs
let params = Params {
tabsize: 8,
expand_tabs: true,
width: 40,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could you please also test with expand_tabs: false?
that is the default, and the padding goes through the tab path

Shorten the two long comments per review, and add an integration test in
tests/integration.rs exercising `-y --width=40` in both the default
(expand_tabs: false, tab-padding path) and --expand-tabs modes, asserting
the gutter marker lands at the middle of the gutter.
Comment thread tests/integration.rs
}

// Visual (tab-aware) column of the `-y` gutter marker on the first output line.
fn side_marker_visual_column(output: &[u8], tabsize: usize) -> Option<usize> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could we just compare the whole stdout instead of this helper?
simpler, and it would also check the exact tabs/spaces emitted

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.

diff: -y draws the gutter marker at the wrong column unless the gutter is 3 or 4 columns wide

2 participants