@@ -565,6 +565,9 @@ fn process_change(
565
565
}
566
566
( Some ( hunk) , Some ( Change :: Deleted ( line_number_in_destination, number_of_lines_deleted) ) ) => {
567
567
if line_number_in_destination < hunk. range_in_destination . start {
568
+ // <---> (hunk)
569
+ // | (line_number_in_destination)
570
+
568
571
* offset_in_destination -= number_of_lines_deleted;
569
572
570
573
let line_range_in_next_destination =
@@ -577,6 +580,9 @@ fn process_change(
577
580
578
581
( None , None )
579
582
} else if line_number_in_destination < hunk. range_in_destination . end {
583
+ // <-----> (hunk)
584
+ // | (line_number_in_destination)
585
+
580
586
if hunk. range_in_destination . start < line_number_in_destination {
581
587
let line_range_in_next_destination = LineRange :: with_offset (
582
588
hunk. range_in_destination . start ..line_number_in_destination,
@@ -598,9 +604,21 @@ fn process_change(
598
604
599
605
( new_hunk, None )
600
606
} else {
601
- * offset_in_destination -= number_of_lines_deleted;
607
+ // <---> (hunk)
608
+ // | (line_number_in_destination)
609
+
610
+ let line_range_in_next_destination =
611
+ LineRange :: with_offset ( hunk. range_in_destination . clone ( ) , * offset_in_destination) ;
602
612
603
- ( Some ( hunk) , None )
613
+ new_hunks_to_blame. push ( UnblamedHunk :: from_destination (
614
+ line_range_in_next_destination. into ( ) ,
615
+ hunk. offset ( ) + * offset_in_destination,
616
+ ) ) ;
617
+
618
+ (
619
+ None ,
620
+ Some ( Change :: Deleted ( line_number_in_destination, number_of_lines_deleted) ) ,
621
+ )
604
622
}
605
623
}
606
624
( Some ( hunk) , None ) => {
@@ -1534,6 +1552,36 @@ fn process_change_works_no_overlap_4() {
1534
1552
assert_eq ! ( offset_in_destination, Offset :: Added ( 1 ) ) ;
1535
1553
}
1536
1554
1555
+ #[ test]
1556
+ fn process_change_works_no_overlap_5 ( ) {
1557
+ let mut lines_blamed: Vec < BlameEntry > = vec ! [ ] ;
1558
+ let mut new_hunks_to_blame: Vec < UnblamedHunk > = vec ! [ ] ;
1559
+ let mut offset_in_destination: Offset = Offset :: Added ( 1 ) ;
1560
+ let suspect = ObjectId :: null ( gix_hash:: Kind :: Sha1 ) ;
1561
+
1562
+ let ( hunk, change) = process_change (
1563
+ & mut lines_blamed,
1564
+ & mut new_hunks_to_blame,
1565
+ & mut offset_in_destination,
1566
+ suspect,
1567
+ // range_in_destination: 17..18
1568
+ Some ( UnblamedHunk :: new ( 15 ..16 , Offset :: Deleted ( 2 ) ) ) ,
1569
+ Some ( Change :: Deleted ( 20 , 1 ) ) ,
1570
+ ) ;
1571
+
1572
+ assert_eq ! ( hunk, None ) ;
1573
+ assert_eq ! ( change, Some ( Change :: Deleted ( 20 , 1 ) ) ) ;
1574
+ assert_eq ! ( lines_blamed, vec![ ] ) ;
1575
+ assert_eq ! (
1576
+ new_hunks_to_blame,
1577
+ vec![ UnblamedHunk {
1578
+ range_in_blamed_file: 15 ..16 ,
1579
+ range_in_destination: 16 ..17
1580
+ } ]
1581
+ ) ;
1582
+ assert_eq ! ( offset_in_destination, Offset :: Added ( 1 ) ) ;
1583
+ }
1584
+
1537
1585
#[ test]
1538
1586
fn process_change_works_unchanged_hunk ( ) {
1539
1587
let mut lines_blamed: Vec < BlameEntry > = vec ! [ ] ;
@@ -1652,17 +1700,17 @@ fn process_change_works_deleted_hunk() {
1652
1700
Some ( Change :: Deleted ( 5 , 3 ) ) ,
1653
1701
) ;
1654
1702
1703
+ assert_eq ! ( hunk, None ) ;
1704
+ assert_eq ! ( change, Some ( Change :: Deleted ( 5 , 3 ) ) ) ;
1705
+ assert_eq ! ( lines_blamed, vec![ ] ) ;
1655
1706
assert_eq ! (
1656
- hunk ,
1657
- Some ( UnblamedHunk {
1707
+ new_hunks_to_blame ,
1708
+ vec! [ UnblamedHunk {
1658
1709
range_in_blamed_file: 0 ..5 ,
1659
1710
range_in_destination: 0 ..5
1660
- } )
1711
+ } ]
1661
1712
) ;
1662
- assert_eq ! ( change, None ) ;
1663
- assert_eq ! ( lines_blamed, vec![ ] ) ;
1664
- assert_eq ! ( new_hunks_to_blame, vec![ ] ) ;
1665
- assert_eq ! ( offset_in_destination, Offset :: Deleted ( 3 ) ) ;
1713
+ assert_eq ! ( offset_in_destination, Offset :: Added ( 0 ) ) ;
1666
1714
}
1667
1715
1668
1716
#[ test]
0 commit comments