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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Feb 28, 2024 at 09:44 UTC
8226e157a92066855811188f7ca3fd4bff5f083d
1 file changed
+36
-21
commit-reach.c
+36
-21
@@ -409,37 +409,38 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
409
return remove_redundant_no_gen(r, array, cnt);
410
}
411
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)
418
{
419
struct commit_list *list;
420
struct commit **rslt;
420
- struct commit_list *result = NULL;
421
int cnt, i;
422
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;
425
for (i = 0; i < n; i++) {
426
if (one == twos[i])
427
- return result;
427
+ return 0;
428
}
429
- if (!result || !result->next) {
429
+ if (!*result || !(*result)->next) {
430
if (cleanup) {
431
clear_commit_marks(one, all_flags);
432
clear_commit_marks_many(n, twos, all_flags);
433
}
434
- return result;
434
+ return 0;
435
}
436
437
/* There are more than one */
438
- cnt = commit_list_count(result);
438
+ cnt = commit_list_count(*result);
439
CALLOC_ARRAY(rslt, cnt);
440
- for (list = result, i = 0; list; list = list->next)
440
+ for (list = *result, i = 0; list; list = list->next)
441
rslt[i++] = list->item;
442
- free_commit_list(result);
442
+ free_commit_list(*result);
443
+ *result = NULL;
444
445
clear_commit_marks(one, all_flags);
446
clear_commit_marks_many(n, twos, all_flags);
@@ -447,13 +448,12 @@ static struct commit_list *get_merge_bases_many_0(struct repository *r,
448
cnt = remove_redundant(r, rslt, cnt);
449
if (cnt < 0) {
450
free(rslt);
450
- return NULL;
451
+ return -1;
452
}
452
- result = NULL;
453
for (i = 0; i < cnt; i++)
454
- commit_list_insert_by_date(rslt[i], &result);
454
+ commit_list_insert_by_date(rslt[i], result);
455
free(rslt);
456
- return result;
456
+ return 0;
457
}
458
459
struct commit_list *repo_get_merge_bases_many(struct repository *r,
@@ -461,7 +461,12 @@ struct commit_list *repo_get_merge_bases_many(struct repository *r,
461
int n,
462
struct commit **twos)
463
{
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;
470
}
471
472
struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
@@ -469,14 +474,24 @@ struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
474
int n,
475
struct commit **twos)
476
{
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;
483
}
484
485
struct commit_list *repo_get_merge_bases(struct repository *r,
486
struct commit *one,
487
struct commit *two)
488
{
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;
495
}
496
497
/*