@@ -18,16 +18,18 @@ bitflags::bitflags! {
1818#[ derive( Debug , thiserror:: Error ) ]
1919#[ allow( missing_docs) ]
2020pub enum Error {
21+ #[ error( "A commit could not be found" ) ]
22+ FindExistingCommit ( #[ from] gix_object:: find:: existing_iter:: Error ) ,
2123 #[ error( "A commit could not be decoded during traversal" ) ]
2224 Decode ( #[ from] gix_object:: decode:: Error ) ,
2325}
2426
2527pub ( crate ) mod function {
26- use gix_hash:: ObjectId ;
27- use std:: cmp:: Ordering ;
28-
2928 use super :: Error ;
3029 use crate :: { merge_base:: Flags , Graph , PriorityQueue } ;
30+ use gix_hash:: ObjectId ;
31+ use gix_revwalk:: graph:: LazyCommit ;
32+ use std:: cmp:: Ordering ;
3133
3234 /// Given a commit at `first` id, traverse the commit `graph` and return all possible merge-base between it and `others`,
3335 /// 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 {
4951 return Ok ( Some ( vec ! [ first] ) ) ;
5052 }
5153
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+ }
5466 Ok ( None )
5567 }
5668
69+ // TODO(ST): Should this type be used for `describe` as well?
5770 struct GenThenTime {
5871 /// Note that the special [`GENERATION_NUMBER_INFINITY`](gix_commitgraph::GENERATION_NUMBER_INFINITY) is used to indicate
5972 /// that no commitgraph is avaialble.
6073 generation : gix_revwalk:: graph:: Generation ,
6174 time : gix_date:: SecondsSinceUnixEpoch ,
6275 }
6376
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+ } )
7087 }
7188 }
7289
0 commit comments