Skip to content

Commit ea1ceb7

Browse files
committed
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 parent 4aed1b9 commit ea1ceb7

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/revwalk.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,9 @@ static int limit_list(git_commit_list **out, git_revwalk *walk, git_commit_list
443443
return 0;
444444
}
445445

446-
static int sort_in_topological_order(git_commit_list **out, git_revwalk *walk)
446+
static int sort_in_topological_order(git_commit_list **out, git_revwalk *walk, git_commit_list *list)
447447
{
448-
git_commit_list *list = NULL, *ll = NULL, *newlist, **pptr;
448+
git_commit_list *ll = NULL, *newlist, **pptr;
449449
git_commit_list_node *next;
450450
git_pqueue queue;
451451
git_vector_cmp queue_cmp = NULL;
@@ -464,16 +464,10 @@ static int sort_in_topological_order(git_commit_list **out, git_revwalk *walk)
464464
* store it in the commit list as we extract it from the lower
465465
* machinery.
466466
*/
467-
while ((error = walk->get_next(&next, walk)) == 0) {
468-
next->in_degree = 1;
469-
git_commit_list_insert(next, &list);
467+
for (ll = list; ll; ll = ll->next) {
468+
ll->item->in_degree = 1;
470469
}
471470

472-
if (error != GIT_ITEROVER)
473-
goto cleanup;
474-
475-
error = 0;
476-
477471
/*
478472
* Count up how many children each commit has. We limit
479473
* 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)
531525
error = 0;
532526

533527
cleanup:
534-
git_commit_list_free(&list);
535528
git_pqueue_free(&queue);
536529
return error;
537530
}
@@ -562,26 +555,32 @@ static int prepare_walk(git_revwalk *walk)
562555
}
563556
}
564557

565-
if ((error = limit_list(&commits, walk, commits)) < 0)
566-
return error;
567-
568558
for (list = commits; list; list = list->next) {
569-
if (list->item->uninteresting)
570-
continue;
571-
572-
if ((error = walk->enqueue(walk, list->item)) < 0) {
573-
git_commit_list_free(&commits);
574-
return error;
575-
}
559+
printf("%s: commit %s\n", __func__, git_oid_tostr_s(&list->item->oid));
576560
}
577561

578-
git_commit_list_free(&commits);
562+
if ((error = limit_list(&commits, walk, commits)) < 0)
563+
return error;
579564

580565
if (walk->sorting & GIT_SORT_TOPOLOGICAL) {
581-
if ((error = sort_in_topological_order(&walk->iterator_topo, walk)))
566+
error = sort_in_topological_order(&walk->iterator_topo, walk, commits);
567+
git_commit_list_free(&commits);
568+
569+
if (error < 0)
582570
return error;
583571

584572
walk->get_next = &revwalk_next_toposort;
573+
} else if (walk->sorting & GIT_SORT_TIME) {
574+
for (list = commits; list && !error; list = list->next)
575+
error = walk->enqueue(walk, list->item);
576+
577+
git_commit_list_free(&commits);
578+
579+
if (error < 0)
580+
return error;
581+
} else {
582+
walk->iterator_rand = commits;
583+
walk->get_next = revwalk_next_unsorted;
585584
}
586585

587586
if (walk->sorting & GIT_SORT_REVERSE) {

0 commit comments

Comments
 (0)