Commit ea1ceb7f by Carlos Martín Nieto

revwalk: remove a useless enqueueing phase for topological and default sorting

After `limit_list()` we already have the list in time-sorted order, which is
what we want in the "default" case. Enqueueing into the "unsorted" list would
just reverse it, and the topological sort will do its own sorting if it needs
to.
parent 4aed1b9a
......@@ -443,9 +443,9 @@ static int limit_list(git_commit_list **out, git_revwalk *walk, git_commit_list
return 0;
}
static int sort_in_topological_order(git_commit_list **out, git_revwalk *walk)
static int sort_in_topological_order(git_commit_list **out, git_revwalk *walk, git_commit_list *list)
{
git_commit_list *list = NULL, *ll = NULL, *newlist, **pptr;
git_commit_list *ll = NULL, *newlist, **pptr;
git_commit_list_node *next;
git_pqueue queue;
git_vector_cmp queue_cmp = NULL;
......@@ -464,16 +464,10 @@ static int sort_in_topological_order(git_commit_list **out, git_revwalk *walk)
* store it in the commit list as we extract it from the lower
* machinery.
*/
while ((error = walk->get_next(&next, walk)) == 0) {
next->in_degree = 1;
git_commit_list_insert(next, &list);
for (ll = list; ll; ll = ll->next) {
ll->item->in_degree = 1;
}
if (error != GIT_ITEROVER)
goto cleanup;
error = 0;
/*
* Count up how many children each commit has. We limit
* ourselves to those commits in the original list (in-degree
......@@ -531,7 +525,6 @@ static int sort_in_topological_order(git_commit_list **out, git_revwalk *walk)
error = 0;
cleanup:
git_commit_list_free(&list);
git_pqueue_free(&queue);
return error;
}
......@@ -562,26 +555,32 @@ static int prepare_walk(git_revwalk *walk)
}
}
if ((error = limit_list(&commits, walk, commits)) < 0)
return error;
for (list = commits; list; list = list->next) {
if (list->item->uninteresting)
continue;
printf("%s: commit %s\n", __func__, git_oid_tostr_s(&list->item->oid));
}
if ((error = walk->enqueue(walk, list->item)) < 0) {
git_commit_list_free(&commits);
if ((error = limit_list(&commits, walk, commits)) < 0)
return error;
}
}
if (walk->sorting & GIT_SORT_TOPOLOGICAL) {
error = sort_in_topological_order(&walk->iterator_topo, walk, commits);
git_commit_list_free(&commits);
if (walk->sorting & GIT_SORT_TOPOLOGICAL) {
if ((error = sort_in_topological_order(&walk->iterator_topo, walk)))
if (error < 0)
return error;
walk->get_next = &revwalk_next_toposort;
} else if (walk->sorting & GIT_SORT_TIME) {
for (list = commits; list && !error; list = list->next)
error = walk->enqueue(walk, list->item);
git_commit_list_free(&commits);
if (error < 0)
return error;
} else {
walk->iterator_rand = commits;
walk->get_next = revwalk_next_unsorted;
}
if (walk->sorting & GIT_SORT_REVERSE) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment