#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 **);
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_get(queue);
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);
+ prio_queue_put(queue, commit);
}
parents = parents->next;
}
const char *skip_blank_lines(const char *msg);
-/** Removes the first commit from a list sorted by date, and adds all
- * of its parents.
- **/
-struct commit *pop_most_recent_commit(struct commit_list **list,
+struct prio_queue;
+
+/* Removes the first commit from a prio_queue and adds its parents. */
+struct commit *pop_most_recent_commit(struct prio_queue *queue,
unsigned int mark);
struct commit *pop_commit(struct commit_list **stack);
#include "commit-graph.h"
#include "sigchain.h"
#include "mergesort.h"
+#include "prio-queue.h"
static int transfer_unpack_limit = -1;
static int fetch_unpack_limit = -1;
return count ? retval : 0;
}
-static struct commit_list *complete;
+static struct prio_queue complete = { compare_commits_by_commit_date };
static int mark_complete(const struct object_id *oid)
{
if (commit && !(commit->object.flags & COMPLETE)) {
commit->object.flags |= COMPLETE;
- commit_list_insert(commit, &complete);
+ prio_queue_put(&complete, commit);
}
return 0;
}
static void mark_recent_complete_commits(struct fetch_pack_args *args,
timestamp_t cutoff)
{
- while (complete && cutoff <= complete->item->date) {
+ while (complete.nr) {
+ struct commit *item = prio_queue_peek(&complete);
+ if (item->date < cutoff)
+ break;
print_verbose(args, _("Marking %s as complete"),
- oid_to_hex(&complete->item->object.oid));
+ oid_to_hex(&item->object.oid));
pop_most_recent_commit(&complete, COMPLETE);
}
}
refs_for_each_rawref(get_main_ref_store(the_repository),
mark_complete_oid, NULL);
for_each_cached_alternate(NULL, mark_alternate_complete);
- commit_list_sort_by_date(&complete);
if (cutoff)
mark_recent_complete_commits(args, cutoff);
}
#include "commit-reach.h"
#include "date.h"
#include "object-file-convert.h"
+#include "prio-queue.h"
static int get_oid_oneline(struct repository *r, const char *, struct object_id *,
const struct commit_list *);
const char *prefix, struct object_id *oid,
const struct commit_list *list)
{
- struct commit_list *copy = NULL, **copy_tail = ©
+ struct prio_queue copy = { compare_commits_by_commit_date };
const struct commit_list *l;
int found = 0;
int negative = 0;
for (l = list; l; l = l->next) {
l->item->object.flags |= ONELINE_SEEN;
- copy_tail = &commit_list_insert(l->item, copy_tail)->next;
+ prio_queue_put(©, l->item);
}
- while (copy) {
+ while (copy.nr) {
const char *p, *buf;
struct commit *commit;
int matches;
regfree(®ex);
for (l = list; l; l = l->next)
clear_commit_marks(l->item, ONELINE_SEEN);
- free_commit_list(copy);
+ clear_prio_queue(©);
return found ? 0 : -1;
}
cb.list = &list;
refs_for_each_ref(get_main_ref_store(repo), handle_one_ref, &cb);
refs_head_ref(get_main_ref_store(repo), handle_one_ref, &cb);
- commit_list_sort_by_date(&list);
ret = get_oid_oneline(repo, name + 2, oid, list);
free_commit_list(list);
'perf/p1450-fsck.sh',
'perf/p1451-fsck-skip-list.sh',
'perf/p1500-graph-walks.sh',
+ 'perf/p1501-rev-parse-oneline.sh',
'perf/p2000-sparse-operations.sh',
'perf/p3400-rebase.sh',
'perf/p3404-rebase-interactive.sh',
--- /dev/null
+#!/bin/sh
+
+test_description='Test :/ object name notation'
+
+. ./perf-lib.sh
+
+test_perf_fresh_repo
+
+#
+# Creates lots of merges to make history traversal costly. In
+# particular it creates 2^($max_level-1)-1 2-way merges on top of
+# 2^($max_level-1) root commits. E.g., the commit history looks like
+# this for a $max_level of 3:
+#
+# _1_
+# / \
+# 2 3
+# / \ / \
+# 4 5 6 7
+#
+# The numbers are the fast-import marks, which also are the commit
+# messages. 1 is the HEAD commit and a merge, 2 and 3 are also merges,
+# 4-7 are the root commits.
+#
+build_history () {
+ local max_level="$1" &&
+ local level="${2:-1}" &&
+ local mark="${3:-1}" &&
+ if test $level -eq $max_level
+ then
+ echo "reset refs/heads/master" &&
+ echo "from $ZERO_OID" &&
+ echo "commit refs/heads/master" &&
+ echo "mark :$mark" &&
+ echo "committer C <c@example.com> 1234567890 +0000" &&
+ echo "data <<EOF" &&
+ echo "$mark" &&
+ echo "EOF"
+ else
+ local level1=$((level+1)) &&
+ local mark1=$((2*mark)) &&
+ local mark2=$((2*mark+1)) &&
+ build_history $max_level $level1 $mark1 &&
+ build_history $max_level $level1 $mark2 &&
+ echo "commit refs/heads/master" &&
+ echo "mark :$mark" &&
+ echo "committer C <c@example.com> 1234567890 +0000" &&
+ echo "data <<EOF" &&
+ echo "$mark" &&
+ echo "EOF" &&
+ echo "from :$mark1" &&
+ echo "merge :$mark2"
+ fi
+}
+
+test_expect_success 'setup' '
+ build_history 16 | git fast-import &&
+ git log --format="%H %s" --reverse >commits &&
+ sed -n -e "s/ .*$//p" -e "q" <commits >expect &&
+ sed -n -e "s/^.* //p" -e "q" <commits >needle
+'
+
+test_perf "rev-parse :/$(cat needle)" '
+ git rev-parse :/$(cat needle) >actual
+'
+
+test_expect_success 'verify result' '
+ test_cmp expect actual
+'
+
+test_done
#include "blob.h"
#include "refs.h"
#include "progress.h"
+#include "prio-queue.h"
static struct object_id current_commit_oid;
#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)
{
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);
}
if (commit) {
commit->object.flags |= COMPLETE;
- commit_list_insert(commit, &complete);
+ prio_queue_put(&complete, commit);
}
return 0;
}
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++) {