pub fn refine_regions(removed: &[&str], added: &[&str]) -> RegionRefinementExpand description
Refine one hunk’s removed region against its added region.
Region-to-region, not line-paired (DR.5). The two runs are tokenised whole, diffed as single token streams, and the changed ranges scattered back onto whichever lines they fell on. Nothing decides which added line “replaced” which removed one, because nothing has to — which is exactly why an n-removed / m-added hunk refines here and declined under the old pairing rule.
This is what the reference implementation does:
magit-diff-update-hunk-refinement hands the hunk’s whole removed
and added regions to smerge-refine-regions. The predecessor’s
claim that “magit declines the same case” was simply wrong.
Returns an empty RegionRefinement — which renders exactly as it
did before refinement existed, the direction this feature must fail
in — when refinement would be noise rather than signal:
- either side is absent (a pure
AddorRemovehas nothing to compare against); - the two regions are identical (nothing to say);
- either side is wholly changed past [
MAX_REFINED_SHARE] — the uniform row tint already conveys “this changed”, and marking nearly all of it adds a second colour saying the same thing; - either side exceeds [
MAX_REGION_BYTES] (see that constant).