@@ -659,6 +659,40 @@ fn get_changes_for_file_path(
659659 . collect ( )
660660}
661661
662+ fn get_changes (
663+ odb : impl gix_object:: Find + gix_object:: FindHeader ,
664+ resource_cache : & mut gix_diff:: blob:: Platform ,
665+ oid : ObjectId ,
666+ previous_oid : ObjectId ,
667+ file_path : & BStr ,
668+ ) -> Vec < Change > {
669+ resource_cache
670+ . set_resource (
671+ previous_oid,
672+ gix_object:: tree:: EntryKind :: Blob ,
673+ file_path,
674+ gix_diff:: blob:: ResourceKind :: OldOrSource ,
675+ & odb,
676+ )
677+ . unwrap ( ) ;
678+ resource_cache
679+ . set_resource (
680+ oid,
681+ gix_object:: tree:: EntryKind :: Blob ,
682+ file_path,
683+ gix_diff:: blob:: ResourceKind :: NewOrDestination ,
684+ & odb,
685+ )
686+ . unwrap ( ) ;
687+
688+ let outcome = resource_cache. prepare_diff ( ) . unwrap ( ) ;
689+ let input = outcome. interned_input ( ) ;
690+ let number_of_lines_in_destination = input. after . len ( ) ;
691+ let change_recorder = ChangeRecorder :: new ( number_of_lines_in_destination. try_into ( ) . unwrap ( ) ) ;
692+
693+ gix_diff:: blob:: diff ( gix_diff:: blob:: Algorithm :: Histogram , & input, change_recorder)
694+ }
695+
662696/// This function merges adjacent blame entries. It merges entries that are adjacent both in the
663697/// blamed file and in the original file that introduced them. This follows `git`’s
664698/// behaviour. `libgit2`, as of 2024-09-19, only checks whether two entries are adjacent in the
@@ -804,30 +838,7 @@ pub fn blame_file<E>(
804838 }
805839 } ;
806840
807- resource_cache
808- . set_resource (
809- * previous_oid,
810- gix_object:: tree:: EntryKind :: Blob ,
811- file_path,
812- gix_diff:: blob:: ResourceKind :: OldOrSource ,
813- & odb,
814- )
815- . unwrap ( ) ;
816- resource_cache
817- . set_resource (
818- * oid,
819- gix_object:: tree:: EntryKind :: Blob ,
820- file_path,
821- gix_diff:: blob:: ResourceKind :: NewOrDestination ,
822- & odb,
823- )
824- . unwrap ( ) ;
825-
826- let outcome = resource_cache. prepare_diff ( ) . unwrap ( ) ;
827- let input = outcome. interned_input ( ) ;
828- let number_of_lines_in_destination = input. after . len ( ) ;
829- let change_recorder = ChangeRecorder :: new ( number_of_lines_in_destination. try_into ( ) . unwrap ( ) ) ;
830- let changes = gix_diff:: blob:: diff ( gix_diff:: blob:: Algorithm :: Histogram , & input, change_recorder) ;
841+ let changes = get_changes ( & odb, resource_cache, * oid, * previous_oid, file_path) ;
831842 lines_to_blame = process_changes ( & mut out, & lines_to_blame, & changes, suspect) ;
832843 }
833844
0 commit comments