@@ -144,15 +144,16 @@ where
144
144
}
145
145
146
146
pub ( crate ) mod function {
147
- use std:: { borrow:: Cow , cmp:: Ordering , collections :: VecDeque , iter :: FromIterator } ;
147
+ use std:: { borrow:: Cow , cmp:: Ordering } ;
148
148
149
149
use bstr:: BStr ;
150
150
use gix_hash:: oid;
151
151
use gix_hashtable:: { hash_map, HashMap } ;
152
152
use gix_object:: CommitRefIter ;
153
153
154
154
use super :: { Error , Outcome } ;
155
- use crate :: describe:: { Flags , Options , MAX_CANDIDATES } ;
155
+ use crate :: describe:: { CommitTime , Flags , Options , MAX_CANDIDATES } ;
156
+ use crate :: PriorityQueue ;
156
157
157
158
/// Given a `commit` id, traverse the commit graph and collect candidate names from the `name_by_oid` mapping to produce
158
159
/// an `Outcome`, which converted [`into_format()`][Outcome::into_format()] will produce a typical `git describe` string.
@@ -201,14 +202,14 @@ pub(crate) mod function {
201
202
let mut buf = Vec :: new ( ) ;
202
203
let mut parent_buf = Vec :: new ( ) ;
203
204
204
- let mut queue = VecDeque :: from_iter ( Some ( ( commit. to_owned ( ) , u32 :: MAX ) ) ) ;
205
+ let mut queue = PriorityQueue :: from_iter ( Some ( ( u32 :: MAX , commit. to_owned ( ) ) ) ) ;
205
206
let mut candidates = Vec :: new ( ) ;
206
207
let mut commits_seen = 0 ;
207
208
let mut gave_up_on_commit = None ;
208
209
let mut seen = HashMap :: < gix_hash:: ObjectId , Flags > :: default ( ) ;
209
210
seen. insert ( commit. to_owned ( ) , 0u32 ) ;
210
211
211
- while let Some ( ( commit, _commit_time ) ) = queue. pop_front ( ) {
212
+ while let Some ( commit) = queue. pop ( ) {
212
213
commits_seen += 1 ;
213
214
if let Some ( name) = name_by_oid. get ( & commit) {
214
215
if candidates. len ( ) < max_candidates {
@@ -290,7 +291,7 @@ pub(crate) mod function {
290
291
} ) ;
291
292
292
293
if let Some ( commit_id) = gave_up_on_commit {
293
- queue. push_front ( ( commit_id , u32:: MAX ) ) ;
294
+ queue. insert ( u32:: MAX , commit_id ) ;
294
295
commits_seen -= 1 ;
295
296
}
296
297
@@ -318,7 +319,7 @@ pub(crate) mod function {
318
319
find : & mut Find ,
319
320
buf : & mut Vec < u8 > ,
320
321
parent_buf : & mut Vec < u8 > ,
321
- queue : & mut VecDeque < ( gix_hash:: ObjectId , u32 ) > ,
322
+ queue : & mut PriorityQueue < CommitTime , gix_hash:: ObjectId > ,
322
323
seen : & mut HashMap < gix_hash:: ObjectId , Flags > ,
323
324
commit : & gix_hash:: oid ,
324
325
commit_flags : Flags ,
@@ -356,10 +357,7 @@ pub(crate) mod function {
356
357
. unwrap_or_default ( ) ;
357
358
358
359
entry. insert ( commit_flags) ;
359
- match queue. binary_search_by ( |c| c. 1 . cmp ( & parent_commit_date) . reverse ( ) ) {
360
- Ok ( _) => queue. push_back ( ( parent_id, parent_commit_date) ) ,
361
- Err ( pos) => queue. insert ( pos, ( parent_id, parent_commit_date) ) ,
362
- } ;
360
+ queue. insert ( parent_commit_date, parent_id) ;
363
361
}
364
362
hash_map:: Entry :: Occupied ( mut entry) => {
365
363
* entry. get_mut ( ) |= commit_flags;
@@ -378,7 +376,7 @@ pub(crate) mod function {
378
376
379
377
#[ allow( clippy:: too_many_arguments) ]
380
378
fn finish_depth_computation < ' name , Find , E > (
381
- mut queue : VecDeque < ( gix_hash:: ObjectId , u32 ) > ,
379
+ mut queue : PriorityQueue < CommitTime , gix_hash:: ObjectId > ,
382
380
mut find : Find ,
383
381
best_candidate : & mut Candidate < ' name > ,
384
382
mut seen : HashMap < gix_hash:: ObjectId , Flags > ,
@@ -391,13 +389,13 @@ pub(crate) mod function {
391
389
E : std:: error:: Error + Send + Sync + ' static ,
392
390
{
393
391
let mut commits_seen = 0 ;
394
- while let Some ( ( commit, _commit_time ) ) = queue. pop_front ( ) {
392
+ while let Some ( commit) = queue. pop ( ) {
395
393
commits_seen += 1 ;
396
394
let flags = seen[ & commit] ;
397
395
if ( flags & best_candidate. identity_bit ) == best_candidate. identity_bit {
398
396
if queue
399
- . iter ( )
400
- . all ( |( id , _ ) | ( seen[ id] & best_candidate. identity_bit ) == best_candidate. identity_bit )
397
+ . iter_random ( )
398
+ . all ( |id | ( seen[ id] & best_candidate. identity_bit ) == best_candidate. identity_bit )
401
399
{
402
400
break ;
403
401
}
@@ -429,3 +427,5 @@ pub(crate) mod function {
429
427
order : usize ,
430
428
}
431
429
}
430
+
431
+ type CommitTime = u32 ;
0 commit comments