Ramsay Jones | 0009d35 | 2018-10-17 23:13:26 +0100 | [diff] [blame] | 1 | #ifndef COMMIT_REACH_H |
| 2 | #define COMMIT_REACH_H |
Derrick Stolee | 5227c38 | 2018-07-20 16:33:02 +0000 | [diff] [blame] | 3 | |
Ramsay Jones | 1406725 | 2018-10-27 02:53:57 +0100 | [diff] [blame] | 4 | #include "commit.h" |
Derrick Stolee | 920f93c | 2018-07-20 16:33:08 +0000 | [diff] [blame] | 5 | #include "commit-slab.h" |
| 6 | |
Derrick Stolee | 5227c38 | 2018-07-20 16:33:02 +0000 | [diff] [blame] | 7 | struct commit_list; |
Derrick Stolee | 920f93c | 2018-07-20 16:33:08 +0000 | [diff] [blame] | 8 | struct ref_filter; |
Ramsay Jones | 1406725 | 2018-10-27 02:53:57 +0100 | [diff] [blame] | 9 | struct object_id; |
| 10 | struct object_array; |
Derrick Stolee | 5227c38 | 2018-07-20 16:33:02 +0000 | [diff] [blame] | 11 | |
Stefan Beller | 21a9651 | 2018-11-13 16:12:55 -0800 | [diff] [blame] | 12 | struct commit_list *repo_get_merge_bases(struct repository *r, |
| 13 | struct commit *rev1, |
| 14 | struct commit *rev2); |
| 15 | struct commit_list *repo_get_merge_bases_many(struct repository *r, |
| 16 | struct commit *one, int n, |
| 17 | struct commit **twos); |
Derrick Stolee | 5227c38 | 2018-07-20 16:33:02 +0000 | [diff] [blame] | 18 | /* To be used only when object flags after this call no longer matter */ |
Stefan Beller | 21a9651 | 2018-11-13 16:12:55 -0800 | [diff] [blame] | 19 | struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r, |
| 20 | struct commit *one, int n, |
| 21 | struct commit **twos); |
| 22 | #ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS |
| 23 | #define get_merge_bases(r1, r2) repo_get_merge_bases(the_repository, r1, r2) |
| 24 | #define get_merge_bases_many(one, n, two) repo_get_merge_bases_many(the_repository, one, n, two) |
| 25 | #define get_merge_bases_many_dirty(one, n, twos) repo_get_merge_bases_many_dirty(the_repository, one, n, twos) |
| 26 | #endif |
| 27 | |
Derrick Stolee | 5227c38 | 2018-07-20 16:33:02 +0000 | [diff] [blame] | 28 | struct commit_list *get_octopus_merge_bases(struct commit_list *in); |
| 29 | |
Carlo Marcelo Arenas Belón | c1ea625 | 2020-06-23 11:42:22 -0700 | [diff] [blame] | 30 | int repo_is_descendant_of(struct repository *r, |
| 31 | struct commit *commit, |
| 32 | struct commit_list *with_commit); |
Stefan Beller | 4d5430f | 2018-11-13 16:12:56 -0800 | [diff] [blame] | 33 | int repo_in_merge_bases(struct repository *r, |
| 34 | struct commit *commit, |
| 35 | struct commit *reference); |
| 36 | int repo_in_merge_bases_many(struct repository *r, |
| 37 | struct commit *commit, |
| 38 | int nr_reference, struct commit **reference); |
| 39 | #ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS |
| 40 | #define in_merge_bases(c1, c2) repo_in_merge_bases(the_repository, c1, c2) |
| 41 | #define in_merge_bases_many(c1, n, cs) repo_in_merge_bases_many(the_repository, c1, n, cs) |
| 42 | #endif |
Derrick Stolee | 5227c38 | 2018-07-20 16:33:02 +0000 | [diff] [blame] | 43 | |
Derrick Stolee | 5227c38 | 2018-07-20 16:33:02 +0000 | [diff] [blame] | 44 | /* |
| 45 | * Takes a list of commits and returns a new list where those |
| 46 | * have been removed that can be reached from other commits in |
| 47 | * the list. It is useful for, e.g., reducing the commits |
| 48 | * randomly thrown at the git-merge command and removing |
| 49 | * redundant commits that the user shouldn't have given to it. |
| 50 | * |
| 51 | * This function destroys the STALE bit of the commit objects' |
| 52 | * flags. |
| 53 | */ |
| 54 | struct commit_list *reduce_heads(struct commit_list *heads); |
| 55 | |
| 56 | /* |
| 57 | * Like `reduce_heads()`, except it replaces the list. Use this |
| 58 | * instead of `foo = reduce_heads(foo);` to avoid memory leaks. |
| 59 | */ |
| 60 | void reduce_heads_replace(struct commit_list **heads); |
| 61 | |
Derrick Stolee | 1d614d4 | 2018-07-20 16:33:06 +0000 | [diff] [blame] | 62 | int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid); |
| 63 | |
Derrick Stolee | 920f93c | 2018-07-20 16:33:08 +0000 | [diff] [blame] | 64 | /* |
| 65 | * Unknown has to be "0" here, because that's the default value for |
| 66 | * contains_cache slab entries that have not yet been assigned. |
| 67 | */ |
| 68 | enum contains_result { |
| 69 | CONTAINS_UNKNOWN = 0, |
| 70 | CONTAINS_NO, |
| 71 | CONTAINS_YES |
| 72 | }; |
| 73 | |
| 74 | define_commit_slab(contains_cache, enum contains_result); |
| 75 | |
| 76 | int commit_contains(struct ref_filter *filter, struct commit *commit, |
| 77 | struct commit_list *list, struct contains_cache *cache); |
| 78 | |
Derrick Stolee | ba3ca1e | 2018-07-20 16:33:13 +0000 | [diff] [blame] | 79 | /* |
| 80 | * Determine if every commit in 'from' can reach at least one commit |
| 81 | * that is marked with 'with_flag'. As we traverse, use 'assign_flag' |
| 82 | * as a marker for commits that are already visited. Do not walk |
Derrick Stolee | 4fbcca4 | 2018-07-20 16:33:28 +0000 | [diff] [blame] | 83 | * commits with date below 'min_commit_date' or generation below |
| 84 | * 'min_generation'. |
Derrick Stolee | ba3ca1e | 2018-07-20 16:33:13 +0000 | [diff] [blame] | 85 | */ |
| 86 | int can_all_from_reach_with_flag(struct object_array *from, |
| 87 | unsigned int with_flag, |
| 88 | unsigned int assign_flag, |
Derrick Stolee | 4fbcca4 | 2018-07-20 16:33:28 +0000 | [diff] [blame] | 89 | time_t min_commit_date, |
| 90 | uint32_t min_generation); |
Derrick Stolee | 1792bc1 | 2018-07-20 16:33:23 +0000 | [diff] [blame] | 91 | int can_all_from_reach(struct commit_list *from, struct commit_list *to, |
| 92 | int commit_date_cutoff); |
Derrick Stolee | ba3ca1e | 2018-07-20 16:33:13 +0000 | [diff] [blame] | 93 | |
Derrick Stolee | fcb2c07 | 2018-11-02 06:14:45 -0700 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * Return a list of commits containing the commits in the 'to' array |
| 97 | * that are reachable from at least one commit in the 'from' array. |
| 98 | * Also add the given 'flag' to each of the commits in the returned list. |
| 99 | * |
| 100 | * This method uses the PARENT1 and PARENT2 flags during its operation, |
| 101 | * so be sure these flags are not set before calling the method. |
| 102 | */ |
| 103 | struct commit_list *get_reachable_subset(struct commit **from, int nr_from, |
| 104 | struct commit **to, int nr_to, |
| 105 | unsigned int reachable_flag); |
| 106 | |
Derrick Stolee | 5227c38 | 2018-07-20 16:33:02 +0000 | [diff] [blame] | 107 | #endif |