commit-reach(repo_get_merge_bases_many): pass on "missing commits" errors
The `merge_bases_many()` function was just taught to indicate parsing errors, and now the `repo_get_merge_bases_many()` function is aware of that, too. Naturally, there are a lot of callers that need to be adjusted now, too. Next stop: `repo_get_merge_bases_dirty()`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Feb 28, 2024 at 09:44 UTC
531738052158fd66bc9b65534309f5c0a9d2808d
6 files changed
+31
-28
bisect.c
+4
-3
@@ -836,10 +836,11 @@ static void handle_skipped_merge_base(const struct object_id *mb)
836
static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
837
{
838
enum bisect_error res = BISECT_OK;
839
- struct commit_list *result;
839
+ struct commit_list *result = NULL;
840
841
- result = repo_get_merge_bases_many(the_repository, rev[0], rev_nr - 1,
842
- rev + 1);
841
+ if (repo_get_merge_bases_many(the_repository, rev[0], rev_nr - 1,
842
+ rev + 1, &result) < 0)
843
+ exit(128);
844
845
for (; result; result = result->next) {
846
const struct object_id *mb = &result->item->object.oid;
builtin/log.c
+7
-6
@@ -1658,7 +1658,7 @@ static struct commit *get_base_commit(const char *base_commit,
1658
struct branch *curr_branch = branch_get(NULL);
1659
const char *upstream = branch_get_upstream(curr_branch, NULL);
1660
if (upstream) {
1661
- struct commit_list *base_list;
1661
+ struct commit_list *base_list = NULL;
1662
struct commit *commit;
1663
struct object_id oid;
1664
@@ -1669,11 +1669,12 @@ static struct commit *get_base_commit(const char *base_commit,
1669
return NULL;
1670
}
1671
commit = lookup_commit_or_die(&oid, "upstream base");
1672
- base_list = repo_get_merge_bases_many(the_repository,
1673
- commit, total,
1674
- list);
1675
- /* There should be one and only one merge base. */
1676
- if (!base_list || base_list->next) {
1672
+ if (repo_get_merge_bases_many(the_repository,
1673
+ commit, total,
1674
+ list,
1675
+ &base_list) < 0 ||
1676
+ /* There should be one and only one merge base. */
1677
+ !base_list || base_list->next) {
1678
if (die_on_failure) {
1679
die(_("could not find exact merge base"));
1680
} else {
commit-reach.c
+6
-10
@@ -461,17 +461,13 @@ static int get_merge_bases_many_0(struct repository *r,
461
return 0;
462
}
463
464
-struct commit_list *repo_get_merge_bases_many(struct repository *r,
465
- struct commit *one,
466
- int n,
467
- struct commit **twos)
464
+int repo_get_merge_bases_many(struct repository *r,
465
+ struct commit *one,
466
+ int n,
467
+ struct commit **twos,
468
+ struct commit_list **result)
469
{
469
- struct commit_list *result = NULL;
470
- if (get_merge_bases_many_0(r, one, n, twos, 1, &result) < 0) {
471
- free_commit_list(result);
472
- return NULL;
473
- }
474
- return result;
470
+ return get_merge_bases_many_0(r, one, n, twos, 1, result);
471
}
472
473
struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
commit-reach.h
+4
-3
@@ -13,9 +13,10 @@ int repo_get_merge_bases(struct repository *r,
13
struct commit *rev1,
14
struct commit *rev2,
15
struct commit_list **result);
16
-struct commit_list *repo_get_merge_bases_many(struct repository *r,
17
- struct commit *one, int n,
18
- struct commit **twos);
16
+int repo_get_merge_bases_many(struct repository *r,
17
+ struct commit *one, int n,
18
+ struct commit **twos,
19
+ struct commit_list **result);
20
/* To be used only when object flags after this call no longer matter */
21
struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
22
struct commit *one, int n,
commit.c
+4
-3
@@ -1052,7 +1052,7 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
1052
{
1053
struct object_id oid;
1054
struct rev_collect revs;
1055
- struct commit_list *bases;
1055
+ struct commit_list *bases = NULL;
1056
int i;
1057
struct commit *ret = NULL;
1058
char *full_refname;
@@ -1077,8 +1077,9 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
1077
for (i = 0; i < revs.nr; i++)
1078
revs.commit[i]->object.flags &= ~TMP_MARK;
1079
1080
- bases = repo_get_merge_bases_many(the_repository, commit, revs.nr,
1081
- revs.commit);
1080
+ if (repo_get_merge_bases_many(the_repository, commit, revs.nr,
1081
+ revs.commit, &bases) < 0)
1082
+ exit(128);
1083
1084
/*
1085
* There should be one and only one merge base, when we found
t/helper/test-reach.c
+6
-3
@@ -115,9 +115,12 @@ int cmd__reach(int ac, const char **av)
115
else if (!strcmp(av[1], "is_descendant_of"))
116
printf("%s(A,X):%d\n", av[1], repo_is_descendant_of(r, A, X));
117
else if (!strcmp(av[1], "get_merge_bases_many")) {
118
- struct commit_list *list = repo_get_merge_bases_many(the_repository,
119
- A, X_nr,
120
- X_array);
118
+ struct commit_list *list = NULL;
119
+ if (repo_get_merge_bases_many(the_repository,
120
+ A, X_nr,
121
+ X_array,
122
+ &list) < 0)
123
+ exit(128);
124
printf("%s(A,X):\n", av[1]);
125
print_sorted_commit_ids(list);
126
} else if (!strcmp(av[1], "reduce_heads")) {