251
return 0;
252
}
253
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 prio_queue_size(&queue->queue) == (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,
255
struct possible_tag *best)
256
{
257
unsigned long seen_commits = 0;
258
struct oidset unflagged = OIDSET_INIT;
295
- struct commit *commit;
296
- int skip = queue->get_pending ? 1 : 0;
259
+ struct commit *c;
260
298
- prio_queue_for_each(&queue->queue, commit) {
299
- if (skip) {
300
- skip = 0;
301
- continue;
302
- }
303
- if (!(commit->object.flags & best->flag_within))
304
- 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);
264
}
265
307
- while (!lazy_queue_empty(queue)) {
308
- struct commit *c = lazy_queue_get(queue);
266
+ while ((c = prio_queue_get(queue))) {
267
struct commit_list *parents = c->parents;
268
seen_commits++;
269
if (c->object.flags & best->flag_within) {
279
repo_parse_commit(the_repository, p);
280
seen = p->object.flags & SEEN;
281
if (!seen)
324
- lazy_queue_put(queue, p);
282
+ prio_queue_put(queue, p);
283
flag_before = p->object.flags & best->flag_within;
284
p->object.flags |= c->object.flags;
285
flag_after = p->object.flags & best->flag_within;
327
328
static void describe_commit(struct commit *cmit, struct strbuf *dst)
329
{
372
- struct commit *gave_up_on = NULL;
373
- 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 };
332
struct commit_name *n;
333
struct possible_tag all_matches[MAX_TAGS];
334
unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
370
}
371
372
cmit->object.flags = SEEN;
415
- lazy_queue_put(&queue, cmit);
416
- while (!lazy_queue_empty(&queue)) {
417
- struct commit *c = lazy_queue_get(&queue);
373
+ prio_queue_put(&queue, cmit);
374
+ while ((c = prio_queue_get(&queue))) {
375
struct commit_list *parents = c->parents;
376
struct commit_name **slot;
377
405
t->depth++;
406
}
407
/* Stop if last remaining path already covered by best candidate(s) */
451
- if (annotated_cnt && lazy_queue_empty(&queue)) {
408
+ if (annotated_cnt && !prio_queue_size(&queue)) {
409
int best_depth = INT_MAX;
410
unsigned best_within = 0;
411
for (cur_match = 0; cur_match < match_cnt; cur_match++) {
428
struct commit *p = parents->item;
429
repo_parse_commit(the_repository, p);
430
if (!(p->object.flags & SEEN))
474
- lazy_queue_put(&queue, p);
431
+ prio_queue_put(&queue, p);
432
p->object.flags |= c->object.flags;
433
parents = parents->next;
434
443
strbuf_add_unique_abbrev(dst, cmit_oid, abbrev);
444
if (suffix)
445
strbuf_addstr(dst, suffix);
489
- lazy_queue_clear(&queue);
446
+ clear_prio_queue(&queue);
447
return;
448
}
449
if (unannotated_cnt)
459
QSORT(all_matches, match_cnt, compare_pt);
460
461
if (gave_up_on) {
505
- lazy_queue_put(&queue, gave_up_on);
462
+ prio_queue_put(&queue, gave_up_on);
463
seen_commits--;
464
}
465
seen_commits += finish_depth_computation(&queue, &all_matches[0]);
509
- lazy_queue_clear(&queue);
466
+ clear_prio_queue(&queue);
467
468
if (debug) {
469
static int label_width = -1;