@@ -409,8 +409,13 @@ fn process_change(
409409 // <---> (blamed)
410410 // <--> <-> (new hunk)
411411 if added. start > hunk. range_in_destination . start {
412- new_hunks_to_blame . push ( UnblamedHunk :: from_destination (
412+ let line_range_in_next_destination = LineRange :: with_offset (
413413 hunk. range_in_destination . start ..added. start ,
414+ * offset_in_destination,
415+ ) ;
416+
417+ new_hunks_to_blame. push ( UnblamedHunk :: from_destination (
418+ line_range_in_next_destination. into ( ) ,
414419 hunk. offset ( ) + * offset_in_destination,
415420 ) ) ;
416421 }
@@ -984,30 +989,30 @@ fn process_change_works_added_hunk_3() {
984989 & mut new_hunks_to_blame,
985990 & mut offset_in_destination,
986991 suspect,
987- Some ( UnblamedHunk :: new ( 0 .. 5 , Offset :: Added ( 0 ) ) ) ,
988- Some ( Change :: Added ( 2 .. 3 , 0 ) ) ,
992+ Some ( UnblamedHunk :: new ( 10 .. 15 , Offset :: Added ( 0 ) ) ) ,
993+ Some ( Change :: Added ( 12 .. 13 , 0 ) ) ,
989994 ) ;
990995
991996 assert_eq ! (
992997 hunk,
993998 Some ( UnblamedHunk {
994- range_in_blamed_file: 3 .. 5 ,
995- range_in_destination: 3 .. 5
999+ range_in_blamed_file: 13 .. 15 ,
1000+ range_in_destination: 13 .. 15
9961001 } )
9971002 ) ;
9981003 assert_eq ! ( change, None ) ;
9991004 assert_eq ! (
10001005 lines_blamed,
10011006 vec![ BlameEntry {
1002- range: 2 .. 3 ,
1007+ range: 12 .. 13 ,
10031008 commit_id: suspect
10041009 } ]
10051010 ) ;
10061011 assert_eq ! (
10071012 new_hunks_to_blame,
10081013 vec![ UnblamedHunk {
1009- range_in_blamed_file: 5 .. 7 ,
1010- range_in_destination: 0 .. 2
1014+ range_in_blamed_file: 10 .. 12 ,
1015+ range_in_destination: 5 .. 7
10111016 } ]
10121017 ) ;
10131018 assert_eq ! ( offset_in_destination, Offset :: Added ( 6 ) ) ;
@@ -1126,6 +1131,48 @@ fn process_change_works_added_hunk_6() {
11261131 assert_eq ! ( offset_in_destination, Offset :: Added ( 2 ) ) ;
11271132}
11281133
1134+ #[ test]
1135+ fn process_change_works_added_hunk_7 ( ) {
1136+ let mut lines_blamed: Vec < BlameEntry > = vec ! [ ] ;
1137+ let mut new_hunks_to_blame: Vec < UnblamedHunk > = vec ! [ ] ;
1138+ let mut offset_in_destination: Offset = Offset :: Added ( 2 ) ;
1139+ let suspect = ObjectId :: null ( gix_hash:: Kind :: Sha1 ) ;
1140+
1141+ let ( hunk, change) = process_change (
1142+ & mut lines_blamed,
1143+ & mut new_hunks_to_blame,
1144+ & mut offset_in_destination,
1145+ suspect,
1146+ // range_in_destination: 2..6
1147+ Some ( UnblamedHunk :: new ( 3 ..7 , Offset :: Added ( 1 ) ) ) ,
1148+ Some ( Change :: Added ( 3 ..5 , 1 ) ) ,
1149+ ) ;
1150+
1151+ assert_eq ! (
1152+ hunk,
1153+ Some ( UnblamedHunk {
1154+ range_in_blamed_file: 6 ..7 ,
1155+ range_in_destination: 5 ..6
1156+ } )
1157+ ) ;
1158+ assert_eq ! ( change, None ) ;
1159+ assert_eq ! (
1160+ lines_blamed,
1161+ vec![ BlameEntry {
1162+ range: 4 ..6 ,
1163+ commit_id: suspect
1164+ } ]
1165+ ) ;
1166+ assert_eq ! (
1167+ new_hunks_to_blame,
1168+ vec![ UnblamedHunk {
1169+ range_in_blamed_file: 3 ..4 ,
1170+ range_in_destination: 0 ..1
1171+ } ]
1172+ ) ;
1173+ assert_eq ! ( offset_in_destination, Offset :: Added ( 3 ) ) ;
1174+ }
1175+
11291176#[ test]
11301177fn process_change_works_unchanged_hunk ( ) {
11311178 let mut lines_blamed: Vec < BlameEntry > = vec ! [ ] ;
0 commit comments