aboutsummaryrefslogtreecommitdiffstats
path: root/commit-graph.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-09-04 14:49:59 +0200
committerJunio C Hamano <gitster@pobox.com>2025-09-04 16:16:22 -0700
commit62490b6d85882e6a0ba434ab436640e31352ffee (patch)
treeed22365fe26780ff6be33710c2c55851a24edbc1 /commit-graph.c
parentcommit-graph: return commit graph from `repo_find_commit_pos_in_graph()` (diff)
downloadgit-62490b6d85882e6a0ba434ab436640e31352ffee.tar.gz
git-62490b6d85882e6a0ba434ab436640e31352ffee.zip
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>
Diffstat (limited to 'commit-graph.c')
-rw-r--r--commit-graph.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/commit-graph.c b/commit-graph.c
index 16dfe58229..0e25b14076 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -2226,7 +2226,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
return 0;
}
-static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
+static void split_graph_merge_strategy(struct write_commit_graph_context *ctx,
+ struct commit_graph *graph_to_merge)
{
struct commit_graph *g;
uint32_t num_commits;
@@ -2245,7 +2246,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
flags = ctx->opts->split_flags;
}
- g = ctx->r->objects->commit_graph;
+ g = graph_to_merge;
num_commits = ctx->commits.nr;
if (flags == COMMIT_GRAPH_SPLIT_REPLACE)
ctx->num_commit_graphs_after = 1;
@@ -2297,7 +2298,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
ctx->commit_graph_filenames_after[i] = xstrdup(ctx->commit_graph_filenames_before[i]);
i = ctx->num_commit_graphs_before - 1;
- g = ctx->r->objects->commit_graph;
+ g = graph_to_merge;
while (g) {
if (i < ctx->num_commit_graphs_after)
@@ -2395,9 +2396,9 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
stop_progress(&ctx->progress);
}
-static void merge_commit_graphs(struct write_commit_graph_context *ctx)
+static void merge_commit_graphs(struct write_commit_graph_context *ctx,
+ struct commit_graph *g)
{
- struct commit_graph *g = ctx->r->objects->commit_graph;
uint32_t current_graph_number = ctx->num_commit_graphs_before;
while (g && current_graph_number >= ctx->num_commit_graphs_after) {
@@ -2632,12 +2633,13 @@ int write_commit_graph(struct odb_source *source,
goto cleanup;
if (ctx.split) {
- split_graph_merge_strategy(&ctx);
+ split_graph_merge_strategy(&ctx, g);
if (!replace)
- merge_commit_graphs(&ctx);
- } else
+ merge_commit_graphs(&ctx, g);
+ } else {
ctx.num_commit_graphs_after = 1;
+ }
ctx.trust_generation_numbers = validate_mixed_generation_chain(g);