Skip to content

Commit 5317380

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f87056c commit 5317380

File tree

6 files changed

+31
-28
lines changed

6 files changed

+31
-28
lines changed

bisect.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,11 @@ static void handle_skipped_merge_base(const struct object_id *mb)
836836
static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
837837
{
838838
enum bisect_error res = BISECT_OK;
839-
struct commit_list *result;
839+
struct commit_list *result = NULL;
840840

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);
843844

844845
for (; result; result = result->next) {
845846
const struct object_id *mb = &result->item->object.oid;

builtin/log.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,7 @@ static struct commit *get_base_commit(const char *base_commit,
16581658
struct branch *curr_branch = branch_get(NULL);
16591659
const char *upstream = branch_get_upstream(curr_branch, NULL);
16601660
if (upstream) {
1661-
struct commit_list *base_list;
1661+
struct commit_list *base_list = NULL;
16621662
struct commit *commit;
16631663
struct object_id oid;
16641664

@@ -1669,11 +1669,12 @@ static struct commit *get_base_commit(const char *base_commit,
16691669
return NULL;
16701670
}
16711671
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) {
16771678
if (die_on_failure) {
16781679
die(_("could not find exact merge base"));
16791680
} else {

commit-reach.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,17 +461,13 @@ static int get_merge_bases_many_0(struct repository *r,
461461
return 0;
462462
}
463463

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)
468469
{
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);
475471
}
476472

477473
struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,

commit-reach.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ int repo_get_merge_bases(struct repository *r,
1313
struct commit *rev1,
1414
struct commit *rev2,
1515
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);
1920
/* To be used only when object flags after this call no longer matter */
2021
struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
2122
struct commit *one, int n,

commit.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
10521052
{
10531053
struct object_id oid;
10541054
struct rev_collect revs;
1055-
struct commit_list *bases;
1055+
struct commit_list *bases = NULL;
10561056
int i;
10571057
struct commit *ret = NULL;
10581058
char *full_refname;
@@ -1077,8 +1077,9 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
10771077
for (i = 0; i < revs.nr; i++)
10781078
revs.commit[i]->object.flags &= ~TMP_MARK;
10791079

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);
10821083

10831084
/*
10841085
* There should be one and only one merge base, when we found

t/helper/test-reach.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,12 @@ int cmd__reach(int ac, const char **av)
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")) {
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);
121124
printf("%s(A,X):\n", av[1]);
122125
print_sorted_commit_ids(list);
123126
} else if (!strcmp(av[1], "reduce_heads")) {

0 commit comments

Comments
 (0)