]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-reach: introduce merge_base_flags enum
authorKristofer Karlsson <krka@spotify.com>
Mon, 11 May 2026 12:59:11 +0000 (12:59 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 12 May 2026 00:33:43 +0000 (09:33 +0900)
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>
builtin/merge-base.c
commit-reach.c
commit-reach.h

index c7ee97fa6ac62aa2c87d9bfac4606629b8c47965..9b50b4660ea64ff8115df95093cd44ae8dc6a723 100644 (file)
@@ -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;
        }
index d3a9b3ed6fe56147a3c33bdba34743cc212abe85..766ba1156af63eb4fec06881278914076a081b6f 100644 (file)
@@ -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;
index 6012402dfcfe453fd710d0b4c9a9e09f8953f63a..a3f2cd80ebf180cb57d7331643dfe61b8fcc33d3 100644 (file)
@@ -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);