From: "Kristofer Karlsson via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>,
Kristofer Karlsson <krka@spotify.com>,
Kristofer Karlsson <krka@spotify.com>
Subject: [PATCH v4 1/2] commit-reach: introduce merge_base_flags enum
Date: Mon, 11 May 2026 12:59:11 +0000 [thread overview]
Message-ID: <12d9e1c85f68703d069440c05dcc3eb3592274ed.1778504352.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2109.v4.git.1778504352.gitgitgadget@gmail.com>
From: Kristofer Karlsson <krka@spotify.com>
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>
---
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);
--
gitgitgadget
next prev parent reply other threads:[~2026-05-11 12:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 15:07 [PATCH] commit-reach: early exit paint_down_to_common for single merge-base Kristofer Karlsson via GitGitGadget
2026-05-11 2:08 ` Junio C Hamano
2026-05-11 6:19 ` [PATCH v2] " Kristofer Karlsson via GitGitGadget
2026-05-11 7:22 ` Patrick Steinhardt
2026-05-11 11:22 ` [PATCH v3] " Kristofer Karlsson via GitGitGadget
2026-05-11 12:04 ` Patrick Steinhardt
2026-05-11 12:59 ` [PATCH v4 0/2] [RFC] commit-reach: skip STALE drain when only one merge-base needed Kristofer Karlsson via GitGitGadget
2026-05-11 12:59 ` Kristofer Karlsson via GitGitGadget [this message]
2026-05-11 12:59 ` [PATCH v4 2/2] commit-reach: early exit paint_down_to_common for single merge-base Kristofer Karlsson via GitGitGadget
2026-05-12 0:40 ` Junio C Hamano
2026-05-12 5:16 ` Kristofer Karlsson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=12d9e1c85f68703d069440c05dcc3eb3592274ed.1778504352.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=krka@spotify.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.