]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'kk/prio-queue-get-put-fusion'
authorJunio C Hamano <gitster@pobox.com>
Mon, 13 Jul 2026 15:27:27 +0000 (08:27 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Jul 2026 15:27:27 +0000 (08:27 -0700)
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

1  2 
builtin/describe.c
commit-reach.c
commit.c
object-name.c
pack-bitmap-write.c
path-walk.c
revision.c

Simple merge
diff --cc commit-reach.c
index 5df471a313cf6be855b61fd9c06d2499e97bc7af,a849de653ef54415aca477ac157da27161268a5f..3898d09dec4e8559fa6948fa3ae6ea683ce69f82
@@@ -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)
  
        /* 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 commit.c
Simple merge
diff --cc object-name.c
Simple merge
index 1bcb3f98a42518fbb47eb98b88dfd0e86e669542,ed9714b135cf52de7e90a9abccceb17ef6f333da..acbea890313b21c770d845392a3bb359d4ea4037
@@@ -636,15 -513,10 +636,17 @@@ static int fill_bitmap_commit(struct bi
                              struct bitmap_index *old_bitmap,
                              const uint32_t *mapping)
  {
 -      struct tree *tree;
+       struct commit *c;
++      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();
  
                }
        }
  
-       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 path-walk.c
Simple merge
diff --cc revision.c
index 0c95edef5947fa491a82a724c04a2143bd9f7a58,34e2d146f4e09d55fd63c581981c27728c40bc69..137a86d33bbbe189ed0ae33a95f9142a5778534c
@@@ -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)