@@ -356,26 +356,13 @@ fn process_change(
356356 && unchanged. end <= hunk. range_in_destination . end ,
357357 ) {
358358 ( _, 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)
377364
378- ( new_hunk , None )
365+ ( Some ( hunk ) , None )
379366 }
380367 ( true , false ) => {
381368 // <--------> (hunk)
@@ -488,24 +475,17 @@ fn process_change(
488475 ) ) ;
489476 }
490477
491- * offset_in_destination += added. end - added. start ;
492- * offset_in_destination -= number_of_lines_deleted;
493-
494478 lines_blamed. push ( BlameEntry :: with_offset (
495479 added. start ..hunk. range_in_destination . end ,
496480 suspect,
497481 hunk. offset ( ) ,
498482 ) ) ;
499483
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) ) )
504486 } else {
505487 todo ! ( ) ;
506- } ;
507-
508- ( None , new_change)
488+ }
509489 }
510490 ( false , true ) => {
511491 // <-------> (hunk)
@@ -1398,7 +1378,7 @@ fn process_change_works_added_hunk_8() {
13981378 ) ;
13991379
14001380 assert_eq ! ( hunk, None ) ;
1401- assert_eq ! ( change, Some ( Change :: Added ( 26 ..27 , 1 ) ) ) ;
1381+ assert_eq ! ( change, Some ( Change :: Added ( 25 ..27 , 1 ) ) ) ;
14021382 assert_eq ! (
14031383 lines_blamed,
14041384 vec![ BlameEntry {
@@ -1408,7 +1388,7 @@ fn process_change_works_added_hunk_8() {
14081388 } ]
14091389 ) ;
14101390 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 ) ) ;
14121392}
14131393
14141394#[ test]
@@ -1442,6 +1422,80 @@ fn process_change_works_added_hunk_9() {
14421422 assert_eq ! ( offset_in_destination, Offset :: Added ( 1 ) ) ;
14431423}
14441424
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+
14451499#[ test]
14461500fn process_change_works_no_overlap ( ) {
14471501 let mut lines_blamed: Vec < BlameEntry > = vec ! [ ] ;
@@ -1738,19 +1792,13 @@ fn process_change_works_unchanged_hunk() {
17381792 assert_eq ! (
17391793 hunk,
17401794 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
17431797 } )
17441798 ) ;
17451799 assert_eq ! ( change, None ) ;
17461800 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![ ] ) ;
17541802 assert_eq ! ( offset_in_destination, Offset :: Added ( 0 ) ) ;
17551803}
17561804
@@ -1805,19 +1853,13 @@ fn process_change_works_unchanged_hunk_3() {
18051853 assert_eq ! (
18061854 hunk,
18071855 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 ,
18101858 } )
18111859 ) ;
18121860 assert_eq ! ( change, None ) ;
18131861 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![ ] ) ;
18211863 assert_eq ! ( offset_in_destination, Offset :: Deleted ( 2 ) ) ;
18221864}
18231865
0 commit comments