@@ -251,56 +251,19 @@ static int compare_pt(const void *a_, const void *b_)
251251 return 0 ;
252252}
253253
254- struct lazy_queue {
255- struct prio_queue queue ;
256- bool get_pending ;
257- };
258-
259- #define LAZY_QUEUE_INIT { { compare_commits_by_commit_date }, false }
260-
261- static void * lazy_queue_get (struct lazy_queue * queue )
262- {
263- if (queue -> get_pending )
264- prio_queue_get (& queue -> queue );
265- else
266- queue -> get_pending = true;
267- return prio_queue_peek (& queue -> queue );
268- }
269-
270- static void lazy_queue_put (struct lazy_queue * queue , void * thing )
271- {
272- if (queue -> get_pending )
273- prio_queue_replace (& queue -> queue , thing );
274- else
275- prio_queue_put (& queue -> queue , thing );
276- queue -> get_pending = false;
277- }
278-
279- static bool lazy_queue_empty (const struct lazy_queue * queue )
280- {
281- return queue -> queue .nr == (queue -> get_pending ? 1 : 0 );
282- }
283-
284- static void lazy_queue_clear (struct lazy_queue * queue )
285- {
286- clear_prio_queue (& queue -> queue );
287- queue -> get_pending = false;
288- }
289-
290- static unsigned long finish_depth_computation (struct lazy_queue * queue ,
254+ static unsigned long finish_depth_computation (struct prio_queue * queue ,
291255 struct possible_tag * best )
292256{
293257 unsigned long seen_commits = 0 ;
294258 struct oidset unflagged = OIDSET_INIT ;
259+ struct commit * c ;
295260
296- for (size_t i = queue -> get_pending ? 1 : 0 ; i < queue -> queue .nr ; i ++ ) {
297- struct commit * commit = queue -> queue .array [i ].data ;
298- if (!(commit -> object .flags & best -> flag_within ))
299- oidset_insert (& unflagged , & commit -> object .oid );
261+ prio_queue_for_each (queue , c ) {
262+ if (!(c -> object .flags & best -> flag_within ))
263+ oidset_insert (& unflagged , & c -> object .oid );
300264 }
301265
302- while (!lazy_queue_empty (queue )) {
303- struct commit * c = lazy_queue_get (queue );
266+ while ((c = prio_queue_get (queue ))) {
304267 struct commit_list * parents = c -> parents ;
305268 seen_commits ++ ;
306269 if (c -> object .flags & best -> flag_within ) {
@@ -316,7 +279,7 @@ static unsigned long finish_depth_computation(struct lazy_queue *queue,
316279 repo_parse_commit (the_repository , p );
317280 seen = p -> object .flags & SEEN ;
318281 if (!seen )
319- lazy_queue_put (queue , p );
282+ prio_queue_put (queue , p );
320283 flag_before = p -> object .flags & best -> flag_within ;
321284 p -> object .flags |= c -> object .flags ;
322285 flag_after = p -> object .flags & best -> flag_within ;
@@ -364,8 +327,8 @@ static void append_suffix(int depth, const struct object_id *oid, struct strbuf
364327
365328static void describe_commit (struct commit * cmit , struct strbuf * dst )
366329{
367- struct commit * gave_up_on = NULL ;
368- struct lazy_queue queue = LAZY_QUEUE_INIT ;
330+ struct commit * c , * gave_up_on = NULL ;
331+ struct prio_queue queue = { compare_commits_by_commit_date } ;
369332 struct commit_name * n ;
370333 struct possible_tag all_matches [MAX_TAGS ];
371334 unsigned int match_cnt = 0 , annotated_cnt = 0 , cur_match ;
@@ -407,9 +370,8 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst)
407370 }
408371
409372 cmit -> object .flags = SEEN ;
410- lazy_queue_put (& queue , cmit );
411- while (!lazy_queue_empty (& queue )) {
412- struct commit * c = lazy_queue_get (& queue );
373+ prio_queue_put (& queue , cmit );
374+ while ((c = prio_queue_get (& queue ))) {
413375 struct commit_list * parents = c -> parents ;
414376 struct commit_name * * slot ;
415377
@@ -443,7 +405,7 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst)
443405 t -> depth ++ ;
444406 }
445407 /* Stop if last remaining path already covered by best candidate(s) */
446- if (annotated_cnt && lazy_queue_empty (& queue )) {
408+ if (annotated_cnt && ! prio_queue_size (& queue )) {
447409 int best_depth = INT_MAX ;
448410 unsigned best_within = 0 ;
449411 for (cur_match = 0 ; cur_match < match_cnt ; cur_match ++ ) {
@@ -466,7 +428,7 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst)
466428 struct commit * p = parents -> item ;
467429 repo_parse_commit (the_repository , p );
468430 if (!(p -> object .flags & SEEN ))
469- lazy_queue_put (& queue , p );
431+ prio_queue_put (& queue , p );
470432 p -> object .flags |= c -> object .flags ;
471433 parents = parents -> next ;
472434
@@ -481,7 +443,7 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst)
481443 strbuf_add_unique_abbrev (dst , cmit_oid , abbrev );
482444 if (suffix )
483445 strbuf_addstr (dst , suffix );
484- lazy_queue_clear (& queue );
446+ clear_prio_queue (& queue );
485447 return ;
486448 }
487449 if (unannotated_cnt )
@@ -497,11 +459,11 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst)
497459 QSORT (all_matches , match_cnt , compare_pt );
498460
499461 if (gave_up_on ) {
500- lazy_queue_put (& queue , gave_up_on );
462+ prio_queue_put (& queue , gave_up_on );
501463 seen_commits -- ;
502464 }
503465 seen_commits += finish_depth_computation (& queue , & all_matches [0 ]);
504- lazy_queue_clear (& queue );
466+ clear_prio_queue (& queue );
505467
506468 if (debug ) {
507469 static int label_width = -1 ;
0 commit comments