1
+ use gix_object:: FindExt ;
1
2
use smallvec:: SmallVec ;
2
3
3
4
/// An iterator over the ancestors one or more starting commits
4
5
pub struct Ancestors < Find , Predicate , StateMut > {
5
- find : Find ,
6
+ objects : Find ,
6
7
cache : Option < gix_commitgraph:: Graph > ,
7
8
predicate : Predicate ,
8
9
state : StateMut ,
@@ -95,7 +96,7 @@ pub mod ancestors {
95
96
use gix_date:: SecondsSinceUnixEpoch ;
96
97
use gix_hash:: { oid, ObjectId } ;
97
98
use gix_hashtable:: HashSet ;
98
- use gix_object:: CommitRefIter ;
99
+ use gix_object:: { CommitRefIter , FindExt } ;
99
100
use smallvec:: SmallVec ;
100
101
101
102
use crate :: commit:: { collect_parents, Ancestors , Either , Info , ParentIds , Parents , Sorting } ;
@@ -104,11 +105,8 @@ pub mod ancestors {
104
105
#[ derive( Debug , thiserror:: Error ) ]
105
106
#[ allow( missing_docs) ]
106
107
pub enum Error {
107
- #[ error( "The commit {oid} could not be found" ) ]
108
- FindExisting {
109
- oid : ObjectId ,
110
- source : Box < dyn std:: error:: Error + Send + Sync + ' static > ,
111
- } ,
108
+ #[ error( transparent) ]
109
+ Find ( #[ from] gix_object:: find:: existing_iter:: Error ) ,
112
110
#[ error( transparent) ]
113
111
ObjectDecode ( #[ from] gix_object:: decode:: Error ) ,
114
112
}
@@ -147,11 +145,10 @@ pub mod ancestors {
147
145
}
148
146
149
147
/// Builder
150
- impl < Find , Predicate , StateMut , E > Ancestors < Find , Predicate , StateMut >
148
+ impl < Find , Predicate , StateMut > Ancestors < Find , Predicate , StateMut >
151
149
where
152
- Find : for < ' a > FnMut ( & oid , & ' a mut Vec < u8 > ) -> Result < CommitRefIter < ' a > , E > ,
150
+ Find : gix_object :: Find ,
153
151
StateMut : BorrowMut < State > ,
154
- E : std:: error:: Error + Send + Sync + ' static ,
155
152
{
156
153
/// Set the sorting method, either topological or by author date
157
154
pub fn sorting ( mut self , sorting : Sorting ) -> Result < Self , Error > {
@@ -164,11 +161,7 @@ pub mod ancestors {
164
161
let cutoff_time = self . sorting . cutoff_time ( ) ;
165
162
let state = self . state . borrow_mut ( ) ;
166
163
for commit_id in state. next . drain ( ..) {
167
- let commit_iter =
168
- ( self . find ) ( & commit_id, & mut state. buf ) . map_err ( |err| Error :: FindExisting {
169
- oid : commit_id,
170
- source : err. into ( ) ,
171
- } ) ?;
164
+ let commit_iter = self . objects . find_commit_iter ( & commit_id, & mut state. buf ) ?;
172
165
let time = commit_iter. committer ( ) ?. time . seconds ;
173
166
match cutoff_time {
174
167
Some ( cutoff_time) if time >= cutoff_time => {
@@ -214,11 +207,10 @@ pub mod ancestors {
214
207
}
215
208
216
209
/// Initialization
217
- impl < Find , StateMut , E > Ancestors < Find , fn ( & oid ) -> bool , StateMut >
210
+ impl < Find , StateMut > Ancestors < Find , fn ( & oid ) -> bool , StateMut >
218
211
where
219
- Find : for < ' a > FnMut ( & oid , & ' a mut Vec < u8 > ) -> Result < CommitRefIter < ' a > , E > ,
212
+ Find : gix_object :: Find ,
220
213
StateMut : BorrowMut < State > ,
221
- E : std:: error:: Error + Send + Sync + ' static ,
222
214
{
223
215
/// Create a new instance.
224
216
///
@@ -236,12 +228,11 @@ pub mod ancestors {
236
228
}
237
229
238
230
/// Initialization
239
- impl < Find , Predicate , StateMut , E > Ancestors < Find , Predicate , StateMut >
231
+ impl < Find , Predicate , StateMut > Ancestors < Find , Predicate , StateMut >
240
232
where
241
- Find : for < ' a > FnMut ( & oid , & ' a mut Vec < u8 > ) -> Result < CommitRefIter < ' a > , E > ,
233
+ Find : gix_object :: Find ,
242
234
Predicate : FnMut ( & oid ) -> bool ,
243
235
StateMut : BorrowMut < State > ,
244
- E : std:: error:: Error + Send + Sync + ' static ,
245
236
{
246
237
/// Create a new instance with commit filtering enabled.
247
238
///
@@ -274,7 +265,7 @@ pub mod ancestors {
274
265
}
275
266
}
276
267
Self {
277
- find,
268
+ objects : find,
278
269
cache : None ,
279
270
predicate,
280
271
state,
@@ -299,12 +290,11 @@ pub mod ancestors {
299
290
}
300
291
}
301
292
302
- impl < Find , Predicate , StateMut , E > Iterator for Ancestors < Find , Predicate , StateMut >
293
+ impl < Find , Predicate , StateMut > Iterator for Ancestors < Find , Predicate , StateMut >
303
294
where
304
- Find : for < ' a > FnMut ( & oid , & ' a mut Vec < u8 > ) -> Result < CommitRefIter < ' a > , E > ,
295
+ Find : gix_object :: Find ,
305
296
Predicate : FnMut ( & oid ) -> bool ,
306
297
StateMut : BorrowMut < State > ,
307
- E : std:: error:: Error + Send + Sync + ' static ,
308
298
{
309
299
type Item = Result < Info , Error > ;
310
300
@@ -334,12 +324,11 @@ pub mod ancestors {
334
324
}
335
325
336
326
/// Utilities
337
- impl < Find , Predicate , StateMut , E > Ancestors < Find , Predicate , StateMut >
327
+ impl < Find , Predicate , StateMut > Ancestors < Find , Predicate , StateMut >
338
328
where
339
- Find : for < ' a > FnMut ( & oid , & ' a mut Vec < u8 > ) -> Result < CommitRefIter < ' a > , E > ,
329
+ Find : gix_object :: Find ,
340
330
Predicate : FnMut ( & oid ) -> bool ,
341
331
StateMut : BorrowMut < State > ,
342
- E : std:: error:: Error + Send + Sync + ' static ,
343
332
{
344
333
fn next_by_commit_date (
345
334
& mut self ,
@@ -349,7 +338,7 @@ pub mod ancestors {
349
338
350
339
let ( commit_time, oid) = state. queue . pop ( ) ?;
351
340
let mut parents: ParentIds = Default :: default ( ) ;
352
- match super :: find ( self . cache . as_ref ( ) , & mut self . find , & oid, & mut state. buf ) {
341
+ match super :: find ( self . cache . as_ref ( ) , & self . objects , & oid, & mut state. buf ) {
353
342
Ok ( Either :: CachedCommit ( commit) ) => {
354
343
if !collect_parents ( & mut state. parent_ids , self . cache . as_ref ( ) , commit. iter_parents ( ) ) {
355
344
// drop corrupt caches and try again with ODB
@@ -380,7 +369,7 @@ pub mod ancestors {
380
369
continue ;
381
370
}
382
371
383
- let parent = ( self . find ) ( id. as_ref ( ) , & mut state. parents_buf ) . ok ( ) ;
372
+ let parent = self . objects . find_commit_iter ( id. as_ref ( ) , & mut state. parents_buf ) . ok ( ) ;
384
373
let parent_commit_time = parent
385
374
. and_then ( |parent| parent. committer ( ) . ok ( ) . map ( |committer| committer. time . seconds ) )
386
375
. unwrap_or_default ( ) ;
@@ -395,12 +384,7 @@ pub mod ancestors {
395
384
}
396
385
}
397
386
}
398
- Err ( err) => {
399
- return Some ( Err ( Error :: FindExisting {
400
- oid,
401
- source : err. into ( ) ,
402
- } ) )
403
- }
387
+ Err ( err) => return Some ( Err ( err. into ( ) ) ) ,
404
388
}
405
389
Some ( Ok ( Info {
406
390
id : oid,
@@ -411,18 +395,17 @@ pub mod ancestors {
411
395
}
412
396
413
397
/// Utilities
414
- impl < Find , Predicate , StateMut , E > Ancestors < Find , Predicate , StateMut >
398
+ impl < Find , Predicate , StateMut > Ancestors < Find , Predicate , StateMut >
415
399
where
416
- Find : for < ' a > FnMut ( & oid , & ' a mut Vec < u8 > ) -> Result < CommitRefIter < ' a > , E > ,
400
+ Find : gix_object :: Find ,
417
401
Predicate : FnMut ( & oid ) -> bool ,
418
402
StateMut : BorrowMut < State > ,
419
- E : std:: error:: Error + Send + Sync + ' static ,
420
403
{
421
404
fn next_by_topology ( & mut self ) -> Option < Result < Info , Error > > {
422
405
let state = self . state . borrow_mut ( ) ;
423
406
let oid = state. next . pop_front ( ) ?;
424
407
let mut parents: ParentIds = Default :: default ( ) ;
425
- match super :: find ( self . cache . as_ref ( ) , & mut self . find , & oid, & mut state. buf ) {
408
+ match super :: find ( self . cache . as_ref ( ) , & self . objects , & oid, & mut state. buf ) {
426
409
Ok ( Either :: CachedCommit ( commit) ) => {
427
410
if !collect_parents ( & mut state. parent_ids , self . cache . as_ref ( ) , commit. iter_parents ( ) ) {
428
411
// drop corrupt caches and try again with ODB
@@ -460,12 +443,7 @@ pub mod ancestors {
460
443
}
461
444
}
462
445
}
463
- Err ( err) => {
464
- return Some ( Err ( Error :: FindExisting {
465
- oid,
466
- source : err. into ( ) ,
467
- } ) )
468
- }
446
+ Err ( err) => return Some ( Err ( err. into ( ) ) ) ,
469
447
}
470
448
Some ( Ok ( Info {
471
449
id : oid,
@@ -503,18 +481,17 @@ fn collect_parents(
503
481
true
504
482
}
505
483
506
- fn find < ' cache , ' buf , Find , E > (
484
+ fn find < ' cache , ' buf , Find > (
507
485
cache : Option < & ' cache gix_commitgraph:: Graph > ,
508
- mut find : Find ,
486
+ objects : Find ,
509
487
id : & gix_hash:: oid ,
510
488
buf : & ' buf mut Vec < u8 > ,
511
- ) -> Result < Either < ' buf , ' cache > , E >
489
+ ) -> Result < Either < ' buf , ' cache > , gix_object :: find :: existing_iter :: Error >
512
490
where
513
- Find : for < ' a > FnMut ( & gix_hash:: oid , & ' a mut Vec < u8 > ) -> Result < gix_object:: CommitRefIter < ' a > , E > ,
514
- E : std:: error:: Error + Send + Sync + ' static ,
491
+ Find : gix_object:: Find ,
515
492
{
516
493
match cache. and_then ( |cache| cache. commit_by_id ( id) . map ( Either :: CachedCommit ) ) {
517
494
Some ( c) => Ok ( c) ,
518
- None => find ( id, buf) . map ( Either :: CommitRefIter ) ,
495
+ None => objects . find_commit_iter ( id, buf) . map ( Either :: CommitRefIter ) ,
519
496
}
520
497
}
0 commit comments