@@ -73,8 +73,16 @@ pub fn file(
73
73
74
74
let mut stats = Statistics :: default ( ) ;
75
75
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 {
78
86
file_path : file_path. to_owned ( ) ,
79
87
commit_id : suspect,
80
88
} ) ?;
@@ -135,7 +143,15 @@ pub fn file(
135
143
. filter ( |( id, _) | * id == suspect)
136
144
. map ( |( _, entry) | entry) ;
137
145
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
+ ) ?;
139
155
}
140
156
141
157
let Some ( entry_id) = entry else {
@@ -177,9 +193,15 @@ pub fn file(
177
193
}
178
194
179
195
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
+ ) ? {
183
205
let no_change_in_entry = entry_id == parent_entry_id;
184
206
if pid == 0 {
185
207
previous_entry = Some ( ( * parent_id, parent_entry_id) ) ;
@@ -200,6 +222,7 @@ pub fn file(
200
222
file_path,
201
223
suspect,
202
224
parent_id,
225
+ cache. as_ref ( ) ,
203
226
& mut stats,
204
227
& mut diff_state,
205
228
& mut buf,
@@ -401,20 +424,19 @@ fn tree_diff_at_file_path(
401
424
file_path : & BStr ,
402
425
id : ObjectId ,
403
426
parent_id : ObjectId ,
427
+ cache : Option < & gix_commitgraph:: Graph > ,
404
428
stats : & mut Statistics ,
405
429
state : & mut gix_diff:: tree:: State ,
406
430
commit_buf : & mut Vec < u8 > ,
407
431
lhs_tree_buf : & mut Vec < u8 > ,
408
432
rhs_tree_buf : & mut Vec < u8 > ,
409
433
) -> 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) ?) ?;
412
435
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) ?;
414
437
stats. trees_decoded += 1 ;
415
438
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) ?) ?;
418
440
419
441
let tree_iter = odb. find_tree_iter ( & tree_id, rhs_tree_buf) ?;
420
442
stats. trees_decoded += 1 ;
@@ -605,13 +627,13 @@ fn find_path_entry_in_commit(
605
627
odb : & impl gix_object:: Find ,
606
628
commit : & gix_hash:: oid ,
607
629
file_path : & BStr ,
630
+ cache : Option < & gix_commitgraph:: Graph > ,
608
631
buf : & mut Vec < u8 > ,
609
632
buf2 : & mut Vec < u8 > ,
610
633
stats : & mut Statistics ,
611
634
) -> 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) ?;
615
637
stats. trees_decoded += 1 ;
616
638
617
639
let res = tree_iter. lookup_entry (
@@ -666,6 +688,13 @@ fn collect_parents(
666
688
Ok ( parent_ids)
667
689
}
668
690
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
+
669
698
/// Return an iterator over tokens for use in diffing. These are usually lines, but it's important
670
699
/// to unify them so the later access shows the right thing.
671
700
pub ( crate ) fn tokens_for_diffing ( data : & [ u8 ] ) -> impl TokenSource < Token = & [ u8 ] > {
0 commit comments