Skip to content

Commit 207c40e

Browse files
dschogitster
authored andcommitted
commit-reach(repo_in_merge_bases_many): optionally expect missing commits
Currently this function treats unrelated commit histories the same way as commit histories with missing commit objects. Typically, missing commit objects constitute a corrupt repository, though, and should be reported as such. The next commits will make it so, but there is one exception: In `git fetch --update-shallow` we _expect_ commit objects to be missing, and we do want to treat the now-incomplete commit histories as unrelated. To allow for that, let's introduce an additional parameter that is passed to `repo_in_merge_bases_many()` to trigger this behavior, and use it in the two callers in `shallow.c`. This commit changes behavior slightly: unless called from the `shallow.c` functions that set the `ignore_missing_commits` bit, any non-existing tip commit that is passed to `repo_in_merge_bases_many()` will now result in an error. Note: When encountering missing commits while traversing the commit history in search for merge bases, with this commit there won't be a change in behavior just yet, their children will still be interpreted as root commits. This bug will get fixed by follow-up commits. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e67431d commit 207c40e

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

commit-reach.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ int repo_is_descendant_of(struct repository *r,
466466

467467
other = with_commit->item;
468468
with_commit = with_commit->next;
469-
if (repo_in_merge_bases_many(r, other, 1, &commit))
469+
if (repo_in_merge_bases_many(r, other, 1, &commit, 0))
470470
return 1;
471471
}
472472
return 0;
@@ -477,17 +477,18 @@ int repo_is_descendant_of(struct repository *r,
477477
* Is "commit" an ancestor of one of the "references"?
478478
*/
479479
int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
480-
int nr_reference, struct commit **reference)
480+
int nr_reference, struct commit **reference,
481+
int ignore_missing_commits)
481482
{
482483
struct commit_list *bases;
483484
int ret = 0, i;
484485
timestamp_t generation, max_generation = GENERATION_NUMBER_ZERO;
485486

486487
if (repo_parse_commit(r, commit))
487-
return ret;
488+
return ignore_missing_commits ? 0 : -1;
488489
for (i = 0; i < nr_reference; i++) {
489490
if (repo_parse_commit(r, reference[i]))
490-
return ret;
491+
return ignore_missing_commits ? 0 : -1;
491492

492493
generation = commit_graph_generation(reference[i]);
493494
if (generation > max_generation)

commit-reach.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ int repo_in_merge_bases(struct repository *r,
3030
struct commit *reference);
3131
int repo_in_merge_bases_many(struct repository *r,
3232
struct commit *commit,
33-
int nr_reference, struct commit **reference);
33+
int nr_reference, struct commit **reference,
34+
int ignore_missing_commits);
3435

3536
/*
3637
* Takes a list of commits and returns a new list where those

remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2680,7 +2680,7 @@ static int is_reachable_in_reflog(const char *local, const struct ref *remote)
26802680
if (MERGE_BASES_BATCH_SIZE < size)
26812681
size = MERGE_BASES_BATCH_SIZE;
26822682

2683-
if ((ret = repo_in_merge_bases_many(the_repository, commit, size, chunk)))
2683+
if ((ret = repo_in_merge_bases_many(the_repository, commit, size, chunk, 0)))
26842684
break;
26852685
}
26862686

shallow.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ static void post_assign_shallow(struct shallow_info *info,
796796
for (j = 0; j < bitmap_nr; j++)
797797
if (bitmap[0][j] &&
798798
/* Step 7, reachability test at commit level */
799-
!repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits)) {
799+
!repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits, 1)) {
800800
update_refstatus(ref_status, info->ref->nr, *bitmap);
801801
dst++;
802802
break;
@@ -827,7 +827,8 @@ int delayed_reachability_test(struct shallow_info *si, int c)
827827
si->reachable[c] = repo_in_merge_bases_many(the_repository,
828828
commit,
829829
si->nr_commits,
830-
si->commits);
830+
si->commits,
831+
1);
831832
si->need_reachability_test[c] = 0;
832833
}
833834
return si->reachable[c];

t/helper/test-reach.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int cmd__reach(int ac, const char **av)
111111
repo_in_merge_bases(the_repository, A, B));
112112
else if (!strcmp(av[1], "in_merge_bases_many"))
113113
printf("%s(A,X):%d\n", av[1],
114-
repo_in_merge_bases_many(the_repository, A, X_nr, X_array));
114+
repo_in_merge_bases_many(the_repository, A, X_nr, X_array, 0));
115115
else if (!strcmp(av[1], "is_descendant_of"))
116116
printf("%s(A,X):%d\n", av[1], repo_is_descendant_of(r, A, X));
117117
else if (!strcmp(av[1], "get_merge_bases_many")) {

0 commit comments

Comments
 (0)