MCPcopy Create free account
hub / github.com/git/git / sort_in_topological_order

Function sort_in_topological_order

commit.c:945–1054  ·  view source on GitHub ↗

* Performs an in-place topological sort on the list supplied. */

Source from the content-addressed store, hash-verified

943 * Performs an in-place topological sort on the list supplied.
944 */
945void sort_in_topological_order(struct commit_list **list, enum rev_sort_order sort_order)
946{
947 struct commit_list *next, *orig = *list;
948 struct commit_list **pptr;
949 struct indegree_slab indegree;
950 struct prio_queue queue;
951 struct commit *commit;
952 struct author_date_slab author_date;
953
954 if (!orig)
955 return;
956 *list = NULL;
957
958 init_indegree_slab(&indegree);
959 memset(&queue, '\0', sizeof(queue));
960
961 switch (sort_order) {
962 default: /* REV_SORT_IN_GRAPH_ORDER */
963 queue.compare = NULL;
964 break;
965 case REV_SORT_BY_COMMIT_DATE:
966 queue.compare = compare_commits_by_commit_date;
967 break;
968 case REV_SORT_BY_AUTHOR_DATE:
969 init_author_date_slab(&author_date);
970 queue.compare = compare_commits_by_author_date;
971 queue.cb_data = &author_date;
972 break;
973 }
974
975 /* Mark them and clear the indegree */
976 for (next = orig; next; next = next->next) {
977 struct commit *commit = next->item;
978 *(indegree_slab_at(&indegree, commit)) = 1;
979 /* also record the author dates, if needed */
980 if (sort_order == REV_SORT_BY_AUTHOR_DATE)
981 record_author_date(&author_date, commit);
982 }
983
984 /* update the indegree */
985 for (next = orig; next; next = next->next) {
986 struct commit_list *parents = next->item->parents;
987 while (parents) {
988 struct commit *parent = parents->item;
989 int *pi = indegree_slab_at(&indegree, parent);
990
991 if (*pi)
992 (*pi)++;
993 parents = parents->next;
994 }
995 }
996
997 /*
998 * find the tips
999 *
1000 * tips are nodes not reachable from any other node in the list
1001 *
1002 * the tips serve as a starting set for the work queue.

Callers 3

prepare_revision_walkFunction · 0.85
cmd_show_branchFunction · 0.85

Calls 7

record_author_dateFunction · 0.85
prio_queue_putFunction · 0.85
prio_queue_reverseFunction · 0.85
commit_list_freeFunction · 0.85
prio_queue_getFunction · 0.85
commit_list_insertFunction · 0.85
clear_prio_queueFunction · 0.85

Tested by

no test coverage detected