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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Feb 28, 2024 at 09:44 UTC f87056ce403b5572683a45efe0e9021777831894
5 files changed +26 -15
builtin/merge-base.c
+6 -2
@@ -74,13 +74,17 @@ static int handle_independent(int count, const char **args)
74 static int handle_octopus(int count, const char **args, int show_all)
75 {
76 struct commit_list *revs = NULL;
77 - struct commit_list *result, *rev;
77 + struct commit_list *result = NULL, *rev;
78 int i;
79
80 for (i = count - 1; i >= 0; i--)
81 commit_list_insert(get_commit_reference(args[i]), &revs);
82
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 + }
88 free_commit_list(revs);
89 reduce_heads_replace(&result);
90
builtin/merge.c
+5 -1
@@ -1523,7 +1523,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1523 } else {
1524 struct commit_list *list = remoteheads;
1525 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 + }
1531 free(list);
1532 }
1533
builtin/pull.c
+3 -2
@@ -815,7 +815,7 @@ static int get_octopus_merge_base(struct object_id *merge_base,
815 const struct object_id *merge_head,
816 const struct object_id *fork_point)
817 {
818 - struct commit_list *revs = NULL, *result;
818 + struct commit_list *revs = NULL, *result = NULL;
819
820 commit_list_insert(lookup_commit_reference(the_repository, curr_head),
821 &revs);
@@ -825,7 +825,8 @@ static int get_octopus_merge_base(struct object_id *merge_base,
825 commit_list_insert(lookup_commit_reference(the_repository, fork_point),
826 &revs);
827
828 - result = get_octopus_merge_bases(revs);
828 + if (get_octopus_merge_bases(revs, &result) < 0)
829 + exit(128);
830 free_commit_list(revs);
831 reduce_heads_replace(&result);
832
commit-reach.c
+11 -9
@@ -175,24 +175,26 @@ static int merge_bases_many(struct repository *r,
175 return 0;
176 }
177
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)
179 {
180 - struct commit_list *i, *j, *k, *ret = NULL;
180 + struct commit_list *i, *j, *k;
181
182 if (!in)
183 - return ret;
183 + return 0;
184
185 - commit_list_insert(in->item, &ret);
185 + commit_list_insert(in->item, result);
186
187 for (i = in->next; i; i = i->next) {
188 struct commit_list *new_commits = NULL, *end = NULL;
189
190 - for (j = ret; j; j = j->next) {
190 + for (j = *result; j; j = j->next) {
191 struct commit_list *bases = NULL;
192 if (repo_get_merge_bases(the_repository, i->item,
193 j->item, &bases) < 0) {
194 free_commit_list(bases);
195 - return NULL;
195 + free_commit_list(*result);
196 + *result = NULL;
197 + return -1;
198 }
199 if (!new_commits)
200 new_commits = bases;
@@ -201,10 +203,10 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)
203 for (k = bases; k; k = k->next)
204 end = k;
205 }
204 - free_commit_list(ret);
205 - ret = new_commits;
206 + free_commit_list(*result);
207 + *result = new_commits;
208 }
207 - return ret;
209 + return 0;
210 }
211
212 static int remove_redundant_no_gen(struct repository *r,
commit-reach.h
+1 -1
@@ -21,7 +21,7 @@ struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
21 struct commit *one, int n,
22 struct commit **twos);
23
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);
25
26 int repo_is_descendant_of(struct repository *r,
27 struct commit *commit,