From: Junio C Hamano Date: Mon, 13 Jul 2026 15:27:27 +0000 (-0700) Subject: Merge branch 'kk/prio-queue-get-put-fusion' X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c775abab0b4acb9db2098ac07ee5d6565494080;p=thirdparty%2Fgit.git Merge branch 'kk/prio-queue-get-put-fusion' The lazy priority queue optimization pattern (deferring actual removal in 'prio_queue_get()' to allow get+put fusion) has been folded directly into 'prio_queue' itself, speeding up commit traversal workflows and simplifying callers. * kk/prio-queue-get-put-fusion: prio-queue: fold lazy_queue into prio_queue for automatic get+put fusion prio-queue: rename .nr to .nr_ and add accessor helpers --- 3c775abab0b4acb9db2098ac07ee5d6565494080 diff --cc commit-reach.c index 5df471a313,a849de653e..3898d09dec --- a/commit-reach.c +++ b/commit-reach.c @@@ -1118,9 -1069,8 +1118,10 @@@ void ahead_behind(struct repository *r struct commit **commits, size_t commits_nr, struct ahead_behind_count *counts, size_t counts_nr) { - struct prio_queue queue = { .compare = compare_commits_by_gen_then_commit_date }; + struct nonstale_queue queue = { + { .compare = compare_commits_by_gen_then_commit_date } + }; + void *entry; size_t width = DIV_ROUND_UP(commits_nr, BITS_IN_EWORD); if (!commits_nr || !counts_nr) @@@ -1186,10 -1136,10 +1187,10 @@@ /* STALE is used here, PARENT2 is used by insert_no_dup(). */ repo_clear_commit_marks(r, PARENT2 | STALE); - for (size_t i = 0; i < queue.pq.nr; i++) - free_bit_array(queue.pq.array[i].data); - prio_queue_for_each(&queue, entry) ++ prio_queue_for_each(&queue.pq, entry) + free_bit_array(entry); clear_bit_arrays(&bit_arrays); - clear_prio_queue(&queue); + clear_nonstale_queue(&queue); } struct commit_and_index { diff --cc pack-bitmap-write.c index 1bcb3f98a4,ed9714b135..acbea89031 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@@ -636,15 -513,10 +636,17 @@@ static int fill_bitmap_commit(struct bi struct bitmap_index *old_bitmap, const uint32_t *mapping) { + struct commit *c; - struct tree *tree; ++ struct tree *t; int found; + int from_pseudo_merge = commit->object.flags & BITMAP_PSEUDO_MERGE; uint32_t pos; + + if (ent->pseudo_merge) + BUG("unexpected pseudo-merge commit in fill_bitmap_commit()"); + + fill_bitmap_commit_calls_nr++; + if (!ent->bitmap) ent->bitmap = bitmap_new(); @@@ -740,23 -575,8 +741,22 @@@ } } - while (tree_queue->nr) { - struct tree *t = prio_queue_get(tree_queue); - while ((tree = prio_queue_get(tree_queue))) { - if (fill_bitmap_tree(writer, ent->bitmap, tree) < 0) ++ while ((t = prio_queue_get(tree_queue))) { + int found; + + pos = find_object_pos(writer, &t->object.oid, &found); + if (!found) + return -1; + if (bitmap_get(ent->bitmap, pos)) { + /* + * If our bit is already set, then there is + * nothing to do. Both this tree and all of its + * children will be set. + */ + continue; + } + + if (fill_bitmap_tree(writer, ent->bitmap, t, pos) < 0) return -1; } return 0; diff --cc revision.c index 0c95edef59,34e2d146f4..137a86d33b --- a/revision.c +++ b/revision.c @@@ -4055,11 -4024,20 +4053,12 @@@ static enum rewrite_result rewrite_one_ } } -static void merge_queue_into_list(struct prio_queue *q, struct commit_list **list) +static void merge_queue_into_prio_queue(struct prio_queue *from, + struct prio_queue *to) { - while (from->nr) - prio_queue_put(to, prio_queue_get(from)); + struct commit *item; - while ((item = prio_queue_peek(q))) { - struct commit_list *p = *list; - - if (p && p->item->date >= item->date) - list = &p->next; - else { - p = commit_list_insert(item, list); - list = &p->next; /* skip newly added item */ - prio_queue_get(q); /* pop item */ - } - } ++ while ((item = prio_queue_get(from))) ++ prio_queue_put(to, item); } static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp)