Skip to content

Commit 62490b6

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 88bc350 commit 62490b6

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

commit-graph.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,7 +2226,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
22262226
return 0;
22272227
}
22282228

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)
22302231
{
22312232
struct commit_graph *g;
22322233
uint32_t num_commits;
@@ -2245,7 +2246,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
22452246
flags = ctx->opts->split_flags;
22462247
}
22472248

2248-
g = ctx->r->objects->commit_graph;
2249+
g = graph_to_merge;
22492250
num_commits = ctx->commits.nr;
22502251
if (flags == COMMIT_GRAPH_SPLIT_REPLACE)
22512252
ctx->num_commit_graphs_after = 1;
@@ -2297,7 +2298,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
22972298
ctx->commit_graph_filenames_after[i] = xstrdup(ctx->commit_graph_filenames_before[i]);
22982299

22992300
i = ctx->num_commit_graphs_before - 1;
2300-
g = ctx->r->objects->commit_graph;
2301+
g = graph_to_merge;
23012302

23022303
while (g) {
23032304
if (i < ctx->num_commit_graphs_after)
@@ -2395,9 +2396,9 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
23952396
stop_progress(&ctx->progress);
23962397
}
23972398

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)
23992401
{
2400-
struct commit_graph *g = ctx->r->objects->commit_graph;
24012402
uint32_t current_graph_number = ctx->num_commit_graphs_before;
24022403

24032404
while (g && current_graph_number >= ctx->num_commit_graphs_after) {
@@ -2632,12 +2633,13 @@ int write_commit_graph(struct odb_source *source,
26322633
goto cleanup;
26332634

26342635
if (ctx.split) {
2635-
split_graph_merge_strategy(&ctx);
2636+
split_graph_merge_strategy(&ctx, g);
26362637

26372638
if (!replace)
2638-
merge_commit_graphs(&ctx);
2639-
} else
2639+
merge_commit_graphs(&ctx, g);
2640+
} else {
26402641
ctx.num_commit_graphs_after = 1;
2642+
}
26412643

26422644
ctx.trust_generation_numbers = validate_mixed_generation_chain(g);
26432645

0 commit comments

Comments
 (0)