commit-reach(repo_in_merge_bases_many): report missing commits

Some functions in Git's source code follow the convention that returning
a negative value indicates a fatal error, e.g. repository corruption.

Let's use this convention in `repo_in_merge_bases()` to report when one
of the specified commits is missing (i.e. when `repo_parse_commit()`
reports an error).

Also adjust the callers of `repo_in_merge_bases()` to handle such
negative return values.

Note: As of this patch, errors are returned only if any of the specified
merge heads is missing. Over the course of the next patches, missing
commits will also be reported by the `paint_down_to_common()` function,
which is called by `repo_in_merge_bases_many()`, and those errors will
be properly propagated back to the caller at that stage.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin
2024-02-28 09:44:09 +00:00
committed by Junio C Hamano
parent 207c40e1e4
commit 24876ebf68
12 changed files with 173 additions and 36 deletions

View File

@ -794,12 +794,16 @@ static void post_assign_shallow(struct shallow_info *info,
if (!*bitmap)
continue;
for (j = 0; j < bitmap_nr; j++)
if (bitmap[0][j] &&
/* Step 7, reachability test at commit level */
!repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits, 1)) {
update_refstatus(ref_status, info->ref->nr, *bitmap);
dst++;
break;
if (bitmap[0][j]) {
/* Step 7, reachability test at commit level */
int ret = repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits, 1);
if (ret < 0)
exit(128);
if (!ret) {
update_refstatus(ref_status, info->ref->nr, *bitmap);
dst++;
break;
}
}
}
info->nr_ours = dst;
@ -829,6 +833,8 @@ int delayed_reachability_test(struct shallow_info *si, int c)
si->nr_commits,
si->commits,
1);
if (si->reachable[c] < 0)
exit(128);
si->need_reachability_test[c] = 0;
}
return si->reachable[c];