Skip to content

Commit f88ee99

Browse files
cruesslerByron
authored andcommitted
Don't consume unblamed hunk following deletion
There might be more changes that are supposed to affect the unblamed hunk. The deletion might, for example, be followed by another deletion or by an addition both of which would have an effect on the offset that needs to be applied to the unblamed hunk.
1 parent 960d7ba commit f88ee99

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

gix-blame/tests/blame.rs

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -570,15 +570,7 @@ fn process_change(
570570

571571
*offset_in_destination -= number_of_lines_deleted;
572572

573-
let line_range_in_next_destination =
574-
LineRange::with_offset(hunk.range_in_destination.clone(), *offset_in_destination);
575-
576-
new_hunks_to_blame.push(UnblamedHunk::from_destination(
577-
line_range_in_next_destination.into(),
578-
hunk.offset() + *offset_in_destination,
579-
));
580-
581-
(None, None)
573+
(Some(hunk), None)
582574
} else if line_number_in_destination < hunk.range_in_destination.end {
583575
// <-----> (hunk)
584576
// | (line_number_in_destination)
@@ -1582,6 +1574,36 @@ fn process_change_works_no_overlap_5() {
15821574
assert_eq!(offset_in_destination, Offset::Added(1));
15831575
}
15841576

1577+
#[test]
1578+
fn process_change_works_no_overlap_6() {
1579+
let mut lines_blamed: Vec<BlameEntry> = vec![];
1580+
let mut new_hunks_to_blame: Vec<UnblamedHunk> = vec![];
1581+
let mut offset_in_destination: Offset = Offset::Added(0);
1582+
let suspect = ObjectId::null(gix_hash::Kind::Sha1);
1583+
1584+
let (hunk, change) = process_change(
1585+
&mut lines_blamed,
1586+
&mut new_hunks_to_blame,
1587+
&mut offset_in_destination,
1588+
suspect,
1589+
// range_in_destination: 22..24
1590+
Some(UnblamedHunk::new(23..25, Offset::Added(1))),
1591+
Some(Change::Deleted(20, 1)),
1592+
);
1593+
1594+
assert_eq!(
1595+
hunk,
1596+
Some(UnblamedHunk {
1597+
range_in_blamed_file: 23..25,
1598+
range_in_destination: 22..24
1599+
})
1600+
);
1601+
assert_eq!(change, None);
1602+
assert_eq!(lines_blamed, vec![]);
1603+
assert_eq!(new_hunks_to_blame, vec![]);
1604+
assert_eq!(offset_in_destination, Offset::Deleted(1));
1605+
}
1606+
15851607
#[test]
15861608
fn process_change_works_unchanged_hunk() {
15871609
let mut lines_blamed: Vec<BlameEntry> = vec![];
@@ -1729,10 +1751,16 @@ fn process_change_works_deleted_hunk_2() {
17291751
Some(Change::Deleted(0, 4)),
17301752
);
17311753

1732-
assert_eq!(hunk, None);
1754+
assert_eq!(
1755+
hunk,
1756+
Some(UnblamedHunk {
1757+
range_in_blamed_file: 2..16,
1758+
range_in_destination: 2..16
1759+
})
1760+
);
17331761
assert_eq!(change, None);
17341762
assert_eq!(lines_blamed, vec![]);
1735-
assert_eq!(new_hunks_to_blame, vec![UnblamedHunk::new(2..16, Offset::Deleted(4))]);
1763+
assert_eq!(new_hunks_to_blame, vec![]);
17361764
assert_eq!(offset_in_destination, Offset::Deleted(4));
17371765
}
17381766

0 commit comments

Comments
 (0)