Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 7, 2025

Adds imara-diff v0.2 alongside existing v0.1 to provide Git's slider heuristics for more intuitive diff placement.

Changes

  • Dependency: Added imara-diff-v0_2 (v0.2.0) alongside existing v0.1.8
  • API: Exposed v0.2 types via blob::v0_2 module (Diff, UnifiedDiffPrinter, IndentHeuristic, etc.)
  • Convenience function: Added diff_with_slider_heuristics() that computes and postprocesses diffs in one call
  • Tests: Added 10 tests demonstrating UnifiedDiffPrinter usage, custom heuristics, and hunk iteration

Usage

use gix_diff::blob::{diff_with_slider_heuristics, v0_2::{Algorithm, InternedInput}};

let input = InternedInput::new(before, after);
let diff = diff_with_slider_heuristics(Algorithm::Histogram, &input);

// Generate unified diff output
let printer = v0_2::BasicLineDiffPrinter(&input.interner);
let output = diff.unified_diff(&printer, v0_2::UnifiedDiffConfig::default(), &input);

Maintains full backward compatibility with existing v0.1 API.

Original prompt

In gix_diff::blob uses imara-diff v0.1 to provide gix_diff::blob::diff() for callers that don't need Git slider heuristics. Add the v0.2 of imara-diff as dependency and expose its Diff structure via git::blob::diff_with_slider_heuristics(). Add tests for it as well as you see fit, showing how the UnifiedDiffPrinter can be used.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add imara-diff v0.2 as dependency and expose Diff structure Add imara-diff v0.2 with slider heuristics support Dec 7, 2025
Copilot AI requested a review from Byron December 7, 2025 08:50
Comment on lines +34 to +35
/// // The diff now has slider heuristics applied
/// assert_eq!(diff.count_removals(), 1);
/// assert_eq!(diff.count_additions(), 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

@Byron Counting removals and additions probably is not the best example to showcase slider heuristics as line numbers are not affected by moving sliders up and down. :-)

Copilot AI and others added 2 commits December 7, 2025 14:11
- Add imara-diff v0.2.0 as dependency alongside v0.1.8
- Expose v0.2 API through blob::v0_2 module
- Add diff_with_slider_heuristics() function for convenient usage
- Add comprehensive tests demonstrating UnifiedDiffPrinter usage
- Tests cover various scenarios including multi-hunk diffs and custom context sizes

Co-authored-by: Byron <[email protected]>
- rename `v0_2` to `v2`
- adjust tests to use more of `insta`
- feature-gate v2 and let only tests activate the feature.
@Byron Byron force-pushed the copilot/add-imara-diff-v0-2 branch from 51ca834 to 4d3a6b1 Compare December 7, 2025 13:52
@Byron Byron marked this pull request as ready for review December 7, 2025 13:53
@Byron Byron enabled auto-merge December 7, 2025 13:53
@Byron
Copy link
Member

Byron commented Dec 7, 2025

Alright, @cruessler, I have worked it over and think v2 is good as experimental feature to play around with. The integration tests are a test-bed on its own, but I think now it's more straightforward to try it with gix-blame for example.

Performance would be interesting, and the usability of the unified diff printer, which desperately misses &[u8] compatibility (and a lot of tests). I have also created pascalkuthe/imara-diff#41 to attack this from another angle, as V2 is quite underdocumented still.

I hope this helps 🙏

@Byron Byron merged commit 111b625 into main Dec 7, 2025
28 checks passed
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.

3 participants