commit-reach: introduce merge_base_flags enum
Replace the boolean ignore_missing_commits parameter in paint_down_to_common() with an enum merge_base_flags, and thread the flags through merge_bases_many(), get_merge_bases_many_0(), and the public repo_get_merge_bases_many_dirty() API. This makes callsites with boolean parameters easier to read and prepares the function for additional flags in a subsequent commit. No functional change: the single caller that used ignore_missing_commits (repo_in_merge_bases_many) now sets MERGE_BASE_IGNORE_MISSING_COMMITS in the flags word, and all other callers pass 0. Signed-off-by: Kristofer Karlsson <krka@spotify.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kristofer Karlsson committed
May 11, 2026 at 12:59 UTC
53f9561055e8377a18a2430262857a3650c73dab
3 files changed
+22
-9
builtin/merge-base.c
+2
-1
@@ -14,7 +14,8 @@ static int show_merge_base(struct commit **rev, size_t rev_nr, int show_all)
14
struct commit_list *result = NULL, *r;
15
16
if (repo_get_merge_bases_many_dirty(the_repository, rev[0],
17
- rev_nr - 1, rev + 1, &result) < 0) {
17
+ rev_nr - 1, rev + 1,
18
+ 0, &result) < 0) {
19
commit_list_free(result);
20
return -1;
21
}
commit-reach.c
+15
-8
@@ -54,7 +54,7 @@ static int paint_down_to_common(struct repository *r,
54
struct commit *one, int n,
55
struct commit **twos,
56
timestamp_t min_generation,
57
- int ignore_missing_commits,
57
+ enum merge_base_flags mb_flags,
58
struct commit_list **result)
59
{
60
struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
@@ -118,7 +118,7 @@ static int paint_down_to_common(struct repository *r,
118
* corrupt commits would already have been
119
* dispatched with a `die()`.
120
*/
121
- if (ignore_missing_commits)
121
+ if (mb_flags & MERGE_BASE_IGNORE_MISSING_COMMITS)
122
return 0;
123
return error(_("could not parse commit %s"),
124
oid_to_hex(&p->object.oid));
@@ -136,6 +136,7 @@ static int paint_down_to_common(struct repository *r,
136
static int merge_bases_many(struct repository *r,
137
struct commit *one, int n,
138
struct commit **twos,
139
+ enum merge_base_flags mb_flags,
140
struct commit_list **result)
141
{
142
struct commit_list *list = NULL, **tail = result;
@@ -165,7 +166,7 @@ static int merge_bases_many(struct repository *r,
166
oid_to_hex(&twos[i]->object.oid));
167
}
168
168
- if (paint_down_to_common(r, one, n, twos, 0, 0, &list)) {
169
+ if (paint_down_to_common(r, one, n, twos, 0, mb_flags, &list)) {
170
commit_list_free(list);
171
return -1;
172
}
@@ -425,6 +426,7 @@ static int get_merge_bases_many_0(struct repository *r,
426
size_t n,
427
struct commit **twos,
428
int cleanup,
429
+ enum merge_base_flags mb_flags,
430
struct commit_list **result)
431
{
432
struct commit_list *list, **tail = result;
@@ -432,7 +434,7 @@ static int get_merge_bases_many_0(struct repository *r,
434
size_t cnt, i;
435
int ret;
436
435
- if (merge_bases_many(r, one, n, twos, result) < 0)
437
+ if (merge_bases_many(r, one, n, twos, mb_flags, result) < 0)
438
return -1;
439
for (i = 0; i < n; i++) {
440
if (one == twos[i])
@@ -475,16 +477,17 @@ int repo_get_merge_bases_many(struct repository *r,
477
struct commit **twos,
478
struct commit_list **result)
479
{
478
- return get_merge_bases_many_0(r, one, n, twos, 1, result);
480
+ return get_merge_bases_many_0(r, one, n, twos, 1, 0, result);
481
}
482
483
int repo_get_merge_bases_many_dirty(struct repository *r,
484
struct commit *one,
485
size_t n,
486
struct commit **twos,
487
+ enum merge_base_flags mb_flags,
488
struct commit_list **result)
489
{
487
- return get_merge_bases_many_0(r, one, n, twos, 0, result);
490
+ return get_merge_bases_many_0(r, one, n, twos, 0, mb_flags, result);
491
}
492
493
int repo_get_merge_bases(struct repository *r,
@@ -492,7 +495,7 @@ int repo_get_merge_bases(struct repository *r,
495
struct commit *two,
496
struct commit_list **result)
497
{
495
- return get_merge_bases_many_0(r, one, 1, &two, 1, result);
498
+ return get_merge_bases_many_0(r, one, 1, &two, 1, 0, result);
499
}
500
501
/*
@@ -537,6 +540,10 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
540
struct commit_list *bases = NULL;
541
int ret = 0, i;
542
timestamp_t generation, max_generation = GENERATION_NUMBER_ZERO;
543
+ enum merge_base_flags mb_flags = 0;
544
+
545
+ if (ignore_missing_commits)
546
+ mb_flags |= MERGE_BASE_IGNORE_MISSING_COMMITS;
547
548
if (repo_parse_commit(r, commit))
549
return ignore_missing_commits ? 0 : -1;
@@ -555,7 +562,7 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
562
563
if (paint_down_to_common(r, commit,
564
nr_reference, reference,
558
- generation, ignore_missing_commits, &bases))
565
+ generation, mb_flags, &bases))
566
ret = -1;
567
else if (commit->object.flags & PARENT2)
568
ret = 1;
commit-reach.h
+5
@@ -17,10 +17,15 @@ int repo_get_merge_bases_many(struct repository *r,
17
struct commit *one, size_t n,
18
struct commit **twos,
19
struct commit_list **result);
20
+enum merge_base_flags {
21
+ MERGE_BASE_IGNORE_MISSING_COMMITS = (1 << 0),
22
+};
23
+
24
/* To be used only when object flags after this call no longer matter */
25
int repo_get_merge_bases_many_dirty(struct repository *r,
26
struct commit *one, size_t n,
27
struct commit **twos,
28
+ enum merge_base_flags mb_flags,
29
struct commit_list **result);
30
31
int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result);