summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2016-10-05 12:23:26 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2016-10-06 11:04:55 +0200
commitea1ceb7f554da276ffb0fe18c6ca4a0233845d55 (patch)
tree00d369c44bb76e6e9d4c144f49b30ffe44645380
parent4aed1b9a69f66bd6ea365a49e1a637c51f8c3013 (diff)
downloadlibgit2-ea1ceb7f554da276ffb0fe18c6ca4a0233845d55.tar.gz
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.
-rw-r--r--src/revwalk.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/src/revwalk.c b/src/revwalk.c
index cea76309b..80f5bdfdf 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -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;
-
- if ((error = walk->enqueue(walk, list->item)) < 0) {
- git_commit_list_free(&commits);
- return error;
- }
+ printf("%s: commit %s\n", __func__, git_oid_tostr_s(&list->item->oid));
}
- git_commit_list_free(&commits);
+ if ((error = limit_list(&commits, walk, commits)) < 0)
+ return error;
if (walk->sorting & GIT_SORT_TOPOLOGICAL) {
- if ((error = sort_in_topological_order(&walk->iterator_topo, walk)))
+ error = sort_in_topological_order(&walk->iterator_topo, walk, commits);
+ git_commit_list_free(&commits);
+
+ 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) {