Skip to content

Filter-out context-only hunks in our range-diff#2398

Merged
Urgau merged 4 commits intorust-lang:masterfrom
Urgau:gh-range-diff-hide-more
May 9, 2026
Merged

Filter-out context-only hunks in our range-diff#2398
Urgau merged 4 commits intorust-lang:masterfrom
Urgau:gh-range-diff-hide-more

Conversation

@Urgau
Copy link
Copy Markdown
Member

@Urgau Urgau commented May 7, 2026

This PR filter-out context-only hunks in our range-diff.

We currently only hide-by-default file changes that only have context-only changes, but as described in #2394, a range-diff might have plenty of hunks that only have context changes (ie not a diff line, +/-).

Currently (with context-only changes) Currently This PR
image image image

Implementation wise, I had to copy and lighting edit the UnifiedDiff implementation from imara-diff in order to be able to filter-out some hunks.

I sadly had to remove the checkbox (not sure it was very useful to begin with) as knowing with lines to show/hide is highly non-trivial for context line as they can be part of the same context for multiple hunks at the same time (each hunk has +- 3 context line).

I also took the opportunity to switch to gix-imara-diff since the original crate has had unreleased fixes for several months.

Testing link: http://localhost:8000/gh-range-diff/rust-lang/miri/98cb1d3d48fa7c8e97994050bfd69e8f3da2a1a7..3f8007e19b8cac3d08fb07579bde3217c58807e4/e0b3afbdd5362aa348abc6661ed6417d1a21f58c..d811aaf958594156e2ce38365b835c361aa88de9

Fixes #2394
cc @RalfJung

Copy link
Copy Markdown
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Can't say I could examine the hunk algorithm in detail at the moment, but the output looks reasonable, and the filtering of non-interesting hunks seems valid.

View changes since this review

@Urgau
Copy link
Copy Markdown
Member Author

Urgau commented May 9, 2026

Can't say I could examine the hunk algorithm in detail at the moment

I wouldn't expect you to do it, I didn't examine it in detail my-self.

The only different between our version and the one in the crate is that we give &[Hunk] instead of &Diff, so we can filter-out some hunks, the rest is strictly the same.

@Urgau Urgau added this pull request to the merge queue May 9, 2026
Merged via the queue into rust-lang:master with commit 6020747 May 9, 2026
3 checks passed
@Urgau Urgau deleted the gh-range-diff-hide-more branch May 9, 2026 11:29
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.

range-diff: some context-only chnges are still shown

2 participants