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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
diff --git a/src/revwalk.c b/src/revwalk.c
index cea7630..80f5bdf 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) {