-
-
Notifications
You must be signed in to change notification settings - Fork 408
Update gix-blame to imara-diff 0.2
#2287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update gix-blame to imara-diff 0.2
#2287
Conversation
|
This looks very promising indeed! Some complexity now moved to Let's see those performance comparisons as well :). |
|
I added a feature flag, I decided to re-use the comment to I’ll mark this PR as ready even though CI hasn’t completed yet (so I can turn off my computer :-)). If anything comes up, I’ll address it, but apart from that, I hope it is finished. The only thing that’s missing is proably a line such as the following one in |
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.
Pull request overview
This PR updates gix-blame to use imara-diff 0.2 through the new blob-experimental feature in gix-diff. The update is feature-gated to allow testing both versions, and notably, a test that previously required should_panic for the Myers algorithm now passes with the new version.
- Feature-gated implementation allows testing both
imara-diff0.1 and 0.2 - New
blob_changesfunction implementation for v2 API with simplified hunk processing - Test organization updated to separate v1 and v2 test cases with appropriate feature gates
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| gix-blame/Cargo.toml | Adds blob-experimental feature flag to enable imara-diff 0.2 via gix-diff |
| justfile | Adds test command for gix-blame with the new blob-experimental feature |
| gix-blame/tests/blame.rs | Splits diff_disparity test into v1 and v2 variants, updates comments to reflect that v2 tests now pass |
| gix-blame/src/file/function.rs | Implements feature-gated blob_changes function for imara-diff 0.2 API with updated hunk processing logic |
gix-blame/src/file/function.rs
Outdated
| let changes = diff | ||
| .hunks() | ||
| .fold((Vec::new(), 0), |(mut hunks, mut last_seen_after_end), hunk| { | ||
| let Hunk { before, after } = hunk; | ||
|
|
||
| // This checks for unchanged hunks. | ||
| if after.start > last_seen_after_end { | ||
| hunks.push(Change::Unchanged(last_seen_after_end..after.start)); | ||
| } | ||
|
|
||
| match (!before.is_empty(), !after.is_empty()) { | ||
| (_, true) => { | ||
| hunks.push(Change::AddedOrReplaced( | ||
| after.start..after.end, | ||
| before.end - before.start, | ||
| )); | ||
| } | ||
| (true, false) => { | ||
| hunks.push(Change::Deleted(after.start, before.end - before.start)); | ||
| } | ||
| (false, false) => unreachable!("BUG: imara-diff provided a non-change"), | ||
| } | ||
|
|
||
| last_seen_after_end = after.end; | ||
|
|
||
| (hunks, last_seen_after_end) | ||
| }); | ||
|
|
||
| stats.blobs_diffed += 1; | ||
| Ok(changes.0) |
Copilot
AI
Dec 17, 2025
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 new implementation is missing logic to handle the final unchanged hunk at the end of the file. In the original implementation (lines 812-815), there's a check in the finish method that adds a final Change::Unchanged if there are lines remaining after the last change. This ensures the entire file is represented by Change entries.
The v2 implementation should add similar logic after the fold operation to check if last_seen_after_end is less than the total number of lines in the destination file, and if so, push a final Change::Unchanged hunk.
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.
Great catch!
We also don't have that could catch this.
a0fee1a to
0b7c1dd
Compare
|
Thanks a lot, this looks very promising already! Lastly, let me point out a critical issue that Copilot found which I 'fixed', but also noticed that there is no test that captures this particular handling. Now I wonder if Blame doesn't care due to its nature, so the special case could be dropped, or if we are really missing that one test that runs into this. |
This is a quick conversion of
gix-blameto useimara-diff0.2 throughgix-diff’s newblob-experimentalfeature. I haven’t run any benchmarks yet, just wanted to open the PR, so you can have a look yourself! The update made one test that previously was markedshould_panicpass, so that’s already promising. :-)