@@ -225,6 +225,12 @@ impl UnblamedHunk {
225
225
}
226
226
}
227
227
228
+ fn shift_by ( & self , offset : Offset ) -> Self {
229
+ let combined_offset = self . offset ( ) + offset;
230
+
231
+ Self :: new ( self . range_in_blamed_file . clone ( ) , combined_offset)
232
+ }
233
+
228
234
fn offset ( & self ) -> Offset {
229
235
if self . range_in_blamed_file . start > self . range_in_destination . start {
230
236
Offset :: Added ( self . range_in_blamed_file . start - self . range_in_destination . start )
@@ -327,13 +333,7 @@ pub fn process_change(
327
333
// <--------> (hunk)
328
334
// <-------> (unchanged)
329
335
330
- let line_range_in_next_destination =
331
- LineRange :: with_offset ( hunk. range_in_destination . clone ( ) , * offset_in_destination) ;
332
-
333
- new_hunks_to_blame. push ( UnblamedHunk :: from_destination (
334
- line_range_in_next_destination. into ( ) ,
335
- hunk. offset ( ) + * offset_in_destination,
336
- ) ) ;
336
+ new_hunks_to_blame. push ( hunk. shift_by ( * offset_in_destination) ) ;
337
337
338
338
( None , Some ( Change :: Unchanged ( unchanged) ) )
339
339
}
@@ -360,13 +360,7 @@ pub fn process_change(
360
360
// <---> (hunk)
361
361
// <----------> (unchanged)
362
362
363
- let line_range_in_next_destination =
364
- LineRange :: with_offset ( hunk. range_in_destination . clone ( ) , * offset_in_destination) ;
365
-
366
- new_hunks_to_blame. push ( UnblamedHunk :: from_destination (
367
- line_range_in_next_destination. into ( ) ,
368
- hunk. offset ( ) + * offset_in_destination,
369
- ) ) ;
363
+ new_hunks_to_blame. push ( hunk. shift_by ( * offset_in_destination) ) ;
370
364
371
365
( None , Some ( Change :: Unchanged ( unchanged. clone ( ) ) ) )
372
366
}
@@ -492,13 +486,7 @@ pub fn process_change(
492
486
// <--> (hunk)
493
487
// <----> (added)
494
488
495
- let line_range_in_next_destination =
496
- LineRange :: with_offset ( hunk. range_in_destination . clone ( ) , * offset_in_destination) ;
497
-
498
- new_hunks_to_blame. push ( UnblamedHunk :: from_destination (
499
- line_range_in_next_destination. into ( ) ,
500
- hunk. offset ( ) + * offset_in_destination,
501
- ) ) ;
489
+ new_hunks_to_blame. push ( hunk. shift_by ( * offset_in_destination) ) ;
502
490
503
491
( None , Some ( Change :: Added ( added. clone ( ) , number_of_lines_deleted) ) )
504
492
} else {
@@ -553,13 +541,7 @@ pub fn process_change(
553
541
// <---> (hunk)
554
542
// | (line_number_in_destination)
555
543
556
- let line_range_in_next_destination =
557
- LineRange :: with_offset ( hunk. range_in_destination . clone ( ) , * offset_in_destination) ;
558
-
559
- new_hunks_to_blame. push ( UnblamedHunk :: from_destination (
560
- line_range_in_next_destination. into ( ) ,
561
- hunk. offset ( ) + * offset_in_destination,
562
- ) ) ;
544
+ new_hunks_to_blame. push ( hunk. shift_by ( * offset_in_destination) ) ;
563
545
564
546
(
565
547
None ,
@@ -568,10 +550,7 @@ pub fn process_change(
568
550
}
569
551
}
570
552
( Some ( hunk) , None ) => {
571
- new_hunks_to_blame. push ( UnblamedHunk :: new (
572
- hunk. range_in_blamed_file . clone ( ) ,
573
- hunk. offset ( ) + * offset_in_destination,
574
- ) ) ;
553
+ new_hunks_to_blame. push ( hunk. shift_by ( * offset_in_destination) ) ;
575
554
576
555
( None , None )
577
556
}
0 commit comments