summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-07-28 12:02:34 -0700
committerJunio C Hamano <gitster@pobox.com>2025-07-28 12:02:34 -0700
commit0f6e5037d40db4768e8b61aea22c68c9711ce544 (patch)
treecf43012483aec4b0ac9d57080dd8c055b6cbf626 /commit.c
parente4ef0485fd78fcb05866ea78df35796b904e4a8e (diff)
parenta79e3519d66671a408041dac8c56d99078de41f2 (diff)
Merge branch 'rs/pop-recent-commit-with-prio-queue'
The pop_most_recent_commit() function can have quite expensive worst case performance characteristics, which has been optimized by using prio-queue data structure. * rs/pop-recent-commit-with-prio-queue: commit: use prio_queue_replace() in pop_most_recent_commit() prio-queue: add prio_queue_replace() commit: convert pop_most_recent_commit() to prio_queue
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/commit.c b/commit.c
index 15115125c3..ea84c8e7f6 100644
--- a/commit.c
+++ b/commit.c
@@ -31,6 +31,7 @@
#include "parse.h"
#include "object-file.h"
#include "object-file-convert.h"
+#include "prio-queue.h"
static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
@@ -739,20 +740,27 @@ void commit_list_sort_by_date(struct commit_list **list)
commit_list_sort(list, commit_list_compare_by_date);
}
-struct commit *pop_most_recent_commit(struct commit_list **list,
+struct commit *pop_most_recent_commit(struct prio_queue *queue,
unsigned int mark)
{
- struct commit *ret = pop_commit(list);
+ struct commit *ret = prio_queue_peek(queue);
+ int get_pending = 1;
struct commit_list *parents = ret->parents;
while (parents) {
struct commit *commit = parents->item;
if (!repo_parse_commit(the_repository, commit) && !(commit->object.flags & mark)) {
commit->object.flags |= mark;
- commit_list_insert_by_date(commit, list);
+ if (get_pending)
+ prio_queue_replace(queue, commit);
+ else
+ prio_queue_put(queue, commit);
+ get_pending = 0;
}
parents = parents->next;
}
+ if (get_pending)
+ prio_queue_get(queue);
return ret;
}