@@ -18,16 +18,18 @@ bitflags::bitflags! {
18
18
#[ derive( Debug , thiserror:: Error ) ]
19
19
#[ allow( missing_docs) ]
20
20
pub enum Error {
21
+ #[ error( "A commit could not be found" ) ]
22
+ FindExistingCommit ( #[ from] gix_object:: find:: existing_iter:: Error ) ,
21
23
#[ error( "A commit could not be decoded during traversal" ) ]
22
24
Decode ( #[ from] gix_object:: decode:: Error ) ,
23
25
}
24
26
25
27
pub ( crate ) mod function {
26
- use gix_hash:: ObjectId ;
27
- use std:: cmp:: Ordering ;
28
-
29
28
use super :: Error ;
30
29
use crate :: { merge_base:: Flags , Graph , PriorityQueue } ;
30
+ use gix_hash:: ObjectId ;
31
+ use gix_revwalk:: graph:: LazyCommit ;
32
+ use std:: cmp:: Ordering ;
31
33
32
34
/// Given a commit at `first` id, traverse the commit `graph` and return all possible merge-base between it and `others`,
33
35
/// sorted from best to worst. Returns `None` if there is no merge-base as `first` and `others` don't share history.
@@ -49,24 +51,39 @@ pub(crate) mod function {
49
51
return Ok ( Some ( vec ! [ first] ) ) ;
50
52
}
51
53
52
- graph. insert ( first, Flags :: COMMIT1 ) ;
53
- let mut queue = PriorityQueue :: from_iter ( Some ( ( GenThenTime :: max ( ) , first) ) ) ;
54
+ let mut queue = PriorityQueue :: < GenThenTime , ObjectId > :: new ( ) ;
55
+ graph. insert_data ( first, |commit| -> Result < _ , Error > {
56
+ queue. insert ( commit. try_into ( ) ?, first) ;
57
+ Ok ( Flags :: COMMIT1 )
58
+ } ) ?;
59
+
60
+ for other in others {
61
+ graph. insert_data ( * other, |commit| -> Result < _ , Error > {
62
+ queue. insert ( commit. try_into ( ) ?, * other) ;
63
+ Ok ( Flags :: COMMIT2 )
64
+ } ) ?;
65
+ }
54
66
Ok ( None )
55
67
}
56
68
69
+ // TODO(ST): Should this type be used for `describe` as well?
57
70
struct GenThenTime {
58
71
/// Note that the special [`GENERATION_NUMBER_INFINITY`](gix_commitgraph::GENERATION_NUMBER_INFINITY) is used to indicate
59
72
/// that no commitgraph is avaialble.
60
73
generation : gix_revwalk:: graph:: Generation ,
61
74
time : gix_date:: SecondsSinceUnixEpoch ,
62
75
}
63
76
64
- impl GenThenTime {
65
- fn max ( ) -> Self {
66
- Self {
67
- generation : gix_commitgraph:: GENERATION_NUMBER_INFINITY ,
68
- time : gix_date:: SecondsSinceUnixEpoch :: MAX ,
69
- }
77
+ impl TryFrom < gix_revwalk:: graph:: LazyCommit < ' _ > > for GenThenTime {
78
+ type Error = gix_object:: decode:: Error ;
79
+
80
+ fn try_from ( commit : LazyCommit < ' _ > ) -> Result < Self , Self :: Error > {
81
+ Ok ( GenThenTime {
82
+ generation : commit
83
+ . generation ( )
84
+ . unwrap_or ( gix_commitgraph:: GENERATION_NUMBER_INFINITY ) ,
85
+ time : commit. committer_timestamp ( ) ?,
86
+ } )
70
87
}
71
88
}
72
89
0 commit comments