Skip to content

Conversation

@kerneltoast
Copy link
Contributor

This implements a --fuzzy option to make interdiff perform a fuzzy comparison between two diffs. This is very helpful, for example, for comparing a backport patch to its upstream source patch to assist a human reviewer in verifying the correctness of the backport.

It's difficult to conditionally add additional arguments to the patch
execution in apply_patch() because they are placed within a compound
literal array.

Make the arguments more extensible by creating a local array and an index
variable to place the next argument into the array. This way, it's much
easier to change the number of arguments provided at runtime.
@codecov
Copy link

codecov bot commented Oct 17, 2025

Codecov Report

❌ Patch coverage is 26.26263% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.74%. Comparing base (7b7dcca) to head (32e5f1d).
⚠️ Report is 18 commits behind head on master.

Files with missing lines Patch % Lines
src/interdiff.c 26.26% 73 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #147      +/-   ##
==========================================
- Coverage   85.78%   85.74%   -0.05%     
==========================================
  Files          15       15              
  Lines        8112     8264     +152     
  Branches     1620     1664      +44     
==========================================
+ Hits         6959     7086     +127     
- Misses       1153     1178      +25     
Flag Coverage Δ
unittests 85.74% <26.26%> (-0.05%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

@kerneltoast
Copy link
Contributor Author

@twaugh codecov aside, what do you think about the fuzzy feature? Are you (un)opposed to the idea?

This implements a --fuzzy option to make interdiff perform a fuzzy
comparison between two diffs. This is very helpful, for example, for
comparing a backport patch to its upstream source patch to assist a human
reviewer in verifying the correctness of the backport.

To achieve fuzzy diffing: Instead of creating a different dummy original
file for p1 and p2 and applying p1 to p2's original file and p2 to p1's
original file, use p1's original file for both cases when fuzzy diffing.

This way, interdiff can rely upon the patch command to fuzz the line offset
and context differences between hunks in p1 and p2. And then the final diff
command at the end will show the remaining differences using the same base
file, so it won't report hunks as differing just because of differing line
offsets. The diff command can't do any fuzzy diffing, hence why we need to
rely on the patch command for this capability.

The fuzzy diffing option also handles rejected hunks by showing them in the
output as a differing hunk. And it tries to avoid *additionally* showing
the *reverse* of the rejected hunks by applying the rejected hunks with
maximum fuzz, so that the final diff command doesn't show them.
@twaugh
Copy link
Owner

twaugh commented Oct 22, 2025

I like it a lot actually, and it's definitely something people have asked for before (in fact I think it's often assumed it will just work).

Does it avoid exposing 'unline's?

@kerneltoast
Copy link
Contributor Author

Yes, it doesn't expose any unlines.

Allow the user to append =N to `--fuzzy` to specify the maximum number of
context lines for `patch` to fuzz.
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.

2 participants