Skip to content

Commit da4fcf7

Browse files
committed
Change offset for changes when there is no hunk
At this point, this is not strictly necessary as the changes to `offset_in_destination` are not read anywhere yet after they are changed in the added branches.
1 parent cbb32f7 commit da4fcf7

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

gix-blame/tests/blame.rs

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,18 @@ fn process_change(
611611

612612
(None, None)
613613
}
614-
(None, Some(_)) => (None, None),
614+
(None, Some(Change::Unchanged(_))) => (None, None),
615+
(None, Some(Change::Added(added, number_of_lines_deleted))) => {
616+
*offset_in_destination += added.end - added.start;
617+
*offset_in_destination -= number_of_lines_deleted;
618+
619+
(None, None)
620+
}
621+
(None, Some(Change::Deleted(_, number_of_lines_deleted))) => {
622+
*offset_in_destination -= number_of_lines_deleted;
623+
624+
(None, None)
625+
}
615626
(None, None) => (None, None),
616627
}
617628
}
@@ -1706,6 +1717,74 @@ fn process_change_works_deleted_hunk_3() {
17061717
assert_eq!(offset_in_destination, Offset::Deleted(4));
17071718
}
17081719

1720+
#[test]
1721+
fn process_change_works_addition_only() {
1722+
let mut lines_blamed: Vec<BlameEntry> = vec![];
1723+
let mut new_hunks_to_blame: Vec<UnblamedHunk> = vec![];
1724+
let mut offset_in_destination: Offset = Offset::Added(1);
1725+
let suspect = ObjectId::null(gix_hash::Kind::Sha1);
1726+
1727+
let (hunk, change) = process_change(
1728+
&mut lines_blamed,
1729+
&mut new_hunks_to_blame,
1730+
&mut offset_in_destination,
1731+
suspect,
1732+
None,
1733+
Some(Change::Added(22..25, 1)),
1734+
);
1735+
1736+
assert_eq!(hunk, None);
1737+
assert_eq!(change, None);
1738+
assert_eq!(lines_blamed, vec![]);
1739+
assert_eq!(new_hunks_to_blame, vec![]);
1740+
assert_eq!(offset_in_destination, Offset::Added(3));
1741+
}
1742+
1743+
#[test]
1744+
fn process_change_works_deletion_only() {
1745+
let mut lines_blamed: Vec<BlameEntry> = vec![];
1746+
let mut new_hunks_to_blame: Vec<UnblamedHunk> = vec![];
1747+
let mut offset_in_destination: Offset = Offset::Added(1);
1748+
let suspect = ObjectId::null(gix_hash::Kind::Sha1);
1749+
1750+
let (hunk, change) = process_change(
1751+
&mut lines_blamed,
1752+
&mut new_hunks_to_blame,
1753+
&mut offset_in_destination,
1754+
suspect,
1755+
None,
1756+
Some(Change::Deleted(11, 5)),
1757+
);
1758+
1759+
assert_eq!(hunk, None);
1760+
assert_eq!(change, None);
1761+
assert_eq!(lines_blamed, vec![]);
1762+
assert_eq!(new_hunks_to_blame, vec![]);
1763+
assert_eq!(offset_in_destination, Offset::Deleted(4));
1764+
}
1765+
1766+
#[test]
1767+
fn process_change_works_unchanged_only() {
1768+
let mut lines_blamed: Vec<BlameEntry> = vec![];
1769+
let mut new_hunks_to_blame: Vec<UnblamedHunk> = vec![];
1770+
let mut offset_in_destination: Offset = Offset::Added(1);
1771+
let suspect = ObjectId::null(gix_hash::Kind::Sha1);
1772+
1773+
let (hunk, change) = process_change(
1774+
&mut lines_blamed,
1775+
&mut new_hunks_to_blame,
1776+
&mut offset_in_destination,
1777+
suspect,
1778+
None,
1779+
Some(Change::Unchanged(11..13)),
1780+
);
1781+
1782+
assert_eq!(hunk, None);
1783+
assert_eq!(change, None);
1784+
assert_eq!(lines_blamed, vec![]);
1785+
assert_eq!(new_hunks_to_blame, vec![]);
1786+
assert_eq!(offset_in_destination, Offset::Added(1));
1787+
}
17091788
#[test]
17101789
fn process_changes_works() {
17111790
let mut lines_blamed: Vec<BlameEntry> = vec![];

0 commit comments

Comments
 (0)