@@ -72,21 +72,19 @@ pub fn file(
7272) -> Result < Outcome , Error > {
7373 let _span = gix_trace:: coarse!( "gix_blame::file()" , ?file_path, ?suspect) ;
7474
75- let mut current_file_path: BString = file_path. into ( ) ;
76-
7775 let mut stats = Statistics :: default ( ) ;
7876 let ( mut buf, mut buf2, mut buf3) = ( Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
7977 let blamed_file_entry_id = find_path_entry_in_commit (
8078 & odb,
8179 & suspect,
82- current_file_path . as_ref ( ) ,
80+ file_path ,
8381 cache. as_ref ( ) ,
8482 & mut buf,
8583 & mut buf2,
8684 & mut stats,
8785 ) ?
8886 . ok_or_else ( || Error :: FileMissing {
89- file_path : current_file_path . to_owned ( ) ,
87+ file_path : file_path . to_owned ( ) ,
9088 commit_id : suspect,
9189 } ) ?;
9290 let blamed_file_blob = odb. find_blob ( & blamed_file_entry_id, & mut buf) ?. data . to_vec ( ) ;
@@ -123,13 +121,22 @@ pub fn file(
123121 break ;
124122 }
125123
126- let is_still_suspect = hunks_to_blame. iter ( ) . any ( |hunk| hunk. has_suspect ( & suspect) ) ;
124+ let first_hunk_for_suspect = hunks_to_blame. iter ( ) . find ( |hunk| hunk. has_suspect ( & suspect) ) ;
125+ let is_still_suspect = first_hunk_for_suspect. is_some ( ) ;
127126 if !is_still_suspect {
128127 // There are no `UnblamedHunk`s associated with this `suspect`, so we can continue with
129128 // the next one.
130129 continue ' outer;
131130 }
132131
132+ // We know `first_hunk_for_suspect` can’t be `None` here because we check `is_some()`
133+ // above.
134+ let current_file_path: BString = first_hunk_for_suspect
135+ . unwrap ( )
136+ . source_file_name
137+ . clone ( )
138+ . unwrap_or_else ( || file_path. to_owned ( ) ) ;
139+
133140 let commit = find_commit ( cache. as_ref ( ) , & odb, & suspect, & mut buf) ?;
134141 let commit_time = commit. commit_time ( ) ?;
135142
@@ -285,7 +292,7 @@ pub fn file(
285292 resource_cache,
286293 id,
287294 previous_id,
288- current_file_path . as_ref ( ) ,
295+ file_path ,
289296 options. diff_algorithm ,
290297 & mut stats,
291298 ) ?;
@@ -301,7 +308,7 @@ pub fn file(
301308 resource_cache,
302309 id,
303310 source_id,
304- current_file_path . as_ref ( ) ,
311+ file_path ,
305312 options. diff_algorithm ,
306313 & mut stats,
307314 ) ?;
@@ -312,8 +319,6 @@ pub fn file(
312319 hunk. source_file_name = Some ( source_location. clone ( ) ) ;
313320 }
314321 }
315-
316- current_file_path = source_location;
317322 }
318323 }
319324 }
0 commit comments