Skip to content

Commit aaeff44

Browse files
committed
Fixed --shallow-since generating descendant borders
When shallow cloning based on a date, it happens that a list of commits is received, where some of the list border commits actually descend one from another. In such cases borders need to be expanded by additional parents and excluding the child as border. Signed-off-by: Samo Pogačnik <samo_pogacnik@t-2.net>
1 parent debbc87 commit aaeff44

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

shallow.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,50 @@ struct commit_list *get_shallow_commits_by_rev_list(struct strvec *argv,
251251
* commit A is processed first, then commit B, whose parent is
252252
* A, later. If NOT_SHALLOW on A is cleared at step 1, B
253253
* itself is considered border at step 2, which is incorrect.
254+
* We must also consider that B has multiple parents, some of
255+
* them not being in the not_shallow_list, but must be added
256+
* as border commits to the result.
257+
*
258+
* The general processing goes like this:
259+
* 1. Above we've coloured the whole not_shallow_list of commits
260+
* with 'not_shallow'.
261+
* 2. For each commit from the not_shallow_list (the code below)
262+
* we colour 'shallow' the commit and its parents, which are not
263+
* already coloured 'not_shallow'.
264+
* 3. Commits with all parents being coloured only 'shallow' remain
265+
* shallow and are being added to result list.
266+
* 4. Commits without all parents being coloured only 'shallow' are
267+
* being excluded as borders, however their parents coloured only
268+
* 'shallow' are being added to the result borders list.
254269
*/
255270
for (p = not_shallow_list; p; p = p->next) {
256271
struct commit *c = p->item;
257272
struct commit_list *parent;
273+
int must_not_be_shallow = 0;
258274

259275
if (repo_parse_commit(the_repository, c))
260276
die("unable to parse commit %s",
261277
oid_to_hex(&c->object.oid));
262278

263279
for (parent = c->parents; parent; parent = parent->next)
264-
if (!(parent->item->object.flags & not_shallow_flag)) {
280+
if (parent->item->object.flags & not_shallow_flag) {
281+
must_not_be_shallow = 1;
282+
} else {
265283
c->object.flags |= shallow_flag;
266-
commit_list_insert(c, &result);
267-
break;
284+
parent->item->object.flags |= shallow_flag;
268285
}
286+
if (must_not_be_shallow) {
287+
c->object.flags &= ~shallow_flag;
288+
for (parent = c->parents; parent; parent = parent->next)
289+
if (parent->item->object.flags & shallow_flag) {
290+
parent->item->object.flags |= not_shallow_flag;
291+
commit_list_insert(parent->item, &result);
292+
}
293+
} else {
294+
for (parent = c->parents; parent; parent = parent->next)
295+
parent->item->object.flags &= ~shallow_flag;
296+
commit_list_insert(c, &result);
297+
}
269298
}
270299
free_commit_list(not_shallow_list);
271300

0 commit comments

Comments
 (0)