aboutsummaryrefslogtreecommitdiffstats
path: root/walker.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-07-22 14:27:51 -0700
committerJunio C Hamano <gitster@pobox.com>2025-07-22 14:27:52 -0700
commitb859ed88ed4224e01f6abbf380a4a22237b86de9 (patch)
tree99f1b972eee301a93f11b59bcc008f5f51f822bb /walker.c
parentRevert "Merge branch 'rs/pop-recent-commit-with-prio-queue' into next" (diff)
parentcommit: use prio_queue_replace() in pop_most_recent_commit() (diff)
downloadgit-b859ed88ed4224e01f6abbf380a4a22237b86de9.tar.gz
git-b859ed88ed4224e01f6abbf380a4a22237b86de9.zip
Merge branch 'rs/pop-recent-commit-with-prio-queue' into next
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 'walker.c')
-rw-r--r--walker.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/walker.c b/walker.c
index d131af04c7..8073754517 100644
--- a/walker.c
+++ b/walker.c
@@ -14,6 +14,7 @@
#include "blob.h"
#include "refs.h"
#include "progress.h"
+#include "prio-queue.h"
static struct object_id current_commit_oid;
@@ -78,7 +79,7 @@ static int process_tree(struct walker *walker, struct tree *tree)
#define SEEN (1U << 1)
#define TO_SCAN (1U << 2)
-static struct commit_list *complete = NULL;
+static struct prio_queue complete = { compare_commits_by_commit_date };
static int process_commit(struct walker *walker, struct commit *commit)
{
@@ -87,7 +88,10 @@ static int process_commit(struct walker *walker, struct commit *commit)
if (repo_parse_commit(the_repository, commit))
return -1;
- while (complete && complete->item->date >= commit->date) {
+ while (complete.nr) {
+ struct commit *item = prio_queue_peek(&complete);
+ if (item->date < commit->date)
+ break;
pop_most_recent_commit(&complete, COMPLETE);
}
@@ -233,7 +237,7 @@ static int mark_complete(const char *path UNUSED,
if (commit) {
commit->object.flags |= COMPLETE;
- commit_list_insert(commit, &complete);
+ prio_queue_put(&complete, commit);
}
return 0;
}
@@ -302,7 +306,6 @@ int walker_fetch(struct walker *walker, int targets, char **target,
if (!walker->get_recover) {
refs_for_each_ref(get_main_ref_store(the_repository),
mark_complete, NULL);
- commit_list_sort_by_date(&complete);
}
for (i = 0; i < targets; i++) {