* Performs an in-place topological sort on the list supplied. */
| 943 | * Performs an in-place topological sort on the list supplied. |
| 944 | */ |
| 945 | void 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. |
no test coverage detected