]>
Commit | Line | Data |
---|---|---|
0009d350 RJ |
1 | #ifndef COMMIT_REACH_H |
2 | #define COMMIT_REACH_H | |
5227c385 | 3 | |
1406725b | 4 | #include "commit.h" |
920f93ca DS |
5 | #include "commit-slab.h" |
6 | ||
5227c385 | 7 | struct commit_list; |
920f93ca | 8 | struct ref_filter; |
1406725b RJ |
9 | struct object_id; |
10 | struct object_array; | |
5227c385 | 11 | |
76e2a099 JS |
12 | int repo_get_merge_bases(struct repository *r, |
13 | struct commit *rev1, | |
14 | struct commit *rev2, | |
15 | struct commit_list **result); | |
21a9651b SB |
16 | struct commit_list *repo_get_merge_bases_many(struct repository *r, |
17 | struct commit *one, int n, | |
18 | struct commit **twos); | |
5227c385 | 19 | /* To be used only when object flags after this call no longer matter */ |
21a9651b SB |
20 | struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r, |
21 | struct commit *one, int n, | |
22 | struct commit **twos); | |
21a9651b | 23 | |
f87056ce | 24 | int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result); |
5227c385 | 25 | |
c1ea625f CMAB |
26 | int repo_is_descendant_of(struct repository *r, |
27 | struct commit *commit, | |
28 | struct commit_list *with_commit); | |
4d5430f7 SB |
29 | int repo_in_merge_bases(struct repository *r, |
30 | struct commit *commit, | |
31 | struct commit *reference); | |
32 | int repo_in_merge_bases_many(struct repository *r, | |
33 | struct commit *commit, | |
207c40e1 JS |
34 | int nr_reference, struct commit **reference, |
35 | int ignore_missing_commits); | |
5227c385 | 36 | |
5227c385 DS |
37 | /* |
38 | * Takes a list of commits and returns a new list where those | |
39 | * have been removed that can be reached from other commits in | |
40 | * the list. It is useful for, e.g., reducing the commits | |
41 | * randomly thrown at the git-merge command and removing | |
42 | * redundant commits that the user shouldn't have given to it. | |
43 | * | |
44 | * This function destroys the STALE bit of the commit objects' | |
45 | * flags. | |
46 | */ | |
47 | struct commit_list *reduce_heads(struct commit_list *heads); | |
48 | ||
49 | /* | |
50 | * Like `reduce_heads()`, except it replaces the list. Use this | |
51 | * instead of `foo = reduce_heads(foo);` to avoid memory leaks. | |
52 | */ | |
53 | void reduce_heads_replace(struct commit_list **heads); | |
54 | ||
1d614d41 DS |
55 | int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid); |
56 | ||
920f93ca DS |
57 | /* |
58 | * Unknown has to be "0" here, because that's the default value for | |
59 | * contains_cache slab entries that have not yet been assigned. | |
60 | */ | |
61 | enum contains_result { | |
62 | CONTAINS_UNKNOWN = 0, | |
63 | CONTAINS_NO, | |
64 | CONTAINS_YES | |
65 | }; | |
66 | ||
67 | define_commit_slab(contains_cache, enum contains_result); | |
68 | ||
69 | int commit_contains(struct ref_filter *filter, struct commit *commit, | |
70 | struct commit_list *list, struct contains_cache *cache); | |
71 | ||
ba3ca1ed DS |
72 | /* |
73 | * Determine if every commit in 'from' can reach at least one commit | |
74 | * that is marked with 'with_flag'. As we traverse, use 'assign_flag' | |
75 | * as a marker for commits that are already visited. Do not walk | |
4fbcca4e DS |
76 | * commits with date below 'min_commit_date' or generation below |
77 | * 'min_generation'. | |
ba3ca1ed DS |
78 | */ |
79 | int can_all_from_reach_with_flag(struct object_array *from, | |
80 | unsigned int with_flag, | |
81 | unsigned int assign_flag, | |
4fbcca4e | 82 | time_t min_commit_date, |
d7f92784 | 83 | timestamp_t min_generation); |
1792bc12 DS |
84 | int can_all_from_reach(struct commit_list *from, struct commit_list *to, |
85 | int commit_date_cutoff); | |
ba3ca1ed | 86 | |
fcb2c076 DS |
87 | |
88 | /* | |
89 | * Return a list of commits containing the commits in the 'to' array | |
90 | * that are reachable from at least one commit in the 'from' array. | |
91 | * Also add the given 'flag' to each of the commits in the returned list. | |
92 | * | |
93 | * This method uses the PARENT1 and PARENT2 flags during its operation, | |
94 | * so be sure these flags are not set before calling the method. | |
95 | */ | |
96 | struct commit_list *get_reachable_subset(struct commit **from, int nr_from, | |
97 | struct commit **to, int nr_to, | |
98 | unsigned int reachable_flag); | |
99 | ||
fd67d149 DS |
100 | struct ahead_behind_count { |
101 | /** | |
102 | * As input, the *_index members indicate which positions in | |
103 | * the 'tips' array correspond to the tip and base of this | |
104 | * comparison. | |
105 | */ | |
106 | size_t tip_index; | |
107 | size_t base_index; | |
108 | ||
109 | /** | |
110 | * These values store the computed counts for each side of the | |
111 | * symmetric difference: | |
112 | * | |
113 | * 'ahead' stores the number of commits reachable from the tip | |
114 | * and not reachable from the base. | |
115 | * | |
116 | * 'behind' stores the number of commits reachable from the base | |
117 | * and not reachable from the tip. | |
118 | */ | |
119 | unsigned int ahead; | |
120 | unsigned int behind; | |
121 | }; | |
122 | ||
123 | /* | |
124 | * Given an array of commits and an array of ahead_behind_count pairs, | |
125 | * compute the ahead/behind counts for each pair. | |
126 | */ | |
127 | void ahead_behind(struct repository *r, | |
128 | struct commit **commits, size_t commits_nr, | |
129 | struct ahead_behind_count *counts, size_t counts_nr); | |
130 | ||
cbfe360b DS |
131 | /* |
132 | * For all tip commits, add 'mark' to their flags if and only if they | |
133 | * are reachable from one of the commits in 'bases'. | |
134 | */ | |
135 | void tips_reachable_from_bases(struct repository *r, | |
136 | struct commit_list *bases, | |
137 | struct commit **tips, size_t tips_nr, | |
138 | int mark); | |
139 | ||
5227c385 | 140 | #endif |