GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — diff: mark every line of a change block with ! in context format by jayhemnani9910 · Pull Request #311 · uutils/diffutils

Conversation

@jayhemnani9910

@jayhemnani9910 jayhemnani9910 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

In context format (-c, -C), when a block of lines is replaced by a block of a different length, only as many lines as pair up get !; the rest are shown as plain deletions or insertions. GNU diff marks every line of the block with !:

$ printf 'a\nb\nc\nd\n' > foo; printf 'a\nx\nd\n' > bar
$ diff -c foo bar
GNU diff 3.12         uutils
*** 1,4 ****          *** 1,4 ****
  a                     a
! b                   - b
! c                   ! c
  d                     d
--- 1,3 ----          --- 1,3 ----
  a                     a
! x                   ! x
  d                     d

Both versions apply with patch, but the output differs from GNU's for any change that isn't line-for-line, and tools that read context diffs see a deletion plus a change instead of one change.

make_diff now tracks each run of changed lines with no common line in between. When the run both deletes and inserts lines, all of its lines on both sides become Change. Runs that only delete or only insert keep - and +. This replaces the one-to-one pairing through expected_lines_change_idx.

New test test_change_block_lines_all_changed (2 lines replaced by 1, 1 replaced by 3) fails without the change. cargo test: 287 passed, clippy unchanged, fmt clean. On 6000 random file pairs with 0, 1 and 3 context lines, wherever uutils -U output equals GNU's (the same alignment), -C output now also equals GNU's in all 14682 cases; before, 3381 of 7373 differed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jayhemnani9910
diff: mark every line of a change block with ! in context format
2ff1348
Copilot AI balanced review requested due to automatic review settings October 22, 2026 05:26
Copilot AI reviewed Oct 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sylvestre
sylvestre reviewed Oct 22, 2026
View reviewed changes
Comment thread src/context_diff.rs Outdated
if (line_number_actual > actual_lines_count)
&& (line_number_expected > expected_lines_count)
{
if let Some(block) = block.take() {

@sylvestre sylvestre Oct 22, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

the same 3 lines if let Some(block) = block.take() { block.finish(...) } appear 3 times, could be dedup, no?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jayhemnani9910 jayhemnani9910 Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done in 184caa0. ChangeBlock::close replaces them.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sylvestre
sylvestre reviewed Oct 22, 2026
View reviewed changes
Comment thread src/context_diff.rs Outdated
mismatch.expected.push(DiffLine::Context(line.to_vec()));
mismatch.actual.push(DiffLine::Context(line.to_vec()));
}
let block = block.get_or_insert_with(|| ChangeBlock::new(&mismatch));

@sylvestre sylvestre Oct 22, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

same here, these 3 lines are duplicated just below
maybe a small helper on ChangeBlock?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jayhemnani9910 jayhemnani9910 Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done in 184caa0, ChangeBlock::mark now opens the block and records whether it deletes or inserts.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
sylvestre
sylvestre reviewed Oct 22, 2026
View reviewed changes
Comment thread src/context_diff.rs Outdated
}
}

if let Some(block) = block.take() {

@sylvestre sylvestre Oct 22, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

take() isn't needed here, block isn't used after

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jayhemnani9910 jayhemnani9910 Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done, dropped it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jayhemnani9910
diff: share change block bookkeeping in context format
184caa0
Copilot AI balanced review requested due to automatic review settings October 22, 2026 10:53
Copilot AI reviewed Oct 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sylvestre
sylvestre merged commit 38fbe73 into uutils:main Oct 22, 2026
31 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@sylvestre

sylvestre commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Thanks for your PR

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BrewTestBot BrewTestBot mentioned this pull request Oct 23, 2026
uutils-diffutils 0.6.0 Homebrew/homebrew-core#320660
Merged
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sylvestre sylvestre sylvestre left review comments
Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@jayhemnani9910 @sylvestre
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.