Skip to content

Commit fb02c52

Browse files
dschogitster
authored andcommitted
commit-reach(merge_bases_many): pass on "missing commits" errors
The `paint_down_to_common()` function was just taught to indicate parsing errors, and now the `merge_bases_many()` function is aware of that, too. One tricky aspect is that `merge_bases_many()` parses commits of its own, but wants to gracefully handle the scenario where NULL is passed as a merge head, returning the empty list of merge bases. The way this was handled involved calling `repo_parse_commit(NULL)` and relying on it to return an error. This has to be done differently now so that we can handle missing commits correctly by producing a fatal error. Next step: adjust the caller of `merge_bases_many()`: `get_merge_bases_many_0()`. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 896a0e1 commit fb02c52

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

commit-reach.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,41 +130,49 @@ static int paint_down_to_common(struct repository *r,
130130
return 0;
131131
}
132132

133-
static struct commit_list *merge_bases_many(struct repository *r,
134-
struct commit *one, int n,
135-
struct commit **twos)
133+
static int merge_bases_many(struct repository *r,
134+
struct commit *one, int n,
135+
struct commit **twos,
136+
struct commit_list **result)
136137
{
137138
struct commit_list *list = NULL;
138-
struct commit_list *result = NULL;
139139
int i;
140140

141141
for (i = 0; i < n; i++) {
142-
if (one == twos[i])
142+
if (one == twos[i]) {
143143
/*
144144
* We do not mark this even with RESULT so we do not
145145
* have to clean it up.
146146
*/
147-
return commit_list_insert(one, &result);
147+
*result = commit_list_insert(one, result);
148+
return 0;
149+
}
148150
}
149151

152+
if (!one)
153+
return 0;
150154
if (repo_parse_commit(r, one))
151-
return NULL;
155+
return error(_("could not parse commit %s"),
156+
oid_to_hex(&one->object.oid));
152157
for (i = 0; i < n; i++) {
158+
if (!twos[i])
159+
return 0;
153160
if (repo_parse_commit(r, twos[i]))
154-
return NULL;
161+
return error(_("could not parse commit %s"),
162+
oid_to_hex(&twos[i]->object.oid));
155163
}
156164

157165
if (paint_down_to_common(r, one, n, twos, 0, 0, &list)) {
158166
free_commit_list(list);
159-
return NULL;
167+
return -1;
160168
}
161169

162170
while (list) {
163171
struct commit *commit = pop_commit(&list);
164172
if (!(commit->object.flags & STALE))
165-
commit_list_insert_by_date(commit, &result);
173+
commit_list_insert_by_date(commit, result);
166174
}
167-
return result;
175+
return 0;
168176
}
169177

170178
struct commit_list *get_octopus_merge_bases(struct commit_list *in)
@@ -409,10 +417,11 @@ static struct commit_list *get_merge_bases_many_0(struct repository *r,
409417
{
410418
struct commit_list *list;
411419
struct commit **rslt;
412-
struct commit_list *result;
420+
struct commit_list *result = NULL;
413421
int cnt, i;
414422

415-
result = merge_bases_many(r, one, n, twos);
423+
if (merge_bases_many(r, one, n, twos, &result) < 0)
424+
return NULL;
416425
for (i = 0; i < n; i++) {
417426
if (one == twos[i])
418427
return result;

0 commit comments

Comments
 (0)