Skip to content

Commit 8226e15

Browse files
dschogitster
authored andcommitted
commit-reach(get_merge_bases_many_0): pass on "missing commits" errors
The `merge_bases_many()` function was just taught to indicate parsing errors, and now the `get_merge_bases_many_0()` function is aware of that, too. Next step: adjust the callers of `get_merge_bases_many_0()`. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb02c52 commit 8226e15

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

commit-reach.c

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -409,74 +409,89 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
409409
return remove_redundant_no_gen(r, array, cnt);
410410
}
411411

412-
static struct commit_list *get_merge_bases_many_0(struct repository *r,
413-
struct commit *one,
414-
int n,
415-
struct commit **twos,
416-
int cleanup)
412+
static int get_merge_bases_many_0(struct repository *r,
413+
struct commit *one,
414+
int n,
415+
struct commit **twos,
416+
int cleanup,
417+
struct commit_list **result)
417418
{
418419
struct commit_list *list;
419420
struct commit **rslt;
420-
struct commit_list *result = NULL;
421421
int cnt, i;
422422

423-
if (merge_bases_many(r, one, n, twos, &result) < 0)
424-
return NULL;
423+
if (merge_bases_many(r, one, n, twos, result) < 0)
424+
return -1;
425425
for (i = 0; i < n; i++) {
426426
if (one == twos[i])
427-
return result;
427+
return 0;
428428
}
429-
if (!result || !result->next) {
429+
if (!*result || !(*result)->next) {
430430
if (cleanup) {
431431
clear_commit_marks(one, all_flags);
432432
clear_commit_marks_many(n, twos, all_flags);
433433
}
434-
return result;
434+
return 0;
435435
}
436436

437437
/* There are more than one */
438-
cnt = commit_list_count(result);
438+
cnt = commit_list_count(*result);
439439
CALLOC_ARRAY(rslt, cnt);
440-
for (list = result, i = 0; list; list = list->next)
440+
for (list = *result, i = 0; list; list = list->next)
441441
rslt[i++] = list->item;
442-
free_commit_list(result);
442+
free_commit_list(*result);
443+
*result = NULL;
443444

444445
clear_commit_marks(one, all_flags);
445446
clear_commit_marks_many(n, twos, all_flags);
446447

447448
cnt = remove_redundant(r, rslt, cnt);
448449
if (cnt < 0) {
449450
free(rslt);
450-
return NULL;
451+
return -1;
451452
}
452-
result = NULL;
453453
for (i = 0; i < cnt; i++)
454-
commit_list_insert_by_date(rslt[i], &result);
454+
commit_list_insert_by_date(rslt[i], result);
455455
free(rslt);
456-
return result;
456+
return 0;
457457
}
458458

459459
struct commit_list *repo_get_merge_bases_many(struct repository *r,
460460
struct commit *one,
461461
int n,
462462
struct commit **twos)
463463
{
464-
return get_merge_bases_many_0(r, one, n, twos, 1);
464+
struct commit_list *result = NULL;
465+
if (get_merge_bases_many_0(r, one, n, twos, 1, &result) < 0) {
466+
free_commit_list(result);
467+
return NULL;
468+
}
469+
return result;
465470
}
466471

467472
struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
468473
struct commit *one,
469474
int n,
470475
struct commit **twos)
471476
{
472-
return get_merge_bases_many_0(r, one, n, twos, 0);
477+
struct commit_list *result = NULL;
478+
if (get_merge_bases_many_0(r, one, n, twos, 0, &result) < 0) {
479+
free_commit_list(result);
480+
return NULL;
481+
}
482+
return result;
473483
}
474484

475485
struct commit_list *repo_get_merge_bases(struct repository *r,
476486
struct commit *one,
477487
struct commit *two)
478488
{
479-
return get_merge_bases_many_0(r, one, 1, &two, 1);
489+
struct commit_list *result = NULL;
490+
if (get_merge_bases_many_0(r, one, 1, &two, 1, &result) < 0) {
491+
free_commit_list(result);
492+
return NULL;
493+
}
494+
return result;
480495
}
481496

482497
/*

0 commit comments

Comments
 (0)