| 1014 | } |
| 1015 | |
| 1016 | struct commit_list *get_reachable_subset(struct commit **from, size_t nr_from, |
| 1017 | struct commit **to, size_t nr_to, |
| 1018 | unsigned int reachable_flag) |
| 1019 | { |
| 1020 | struct commit **item; |
| 1021 | struct commit *current; |
| 1022 | struct commit_list *found_commits = NULL; |
| 1023 | struct commit **to_last = to + nr_to; |
| 1024 | struct commit **from_last = from + nr_from; |
| 1025 | timestamp_t min_generation = GENERATION_NUMBER_INFINITY; |
| 1026 | int num_to_find = 0; |
| 1027 | |
| 1028 | struct prio_queue queue = { compare_commits_by_gen_then_commit_date }; |
| 1029 | |
| 1030 | for (item = to; item < to_last; item++) { |
| 1031 | timestamp_t generation; |
| 1032 | struct commit *c = *item; |
| 1033 | |
| 1034 | repo_parse_commit(the_repository, c); |
| 1035 | generation = commit_graph_generation(c); |
| 1036 | if (generation < min_generation) |
| 1037 | min_generation = generation; |
| 1038 | |
| 1039 | if (!(c->object.flags & PARENT1)) { |
| 1040 | c->object.flags |= PARENT1; |
| 1041 | num_to_find++; |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | for (item = from; item < from_last; item++) { |
| 1046 | struct commit *c = *item; |
| 1047 | if (!(c->object.flags & PARENT2)) { |
| 1048 | c->object.flags |= PARENT2; |
| 1049 | repo_parse_commit(the_repository, c); |
| 1050 | |
| 1051 | prio_queue_put(&queue, *item); |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | while (num_to_find && (current = prio_queue_get(&queue)) != NULL) { |
| 1056 | struct commit_list *parents; |
| 1057 | |
| 1058 | if (current->object.flags & PARENT1) { |
| 1059 | current->object.flags &= ~PARENT1; |
| 1060 | current->object.flags |= reachable_flag; |
| 1061 | commit_list_insert(current, &found_commits); |
| 1062 | num_to_find--; |
| 1063 | } |
| 1064 | |
| 1065 | for (parents = current->parents; parents; parents = parents->next) { |
| 1066 | struct commit *p = parents->item; |
| 1067 | |
| 1068 | repo_parse_commit(the_repository, p); |
| 1069 | |
| 1070 | if (commit_graph_generation(p) < min_generation) |
| 1071 | continue; |
| 1072 | |
| 1073 | if (p->object.flags & PARENT2) |