@@ -356,26 +356,13 @@ fn process_change(
356
356
&& unchanged. end <= hunk. range_in_destination . end ,
357
357
) {
358
358
( _, true ) => {
359
- let line_range_in_next_destination = LineRange :: with_offset (
360
- ( unchanged. start . max ( hunk. range_in_destination . start ) ) ..unchanged. end ,
361
- * offset_in_destination,
362
- ) ;
363
-
364
- new_hunks_to_blame. push ( UnblamedHunk :: from_destination (
365
- line_range_in_next_destination. into ( ) ,
366
- hunk. offset ( ) + * offset_in_destination,
367
- ) ) ;
368
-
369
- let new_hunk = if hunk. range_in_destination . end > unchanged. end {
370
- Some ( UnblamedHunk :: from_destination (
371
- unchanged. end ..hunk. range_in_destination . end ,
372
- hunk. offset ( ) ,
373
- ) )
374
- } else {
375
- None
376
- } ;
359
+ // <------> (hunk)
360
+ // <-------> (unchanged)
361
+ //
362
+ // <----------> (hunk)
363
+ // <---> (unchanged)
377
364
378
- ( new_hunk , None )
365
+ ( Some ( hunk ) , None )
379
366
}
380
367
( true , false ) => {
381
368
// <--------> (hunk)
@@ -488,24 +475,17 @@ fn process_change(
488
475
) ) ;
489
476
}
490
477
491
- * offset_in_destination += added. end - added. start ;
492
- * offset_in_destination -= number_of_lines_deleted;
493
-
494
478
lines_blamed. push ( BlameEntry :: with_offset (
495
479
added. start ..hunk. range_in_destination . end ,
496
480
suspect,
497
481
hunk. offset ( ) ,
498
482
) ) ;
499
483
500
- let new_change = if added. end > hunk. range_in_destination . end {
501
- let line_range = hunk. range_in_destination . end ..added. end ;
502
-
503
- Some ( Change :: Added ( line_range, number_of_lines_deleted) )
484
+ if added. end > hunk. range_in_destination . end {
485
+ ( None , Some ( Change :: Added ( added, number_of_lines_deleted) ) )
504
486
} else {
505
487
todo ! ( ) ;
506
- } ;
507
-
508
- ( None , new_change)
488
+ }
509
489
}
510
490
( false , true ) => {
511
491
// <-------> (hunk)
@@ -1398,7 +1378,7 @@ fn process_change_works_added_hunk_8() {
1398
1378
) ;
1399
1379
1400
1380
assert_eq ! ( hunk, None ) ;
1401
- assert_eq ! ( change, Some ( Change :: Added ( 26 ..27 , 1 ) ) ) ;
1381
+ assert_eq ! ( change, Some ( Change :: Added ( 25 ..27 , 1 ) ) ) ;
1402
1382
assert_eq ! (
1403
1383
lines_blamed,
1404
1384
vec![ BlameEntry {
@@ -1408,7 +1388,7 @@ fn process_change_works_added_hunk_8() {
1408
1388
} ]
1409
1389
) ;
1410
1390
assert_eq ! ( new_hunks_to_blame, vec![ ] ) ;
1411
- assert_eq ! ( offset_in_destination, Offset :: Added ( 2 ) ) ;
1391
+ assert_eq ! ( offset_in_destination, Offset :: Added ( 1 ) ) ;
1412
1392
}
1413
1393
1414
1394
#[ test]
@@ -1442,6 +1422,80 @@ fn process_change_works_added_hunk_9() {
1442
1422
assert_eq ! ( offset_in_destination, Offset :: Added ( 1 ) ) ;
1443
1423
}
1444
1424
1425
+ #[ test]
1426
+ fn process_change_works_added_hunk_10 ( ) {
1427
+ let mut lines_blamed: Vec < BlameEntry > = vec ! [ ] ;
1428
+ let mut new_hunks_to_blame: Vec < UnblamedHunk > = vec ! [ ] ;
1429
+ let mut offset_in_destination: Offset = Offset :: Added ( 0 ) ;
1430
+ let suspect = ObjectId :: null ( gix_hash:: Kind :: Sha1 ) ;
1431
+
1432
+ let ( hunk, change) = process_change (
1433
+ & mut lines_blamed,
1434
+ & mut new_hunks_to_blame,
1435
+ & mut offset_in_destination,
1436
+ suspect,
1437
+ // range_in_destination: 70..108
1438
+ Some ( UnblamedHunk :: new ( 71 ..109 , Offset :: Added ( 1 ) ) ) ,
1439
+ Some ( Change :: Added ( 106 ..109 , 0 ) ) ,
1440
+ ) ;
1441
+
1442
+ assert_eq ! ( hunk, None ) ;
1443
+ assert_eq ! ( change, Some ( Change :: Added ( 106 ..109 , 0 ) ) ) ;
1444
+ assert_eq ! (
1445
+ lines_blamed,
1446
+ vec![ BlameEntry {
1447
+ range_in_blamed_file: 107 ..109 ,
1448
+ range_in_original_file: 106 ..108 ,
1449
+ commit_id: suspect
1450
+ } ]
1451
+ ) ;
1452
+ assert_eq ! (
1453
+ new_hunks_to_blame,
1454
+ vec![ UnblamedHunk {
1455
+ range_in_blamed_file: 71 ..107 ,
1456
+ range_in_destination: 70 ..106
1457
+ } ]
1458
+ ) ;
1459
+ assert_eq ! ( offset_in_destination, Offset :: Added ( 0 ) ) ;
1460
+ }
1461
+
1462
+ #[ test]
1463
+ fn process_change_works_added_hunk_11 ( ) {
1464
+ let mut lines_blamed: Vec < BlameEntry > = vec ! [ ] ;
1465
+ let mut new_hunks_to_blame: Vec < UnblamedHunk > = vec ! [ ] ;
1466
+ let mut offset_in_destination: Offset = Offset :: Added ( 0 ) ;
1467
+ let suspect = ObjectId :: null ( gix_hash:: Kind :: Sha1 ) ;
1468
+
1469
+ let ( hunk, change) = process_change (
1470
+ & mut lines_blamed,
1471
+ & mut new_hunks_to_blame,
1472
+ & mut offset_in_destination,
1473
+ suspect,
1474
+ // range_in_destination: 137..144
1475
+ Some ( UnblamedHunk :: new ( 149 ..156 , Offset :: Added ( 12 ) ) ) ,
1476
+ Some ( Change :: Added ( 143 ..146 , 0 ) ) ,
1477
+ ) ;
1478
+
1479
+ assert_eq ! ( hunk, None ) ;
1480
+ assert_eq ! ( change, Some ( Change :: Added ( 143 ..146 , 0 ) ) ) ;
1481
+ assert_eq ! (
1482
+ lines_blamed,
1483
+ vec![ BlameEntry {
1484
+ range_in_blamed_file: 155 ..156 ,
1485
+ range_in_original_file: 143 ..144 ,
1486
+ commit_id: suspect
1487
+ } ]
1488
+ ) ;
1489
+ assert_eq ! (
1490
+ new_hunks_to_blame,
1491
+ vec![ UnblamedHunk {
1492
+ range_in_blamed_file: 149 ..155 ,
1493
+ range_in_destination: 137 ..143
1494
+ } ]
1495
+ ) ;
1496
+ assert_eq ! ( offset_in_destination, Offset :: Added ( 0 ) ) ;
1497
+ }
1498
+
1445
1499
#[ test]
1446
1500
fn process_change_works_no_overlap ( ) {
1447
1501
let mut lines_blamed: Vec < BlameEntry > = vec ! [ ] ;
@@ -1738,19 +1792,13 @@ fn process_change_works_unchanged_hunk() {
1738
1792
assert_eq ! (
1739
1793
hunk,
1740
1794
Some ( UnblamedHunk {
1741
- range_in_blamed_file: 3 ..5 ,
1742
- range_in_destination: 3 ..5
1795
+ range_in_blamed_file: 0 ..5 ,
1796
+ range_in_destination: 0 ..5
1743
1797
} )
1744
1798
) ;
1745
1799
assert_eq ! ( change, None ) ;
1746
1800
assert_eq ! ( lines_blamed, vec![ ] ) ;
1747
- assert_eq ! (
1748
- new_hunks_to_blame,
1749
- vec![ UnblamedHunk {
1750
- range_in_blamed_file: 0 ..3 ,
1751
- range_in_destination: 0 ..3
1752
- } ]
1753
- ) ;
1801
+ assert_eq ! ( new_hunks_to_blame, vec![ ] ) ;
1754
1802
assert_eq ! ( offset_in_destination, Offset :: Added ( 0 ) ) ;
1755
1803
}
1756
1804
@@ -1805,19 +1853,13 @@ fn process_change_works_unchanged_hunk_3() {
1805
1853
assert_eq ! (
1806
1854
hunk,
1807
1855
Some ( UnblamedHunk {
1808
- range_in_blamed_file: 24 ..30 ,
1809
- range_in_destination: 23 ..29
1856
+ range_in_blamed_file: 22 ..30 ,
1857
+ range_in_destination: 21 ..29 ,
1810
1858
} )
1811
1859
) ;
1812
1860
assert_eq ! ( change, None ) ;
1813
1861
assert_eq ! ( lines_blamed, vec![ ] ) ;
1814
- assert_eq ! (
1815
- new_hunks_to_blame,
1816
- vec![ UnblamedHunk {
1817
- range_in_blamed_file: 22 ..24 ,
1818
- range_in_destination: 23 ..25
1819
- } ]
1820
- ) ;
1862
+ assert_eq ! ( new_hunks_to_blame, vec![ ] ) ;
1821
1863
assert_eq ! ( offset_in_destination, Offset :: Deleted ( 2 ) ) ;
1822
1864
}
1823
1865
0 commit comments