commit-graph: pass graphs that are to be merged as parameter

When determining whether or not we want to merge a commit graph chain we retrieve the graph that is to be merged via the context's repository. With an upcoming change though it will become a bit more complex to figure out the commit graph, which would lead to code duplication. Prepare for this change by passing the graph that is to be merged as a parameter. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Sep 4, 2025 at 14:49 UTC 62490b6d85882e6a0ba434ab436640e31352ffee
1 file changed +10 -8
commit-graph.c
+10 -8
@@ -2226,7 +2226,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2226 return 0;
2227 }
2228
2229 -static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
2229 +static void split_graph_merge_strategy(struct write_commit_graph_context *ctx,
2230 + struct commit_graph *graph_to_merge)
2231 {
2232 struct commit_graph *g;
2233 uint32_t num_commits;
@@ -2245,7 +2246,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
2246 flags = ctx->opts->split_flags;
2247 }
2248
2248 - g = ctx->r->objects->commit_graph;
2249 + g = graph_to_merge;
2250 num_commits = ctx->commits.nr;
2251 if (flags == COMMIT_GRAPH_SPLIT_REPLACE)
2252 ctx->num_commit_graphs_after = 1;
@@ -2297,7 +2298,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
2298 ctx->commit_graph_filenames_after[i] = xstrdup(ctx->commit_graph_filenames_before[i]);
2299
2300 i = ctx->num_commit_graphs_before - 1;
2300 - g = ctx->r->objects->commit_graph;
2301 + g = graph_to_merge;
2302
2303 while (g) {
2304 if (i < ctx->num_commit_graphs_after)
@@ -2395,9 +2396,9 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
2396 stop_progress(&ctx->progress);
2397 }
2398
2398 -static void merge_commit_graphs(struct write_commit_graph_context *ctx)
2399 +static void merge_commit_graphs(struct write_commit_graph_context *ctx,
2400 + struct commit_graph *g)
2401 {
2400 - struct commit_graph *g = ctx->r->objects->commit_graph;
2402 uint32_t current_graph_number = ctx->num_commit_graphs_before;
2403
2404 while (g && current_graph_number >= ctx->num_commit_graphs_after) {
@@ -2632,12 +2633,13 @@ int write_commit_graph(struct odb_source *source,
2633 goto cleanup;
2634
2635 if (ctx.split) {
2635 - split_graph_merge_strategy(&ctx);
2636 + split_graph_merge_strategy(&ctx, g);
2637
2638 if (!replace)
2638 - merge_commit_graphs(&ctx);
2639 - } else
2639 + merge_commit_graphs(&ctx, g);
2640 + } else {
2641 ctx.num_commit_graphs_after = 1;
2642 + }
2643
2644 ctx.trust_generation_numbers = validate_mixed_generation_chain(g);
2645