Skip to content

Commit f87056c

Browse files
dschogitster
authored andcommitted
commit-reach(get_octopus_merge_bases): pass on "missing commits" errors
The `merge_bases_many()` function was just taught to indicate parsing errors, and now the `repo_get_merge_bases()` function (which is also surfaced via the `get_merge_bases()` macro) is aware of that, too. Naturally, the callers need to be adjusted now, too. Next step: adjust `repo_get_merge_bases_many()`. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 76e2a09 commit f87056c

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

builtin/merge-base.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ static int handle_independent(int count, const char **args)
7474
static int handle_octopus(int count, const char **args, int show_all)
7575
{
7676
struct commit_list *revs = NULL;
77-
struct commit_list *result, *rev;
77+
struct commit_list *result = NULL, *rev;
7878
int i;
7979

8080
for (i = count - 1; i >= 0; i--)
8181
commit_list_insert(get_commit_reference(args[i]), &revs);
8282

83-
result = get_octopus_merge_bases(revs);
83+
if (get_octopus_merge_bases(revs, &result) < 0) {
84+
free_commit_list(revs);
85+
free_commit_list(result);
86+
return 128;
87+
}
8488
free_commit_list(revs);
8589
reduce_heads_replace(&result);
8690

builtin/merge.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
15231523
} else {
15241524
struct commit_list *list = remoteheads;
15251525
commit_list_insert(head_commit, &list);
1526-
common = get_octopus_merge_bases(list);
1526+
if (get_octopus_merge_bases(list, &common) < 0) {
1527+
free(list);
1528+
ret = 2;
1529+
goto done;
1530+
}
15271531
free(list);
15281532
}
15291533

builtin/pull.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ static int get_octopus_merge_base(struct object_id *merge_base,
815815
const struct object_id *merge_head,
816816
const struct object_id *fork_point)
817817
{
818-
struct commit_list *revs = NULL, *result;
818+
struct commit_list *revs = NULL, *result = NULL;
819819

820820
commit_list_insert(lookup_commit_reference(the_repository, curr_head),
821821
&revs);
@@ -825,7 +825,8 @@ static int get_octopus_merge_base(struct object_id *merge_base,
825825
commit_list_insert(lookup_commit_reference(the_repository, fork_point),
826826
&revs);
827827

828-
result = get_octopus_merge_bases(revs);
828+
if (get_octopus_merge_bases(revs, &result) < 0)
829+
exit(128);
829830
free_commit_list(revs);
830831
reduce_heads_replace(&result);
831832

commit-reach.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,24 +175,26 @@ static int merge_bases_many(struct repository *r,
175175
return 0;
176176
}
177177

178-
struct commit_list *get_octopus_merge_bases(struct commit_list *in)
178+
int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result)
179179
{
180-
struct commit_list *i, *j, *k, *ret = NULL;
180+
struct commit_list *i, *j, *k;
181181

182182
if (!in)
183-
return ret;
183+
return 0;
184184

185-
commit_list_insert(in->item, &ret);
185+
commit_list_insert(in->item, result);
186186

187187
for (i = in->next; i; i = i->next) {
188188
struct commit_list *new_commits = NULL, *end = NULL;
189189

190-
for (j = ret; j; j = j->next) {
190+
for (j = *result; j; j = j->next) {
191191
struct commit_list *bases = NULL;
192192
if (repo_get_merge_bases(the_repository, i->item,
193193
j->item, &bases) < 0) {
194194
free_commit_list(bases);
195-
return NULL;
195+
free_commit_list(*result);
196+
*result = NULL;
197+
return -1;
196198
}
197199
if (!new_commits)
198200
new_commits = bases;
@@ -201,10 +203,10 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)
201203
for (k = bases; k; k = k->next)
202204
end = k;
203205
}
204-
free_commit_list(ret);
205-
ret = new_commits;
206+
free_commit_list(*result);
207+
*result = new_commits;
206208
}
207-
return ret;
209+
return 0;
208210
}
209211

210212
static int remove_redundant_no_gen(struct repository *r,

commit-reach.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
2121
struct commit *one, int n,
2222
struct commit **twos);
2323

24-
struct commit_list *get_octopus_merge_bases(struct commit_list *in);
24+
int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result);
2525

2626
int repo_is_descendant_of(struct repository *r,
2727
struct commit *commit,

0 commit comments

Comments
 (0)