Skip to content

Commit

Permalink
Simplify a branch that processes unchanged lines
Browse files Browse the repository at this point in the history
Don't split unblamed hunk when it overlaps with unchanged lines.
  • Loading branch information
cruessler committed Sep 20, 2024
1 parent 17e7833 commit 42fe45f
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions gix-blame/tests/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,38 +367,16 @@ fn process_change(
(true, false) => {
// <--------> (hunk)
// <-------> (unchanged)
// <----> (new hunk)
// <--> (new hunk)

if unchanged.start > hunk.range_in_destination.start {
let line_range_in_next_destination = LineRange::with_offset(
hunk.range_in_destination.start..unchanged.start,
*offset_in_destination,
);

new_hunks_to_blame.push(UnblamedHunk::from_destination(
line_range_in_next_destination.into(),
hunk.offset() + *offset_in_destination,
));
}

let line_range_in_next_destination =
LineRange::with_offset(unchanged.start..hunk.range_in_destination.end, *offset_in_destination);
LineRange::with_offset(hunk.range_in_destination.clone(), *offset_in_destination);

new_hunks_to_blame.push(UnblamedHunk::from_destination(
line_range_in_next_destination.into(),
hunk.offset() + *offset_in_destination,
));

let new_change = if unchanged.end > hunk.range_in_destination.end {
let line_range = hunk.range_in_destination.end..unchanged.end;

Some(Change::Unchanged(line_range))
} else {
todo!();
};

(None, new_change)
(None, Some(Change::Unchanged(unchanged)))
}
(false, false) => {
if unchanged.end <= hunk.range_in_destination.start {
Expand Down Expand Up @@ -1761,7 +1739,7 @@ fn process_change_works_enclosing_unchanged_lines() {
);

assert_eq!(hunk, None);
assert_eq!(change, Some(Change::Unchanged(113..172)));
assert_eq!(change, Some(Change::Unchanged(109..172)));
assert_eq!(lines_blamed, vec![]);
assert_eq!(
new_hunks_to_blame,
Expand Down Expand Up @@ -1819,7 +1797,7 @@ fn process_change_works_unchanged_hunk_2() {
);

assert_eq!(hunk, None);
assert_eq!(change, Some(Change::Unchanged(5..7)));
assert_eq!(change, Some(Change::Unchanged(0..7)));
assert_eq!(lines_blamed, vec![]);
assert_eq!(
new_hunks_to_blame,
Expand Down

0 comments on commit 42fe45f

Please sign in to comment.