@@ -517,9 +517,9 @@ fn process_change(
517517 }
518518 }
519519 ( Some ( hunk) , Some ( Change :: Deleted ( line_number_in_destination, number_of_lines_deleted) ) ) => {
520- * offset_in_destination -= number_of_lines_deleted;
520+ if line_number_in_destination < hunk. range_in_destination . start {
521+ * offset_in_destination -= number_of_lines_deleted;
521522
522- if hunk. range_in_destination . start > line_number_in_destination {
523523 let line_range_in_next_destination =
524524 LineRange :: with_offset ( hunk. range_in_destination . clone ( ) , * offset_in_destination) ;
525525
@@ -529,7 +529,30 @@ fn process_change(
529529 ) ) ;
530530
531531 ( None , None )
532+ } else if line_number_in_destination < hunk. range_in_destination . end {
533+ if hunk. range_in_destination . start < line_number_in_destination {
534+ let line_range_in_next_destination = LineRange :: with_offset (
535+ hunk. range_in_destination . start ..line_number_in_destination,
536+ * offset_in_destination,
537+ ) ;
538+
539+ new_hunks_to_blame. push ( UnblamedHunk :: from_destination (
540+ line_range_in_next_destination. into ( ) ,
541+ hunk. offset ( ) + * offset_in_destination,
542+ ) ) ;
543+ }
544+
545+ * offset_in_destination -= number_of_lines_deleted;
546+
547+ let new_hunk = Some ( UnblamedHunk :: from_destination (
548+ line_number_in_destination..hunk. range_in_destination . end ,
549+ hunk. offset ( ) ,
550+ ) ) ;
551+
552+ ( new_hunk, None )
532553 } else {
554+ * offset_in_destination -= number_of_lines_deleted;
555+
533556 ( Some ( hunk) , None )
534557 }
535558 }
@@ -1418,6 +1441,35 @@ fn process_change_works_deleted_hunk_2() {
14181441 assert_eq ! ( offset_in_destination, Offset :: Deleted ( 4 ) ) ;
14191442}
14201443
1444+ #[ test]
1445+ fn process_change_works_deleted_hunk_3 ( ) {
1446+ let mut lines_blamed: Vec < BlameEntry > = vec ! [ ] ;
1447+ let mut new_hunks_to_blame: Vec < UnblamedHunk > = vec ! [ ] ;
1448+ let mut offset_in_destination: Offset = Offset :: Added ( 0 ) ;
1449+ let suspect = ObjectId :: null ( gix_hash:: Kind :: Sha1 ) ;
1450+
1451+ let ( hunk, change) = process_change (
1452+ & mut lines_blamed,
1453+ & mut new_hunks_to_blame,
1454+ & mut offset_in_destination,
1455+ suspect,
1456+ Some ( UnblamedHunk :: new ( 2 ..16 , Offset :: Added ( 0 ) ) ) ,
1457+ Some ( Change :: Deleted ( 14 , 4 ) ) ,
1458+ ) ;
1459+
1460+ assert_eq ! (
1461+ hunk,
1462+ Some ( UnblamedHunk {
1463+ range_in_blamed_file: 14 ..16 ,
1464+ range_in_destination: 14 ..16
1465+ } )
1466+ ) ;
1467+ assert_eq ! ( change, None ) ;
1468+ assert_eq ! ( lines_blamed, vec![ ] ) ;
1469+ assert_eq ! ( new_hunks_to_blame, vec![ UnblamedHunk :: new( 2 ..14 , Offset :: Added ( 0 ) ) ] ) ;
1470+ assert_eq ! ( offset_in_destination, Offset :: Deleted ( 4 ) ) ;
1471+ }
1472+
14211473#[ test]
14221474fn process_changes_works ( ) {
14231475 let mut lines_blamed: Vec < BlameEntry > = vec ! [ ] ;
0 commit comments