@@ -73,8 +73,16 @@ pub fn file(
7373
7474    let  mut  stats = Statistics :: default ( ) ; 
7575    let  ( mut  buf,  mut  buf2,  mut  buf3)  = ( Vec :: new ( ) ,  Vec :: new ( ) ,  Vec :: new ( ) ) ; 
76-     let  blamed_file_entry_id = find_path_entry_in_commit ( & odb,  & suspect,  file_path,  & mut  buf,  & mut  buf2,  & mut  stats) ?
77-         . ok_or_else ( || Error :: FileMissing  { 
76+     let  blamed_file_entry_id = find_path_entry_in_commit ( 
77+         & odb, 
78+         & suspect, 
79+         file_path, 
80+         cache. as_ref ( ) , 
81+         & mut  buf, 
82+         & mut  buf2, 
83+         & mut  stats, 
84+     ) ?
85+     . ok_or_else ( || Error :: FileMissing  { 
7886        file_path :  file_path. to_owned ( ) , 
7987        commit_id :  suspect, 
8088    } ) ?; 
@@ -135,7 +143,15 @@ pub fn file(
135143            . filter ( |( id,  _) | * id == suspect) 
136144            . map ( |( _,  entry) | entry) ; 
137145        if  entry. is_none ( )  { 
138-             entry = find_path_entry_in_commit ( & odb,  & suspect,  file_path,  & mut  buf,  & mut  buf2,  & mut  stats) ?; 
146+             entry = find_path_entry_in_commit ( 
147+                 & odb, 
148+                 & suspect, 
149+                 file_path, 
150+                 cache. as_ref ( ) , 
151+                 & mut  buf, 
152+                 & mut  buf2, 
153+                 & mut  stats, 
154+             ) ?; 
139155        } 
140156
141157        let  Some ( entry_id)  = entry else  { 
@@ -177,9 +193,15 @@ pub fn file(
177193        } 
178194
179195        for  ( pid,  ( parent_id,  parent_commit_time) )  in  parent_ids. iter ( ) . enumerate ( )  { 
180-             if  let  Some ( parent_entry_id)  =
181-                 find_path_entry_in_commit ( & odb,  parent_id,  file_path,  & mut  buf,  & mut  buf2,  & mut  stats) ?
182-             { 
196+             if  let  Some ( parent_entry_id)  = find_path_entry_in_commit ( 
197+                 & odb, 
198+                 parent_id, 
199+                 file_path, 
200+                 cache. as_ref ( ) , 
201+                 & mut  buf, 
202+                 & mut  buf2, 
203+                 & mut  stats, 
204+             ) ? { 
183205                let  no_change_in_entry = entry_id == parent_entry_id; 
184206                if  pid == 0  { 
185207                    previous_entry = Some ( ( * parent_id,  parent_entry_id) ) ; 
@@ -200,6 +222,7 @@ pub fn file(
200222                file_path, 
201223                suspect, 
202224                parent_id, 
225+                 cache. as_ref ( ) , 
203226                & mut  stats, 
204227                & mut  diff_state, 
205228                & mut  buf, 
@@ -401,20 +424,19 @@ fn tree_diff_at_file_path(
401424    file_path :  & BStr , 
402425    id :  ObjectId , 
403426    parent_id :  ObjectId , 
427+     cache :  Option < & gix_commitgraph:: Graph > , 
404428    stats :  & mut  Statistics , 
405429    state :  & mut  gix_diff:: tree:: State , 
406430    commit_buf :  & mut  Vec < u8 > , 
407431    lhs_tree_buf :  & mut  Vec < u8 > , 
408432    rhs_tree_buf :  & mut  Vec < u8 > , 
409433)  -> Result < Option < gix_diff:: tree:: recorder:: Change > ,  Error >  { 
410-     let  parent_tree = odb. find_commit ( & parent_id,  commit_buf) ?. tree ( ) ; 
411-     stats. commits_to_tree  += 1 ; 
434+     let  parent_tree_id = tree_id ( find_commit ( cache,  & odb,  & parent_id,  commit_buf) ?) ?; 
412435
413-     let  parent_tree_iter = odb. find_tree_iter ( & parent_tree ,  lhs_tree_buf) ?; 
436+     let  parent_tree_iter = odb. find_tree_iter ( & parent_tree_id ,  lhs_tree_buf) ?; 
414437    stats. trees_decoded  += 1 ; 
415438
416-     let  tree_id = odb. find_commit ( & id,  commit_buf) ?. tree ( ) ; 
417-     stats. commits_to_tree  += 1 ; 
439+     let  tree_id = tree_id ( find_commit ( cache,  & odb,  & id,  commit_buf) ?) ?; 
418440
419441    let  tree_iter = odb. find_tree_iter ( & tree_id,  rhs_tree_buf) ?; 
420442    stats. trees_decoded  += 1 ; 
@@ -605,13 +627,13 @@ fn find_path_entry_in_commit(
605627    odb :  & impl  gix_object:: Find , 
606628    commit :  & gix_hash:: oid , 
607629    file_path :  & BStr , 
630+     cache :  Option < & gix_commitgraph:: Graph > , 
608631    buf :  & mut  Vec < u8 > , 
609632    buf2 :  & mut  Vec < u8 > , 
610633    stats :  & mut  Statistics , 
611634)  -> Result < Option < ObjectId > ,  Error >  { 
612-     let  commit_id = odb. find_commit ( commit,  buf) ?. tree ( ) ; 
613-     stats. commits_to_tree  += 1 ; 
614-     let  tree_iter = odb. find_tree_iter ( & commit_id,  buf) ?; 
635+     let  tree_id = tree_id ( find_commit ( cache,  odb,  commit,  buf) ?) ?; 
636+     let  tree_iter = odb. find_tree_iter ( & tree_id,  buf) ?; 
615637    stats. trees_decoded  += 1 ; 
616638
617639    let  res = tree_iter. lookup_entry ( 
@@ -666,6 +688,13 @@ fn collect_parents(
666688    Ok ( parent_ids) 
667689} 
668690
691+ fn  tree_id ( commit :  gix_traverse:: commit:: Either < ' _ ,  ' _ > )  -> Result < ObjectId ,  Error >  { 
692+     match  commit { 
693+         gix_traverse:: commit:: Either :: CommitRefIter ( mut  commit_ref_iter)  => Ok ( commit_ref_iter. tree_id ( ) ?) , 
694+         gix_traverse:: commit:: Either :: CachedCommit ( commit)  => Ok ( commit. root_tree_id ( ) . into ( ) ) , 
695+     } 
696+ } 
697+ 
669698/// Return an iterator over tokens for use in diffing. These are usually lines, but it's important 
670699/// to unify them so the later access shows the right thing. 
671700pub ( crate )  fn  tokens_for_diffing ( data :  & [ u8 ] )  -> impl  TokenSource < Token  = & [ u8 ] >  { 
0 commit comments