250
return 0;
251
}
252
253
-static bool all_have_flag(const struct prio_queue *queue, unsigned flag)
253
+struct lazy_queue {
254
+ struct prio_queue queue;
255
+ bool get_pending;
256
+};
257
+
258
+#define LAZY_QUEUE_INIT { { compare_commits_by_commit_date }, false }
259
+
260
+static void *lazy_queue_get(struct lazy_queue *queue)
261
+{
262
+ if (queue->get_pending)
263
+ prio_queue_get(&queue->queue);
264
+ else
265
+ queue->get_pending = true;
266
+ return prio_queue_peek(&queue->queue);
267
+}
268
+
269
+static void lazy_queue_put(struct lazy_queue *queue, void *thing)
270
+{
271
+ if (queue->get_pending)
272
+ prio_queue_replace(&queue->queue, thing);
273
+ else
274
+ prio_queue_put(&queue->queue, thing);
275
+ queue->get_pending = false;
276
+}
277
+
278
+static bool lazy_queue_empty(const struct lazy_queue *queue)
279
+{
280
+ return queue->queue.nr == (queue->get_pending ? 1 : 0);
281
+}
282
+
283
+static void lazy_queue_clear(struct lazy_queue *queue)
284
+{
285
+ clear_prio_queue(&queue->queue);
286
+ queue->get_pending = false;
287
+}
288
+
289
+static bool all_have_flag(const struct lazy_queue *queue, unsigned flag)
290
{
255
- for (size_t i = 0; i < queue->nr; i++) {
256
- struct commit *commit = queue->array[i].data;
291
+ for (size_t i = queue->get_pending ? 1 : 0; i < queue->queue.nr; i++) {
292
+ struct commit *commit = queue->queue.array[i].data;
293
if (!(commit->object.flags & flag))
294
return false;
295
}
296
return true;
297
}
298
263
-static unsigned long finish_depth_computation(struct prio_queue *queue,
299
+static unsigned long finish_depth_computation(struct lazy_queue *queue,
300
struct possible_tag *best)
301
{
302
unsigned long seen_commits = 0;
267
- while (queue->nr) {
268
- struct commit *c = prio_queue_get(queue);
303
+ while (!lazy_queue_empty(queue)) {
304
+ struct commit *c = lazy_queue_get(queue);
305
struct commit_list *parents = c->parents;
306
seen_commits++;
307
if (c->object.flags & best->flag_within) {
313
struct commit *p = parents->item;
314
repo_parse_commit(the_repository, p);
315
if (!(p->object.flags & SEEN))
280
- prio_queue_put(queue, p);
316
+ lazy_queue_put(queue, p);
317
p->object.flags |= c->object.flags;
318
parents = parents->next;
319
}
355
static void describe_commit(struct object_id *oid, struct strbuf *dst)
356
{
357
struct commit *cmit, *gave_up_on = NULL;
322
- struct prio_queue queue = { compare_commits_by_commit_date };
358
+ struct lazy_queue queue = LAZY_QUEUE_INIT;
359
struct commit_name *n;
360
struct possible_tag all_matches[MAX_TAGS];
361
unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
399
}
400
401
cmit->object.flags = SEEN;
366
- prio_queue_put(&queue, cmit);
367
- while (queue.nr) {
368
- struct commit *c = prio_queue_get(&queue);
402
+ lazy_queue_put(&queue, cmit);
403
+ while (!lazy_queue_empty(&queue)) {
404
+ struct commit *c = lazy_queue_get(&queue);
405
struct commit_list *parents = c->parents;
406
struct commit_name **slot;
407
435
t->depth++;
436
}
437
/* Stop if last remaining path already covered by best candidate(s) */
402
- if (annotated_cnt && !queue.nr) {
438
+ if (annotated_cnt && lazy_queue_empty(&queue)) {
439
int best_depth = INT_MAX;
440
unsigned best_within = 0;
441
for (cur_match = 0; cur_match < match_cnt; cur_match++) {
458
struct commit *p = parents->item;
459
repo_parse_commit(the_repository, p);
460
if (!(p->object.flags & SEEN))
425
- prio_queue_put(&queue, p);
461
+ lazy_queue_put(&queue, p);
462
p->object.flags |= c->object.flags;
463
parents = parents->next;
464
473
strbuf_add_unique_abbrev(dst, cmit_oid, abbrev);
474
if (suffix)
475
strbuf_addstr(dst, suffix);
440
- clear_prio_queue(&queue);
476
+ lazy_queue_clear(&queue);
477
return;
478
}
479
if (unannotated_cnt)
489
QSORT(all_matches, match_cnt, compare_pt);
490
491
if (gave_up_on) {
456
- prio_queue_put(&queue, gave_up_on);
492
+ lazy_queue_put(&queue, gave_up_on);
493
seen_commits--;
494
}
495
seen_commits += finish_depth_computation(&queue, &all_matches[0]);
460
- clear_prio_queue(&queue);
496
+ lazy_queue_clear(&queue);
497
498
if (debug) {
499
static int label_width = -1;