From 53f9561055e8377a18a2430262857a3650c73dab Mon Sep 17 00:00:00 2001 From: Kristofer Karlsson Date: Mon, 11 May 2026 12:59:11 +0000 Subject: [PATCH] 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 Signed-off-by: Junio C Hamano --- builtin/merge-base.c | 3 ++- commit-reach.c | 23 +++++++++++++++-------- commit-reach.h | 5 +++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/builtin/merge-base.c b/builtin/merge-base.c index c7ee97fa6a..9b50b4660e 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -14,7 +14,8 @@ static int show_merge_base(struct commit **rev, size_t rev_nr, int show_all) struct commit_list *result = NULL, *r; if (repo_get_merge_bases_many_dirty(the_repository, rev[0], - rev_nr - 1, rev + 1, &result) < 0) { + rev_nr - 1, rev + 1, + 0, &result) < 0) { commit_list_free(result); return -1; } diff --git a/commit-reach.c b/commit-reach.c index d3a9b3ed6f..766ba1156a 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -54,7 +54,7 @@ static int paint_down_to_common(struct repository *r, struct commit *one, int n, struct commit **twos, timestamp_t min_generation, - int ignore_missing_commits, + enum merge_base_flags mb_flags, struct commit_list **result) { struct prio_queue queue = { compare_commits_by_gen_then_commit_date }; @@ -118,7 +118,7 @@ static int paint_down_to_common(struct repository *r, * corrupt commits would already have been * dispatched with a `die()`. */ - if (ignore_missing_commits) + if (mb_flags & MERGE_BASE_IGNORE_MISSING_COMMITS) return 0; return error(_("could not parse commit %s"), oid_to_hex(&p->object.oid)); @@ -136,6 +136,7 @@ static int paint_down_to_common(struct repository *r, static int merge_bases_many(struct repository *r, struct commit *one, int n, struct commit **twos, + enum merge_base_flags mb_flags, struct commit_list **result) { struct commit_list *list = NULL, **tail = result; @@ -165,7 +166,7 @@ static int merge_bases_many(struct repository *r, oid_to_hex(&twos[i]->object.oid)); } - if (paint_down_to_common(r, one, n, twos, 0, 0, &list)) { + if (paint_down_to_common(r, one, n, twos, 0, mb_flags, &list)) { commit_list_free(list); return -1; } @@ -425,6 +426,7 @@ static int get_merge_bases_many_0(struct repository *r, size_t n, struct commit **twos, int cleanup, + enum merge_base_flags mb_flags, struct commit_list **result) { struct commit_list *list, **tail = result; @@ -432,7 +434,7 @@ static int get_merge_bases_many_0(struct repository *r, size_t cnt, i; int ret; - if (merge_bases_many(r, one, n, twos, result) < 0) + if (merge_bases_many(r, one, n, twos, mb_flags, result) < 0) return -1; for (i = 0; i < n; i++) { if (one == twos[i]) @@ -475,16 +477,17 @@ int repo_get_merge_bases_many(struct repository *r, struct commit **twos, struct commit_list **result) { - return get_merge_bases_many_0(r, one, n, twos, 1, result); + return get_merge_bases_many_0(r, one, n, twos, 1, 0, result); } int repo_get_merge_bases_many_dirty(struct repository *r, struct commit *one, size_t n, struct commit **twos, + enum merge_base_flags mb_flags, struct commit_list **result) { - return get_merge_bases_many_0(r, one, n, twos, 0, result); + return get_merge_bases_many_0(r, one, n, twos, 0, mb_flags, result); } int repo_get_merge_bases(struct repository *r, @@ -492,7 +495,7 @@ int repo_get_merge_bases(struct repository *r, struct commit *two, struct commit_list **result) { - return get_merge_bases_many_0(r, one, 1, &two, 1, result); + return get_merge_bases_many_0(r, one, 1, &two, 1, 0, result); } /* @@ -537,6 +540,10 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit, struct commit_list *bases = NULL; int ret = 0, i; timestamp_t generation, max_generation = GENERATION_NUMBER_ZERO; + enum merge_base_flags mb_flags = 0; + + if (ignore_missing_commits) + mb_flags |= MERGE_BASE_IGNORE_MISSING_COMMITS; if (repo_parse_commit(r, commit)) return ignore_missing_commits ? 0 : -1; @@ -555,7 +562,7 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit, if (paint_down_to_common(r, commit, nr_reference, reference, - generation, ignore_missing_commits, &bases)) + generation, mb_flags, &bases)) ret = -1; else if (commit->object.flags & PARENT2) ret = 1; diff --git a/commit-reach.h b/commit-reach.h index 6012402dfc..a3f2cd80eb 100644 --- a/commit-reach.h +++ b/commit-reach.h @@ -17,10 +17,15 @@ int repo_get_merge_bases_many(struct repository *r, struct commit *one, size_t n, struct commit **twos, struct commit_list **result); +enum merge_base_flags { + MERGE_BASE_IGNORE_MISSING_COMMITS = (1 << 0), +}; + /* To be used only when object flags after this call no longer matter */ int repo_get_merge_bases_many_dirty(struct repository *r, struct commit *one, size_t n, struct commit **twos, + enum merge_base_flags mb_flags, struct commit_list **result); int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result); -- 2.52.0