@@ -39,7 +39,7 @@ fn process_change(
39
39
// 3. `change` *must* be returned if it is not fully included in `hunk`.
40
40
match ( hunk, change) {
41
41
( Some ( hunk) , Some ( Change :: Unchanged ( unchanged) ) ) => {
42
- let Some ( range_in_suspect) = hunk. suspects . get ( & suspect) else {
42
+ let Some ( range_in_suspect) = hunk. get_range ( & suspect) else {
43
43
// We don’t clone blame to `parent` as `suspect` has nothing to do with this
44
44
// `hunk`.
45
45
new_hunks_to_blame. push ( hunk) ;
@@ -102,7 +102,7 @@ fn process_change(
102
102
}
103
103
}
104
104
( Some ( hunk) , Some ( Change :: AddedOrReplaced ( added, number_of_lines_deleted) ) ) => {
105
- let Some ( range_in_suspect) = hunk. suspects . get ( & suspect) . cloned ( ) else {
105
+ let Some ( range_in_suspect) = hunk. get_range ( & suspect) . cloned ( ) else {
106
106
new_hunks_to_blame. push ( hunk) ;
107
107
return ( None , Some ( Change :: AddedOrReplaced ( added, number_of_lines_deleted) ) ) ;
108
108
} ;
@@ -247,7 +247,7 @@ fn process_change(
247
247
}
248
248
}
249
249
( Some ( hunk) , Some ( Change :: Deleted ( line_number_in_destination, number_of_lines_deleted) ) ) => {
250
- let Some ( range_in_suspect) = hunk. suspects . get ( & suspect) else {
250
+ let Some ( range_in_suspect) = hunk. get_range ( & suspect) else {
251
251
new_hunks_to_blame. push ( hunk) ;
252
252
return (
253
253
None ,
@@ -359,12 +359,16 @@ fn process_changes(
359
359
360
360
impl UnblamedHunk {
361
361
fn shift_by ( mut self , suspect : ObjectId , offset : Offset ) -> Self {
362
- self . suspects . entry ( suspect) . and_modify ( |e| * e = e. shift_by ( offset) ) ;
362
+ if let Some ( position) = self . suspects . iter ( ) . position ( |entry| entry. 0 == suspect) {
363
+ if let Some ( ( _, ref mut range_in_suspect) ) = self . suspects . get_mut ( position) {
364
+ * range_in_suspect = range_in_suspect. shift_by ( offset) ;
365
+ }
366
+ }
363
367
self
364
368
}
365
369
366
370
fn split_at ( self , suspect : ObjectId , line_number_in_destination : u32 ) -> Either < Self , ( Self , Self ) > {
367
- match self . suspects . get ( & suspect) {
371
+ match self . get_range ( & suspect) {
368
372
None => Either :: Left ( self ) ,
369
373
Some ( range_in_suspect) => {
370
374
if !range_in_suspect. contains ( & line_number_in_destination) {
@@ -405,34 +409,38 @@ impl UnblamedHunk {
405
409
/// This is like [`Self::pass_blame()`], but easier to use in places where the 'passing' is
406
410
/// done 'inline'.
407
411
fn passed_blame ( mut self , from : ObjectId , to : ObjectId ) -> Self {
408
- if let Some ( range_in_suspect) = self . suspects . remove ( & from) {
409
- self . suspects . insert ( to, range_in_suspect) ;
412
+ if let Some ( position) = self . suspects . iter ( ) . position ( |entry| entry. 0 == from) {
413
+ if let Some ( ( ref mut commit_id, _) ) = self . suspects . get_mut ( position) {
414
+ * commit_id = to;
415
+ }
410
416
}
411
417
self
412
418
}
413
419
414
420
/// Transfer all ranges from the commit at `from` to the commit at `to`.
415
421
fn pass_blame ( & mut self , from : ObjectId , to : ObjectId ) {
416
- if let Some ( range_in_suspect) = self . suspects . remove ( & from) {
417
- self . suspects . insert ( to, range_in_suspect) ;
422
+ if let Some ( position) = self . suspects . iter ( ) . position ( |entry| entry. 0 == from) {
423
+ if let Some ( ( ref mut commit_id, _) ) = self . suspects . get_mut ( position) {
424
+ * commit_id = to;
425
+ }
418
426
}
419
427
}
420
428
421
429
fn clone_blame ( & mut self , from : ObjectId , to : ObjectId ) {
422
- if let Some ( range_in_suspect) = self . suspects . get ( & from) {
423
- self . suspects . insert ( to, range_in_suspect. clone ( ) ) ;
430
+ if let Some ( range_in_suspect) = self . get_range ( & from) {
431
+ self . suspects . push ( ( to, range_in_suspect. clone ( ) ) ) ;
424
432
}
425
433
}
426
434
427
435
fn remove_blame ( & mut self , suspect : ObjectId ) {
428
- self . suspects . remove ( & suspect) ;
436
+ self . suspects . retain ( |entry| entry . 0 != suspect) ;
429
437
}
430
438
}
431
439
432
440
impl BlameEntry {
433
441
/// Create an offset from a portion of the *Blamed File*.
434
442
fn from_unblamed_hunk ( unblamed_hunk : & UnblamedHunk , commit_id : ObjectId ) -> Option < Self > {
435
- let range_in_source_file = unblamed_hunk. suspects . get ( & commit_id) ?;
443
+ let range_in_source_file = unblamed_hunk. get_range ( & commit_id) ?;
436
444
437
445
Some ( Self {
438
446
start_in_blamed_file : unblamed_hunk. range_in_blamed_file . start ,
0 commit comments