|
10 | 10 | #include "diff.h"
|
11 | 11 | #include "revision.h"
|
12 | 12 | #include "commit-slab.h"
|
| 13 | +#include "revision.h" |
| 14 | +#include "list-objects.h" |
13 | 15 |
|
14 | 16 | static int is_shallow = -1;
|
15 | 17 | static struct stat_validity shallow_stat;
|
@@ -137,6 +139,82 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
|
137 | 139 | return result;
|
138 | 140 | }
|
139 | 141 |
|
| 142 | +static void show_commit(struct commit *commit, void *data) |
| 143 | +{ |
| 144 | + commit_list_insert(commit, data); |
| 145 | +} |
| 146 | + |
| 147 | +/* |
| 148 | + * Given rev-list arguments, run rev-list. All reachable commits |
| 149 | + * except border ones are marked with not_shallow_flag. Border commits |
| 150 | + * are marked with shallow_flag. The list of border/shallow commits |
| 151 | + * are also returned. |
| 152 | + */ |
| 153 | +struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av, |
| 154 | + int shallow_flag, |
| 155 | + int not_shallow_flag) |
| 156 | +{ |
| 157 | + struct commit_list *result = NULL, *p; |
| 158 | + struct commit_list *not_shallow_list = NULL; |
| 159 | + struct rev_info revs; |
| 160 | + int both_flags = shallow_flag | not_shallow_flag; |
| 161 | + |
| 162 | + /* |
| 163 | + * SHALLOW (excluded) and NOT_SHALLOW (included) should not be |
| 164 | + * set at this point. But better be safe than sorry. |
| 165 | + */ |
| 166 | + clear_object_flags(both_flags); |
| 167 | + |
| 168 | + is_repository_shallow(); /* make sure shallows are read */ |
| 169 | + |
| 170 | + init_revisions(&revs, NULL); |
| 171 | + save_commit_buffer = 0; |
| 172 | + setup_revisions(ac, av, &revs, NULL); |
| 173 | + |
| 174 | + if (prepare_revision_walk(&revs)) |
| 175 | + die("revision walk setup failed"); |
| 176 | + traverse_commit_list(&revs, show_commit, NULL, ¬_shallow_list); |
| 177 | + |
| 178 | + /* Mark all reachable commits as NOT_SHALLOW */ |
| 179 | + for (p = not_shallow_list; p; p = p->next) |
| 180 | + p->item->object.flags |= not_shallow_flag; |
| 181 | + |
| 182 | + /* |
| 183 | + * mark border commits SHALLOW + NOT_SHALLOW. |
| 184 | + * We cannot clear NOT_SHALLOW right now. Imagine border |
| 185 | + * commit A is processed first, then commit B, whose parent is |
| 186 | + * A, later. If NOT_SHALLOW on A is cleared at step 1, B |
| 187 | + * itself is considered border at step 2, which is incorrect. |
| 188 | + */ |
| 189 | + for (p = not_shallow_list; p; p = p->next) { |
| 190 | + struct commit *c = p->item; |
| 191 | + struct commit_list *parent; |
| 192 | + |
| 193 | + if (parse_commit(c)) |
| 194 | + die("unable to parse commit %s", |
| 195 | + oid_to_hex(&c->object.oid)); |
| 196 | + |
| 197 | + for (parent = c->parents; parent; parent = parent->next) |
| 198 | + if (!(parent->item->object.flags & not_shallow_flag)) { |
| 199 | + c->object.flags |= shallow_flag; |
| 200 | + commit_list_insert(c, &result); |
| 201 | + break; |
| 202 | + } |
| 203 | + } |
| 204 | + free_commit_list(not_shallow_list); |
| 205 | + |
| 206 | + /* |
| 207 | + * Now we can clean up NOT_SHALLOW on border commits. Having |
| 208 | + * both flags set can confuse the caller. |
| 209 | + */ |
| 210 | + for (p = result; p; p = p->next) { |
| 211 | + struct object *o = &p->item->object; |
| 212 | + if ((o->flags & both_flags) == both_flags) |
| 213 | + o->flags &= ~not_shallow_flag; |
| 214 | + } |
| 215 | + return result; |
| 216 | +} |
| 217 | + |
140 | 218 | static void check_shallow_file_for_update(void)
|
141 | 219 | {
|
142 | 220 | if (is_shallow == -1)
|
|
0 commit comments