+static int write_graph_chunk_base_1(struct hashfile *f,
+ struct commit_graph *g)
+{
+ int num = 0;
+
+ if (!g)
+ return 0;
+
+ num = write_graph_chunk_base_1(f, g->base_graph);
+ hashwrite(f, g->oid.hash, the_hash_algo->rawsz);
+ return num + 1;
+}
+
+static int write_graph_chunk_base(struct hashfile *f,
+ struct write_commit_graph_context *ctx)
+{
+ int num = write_graph_chunk_base_1(f, ctx->new_base_graph);
+
+ if (num != ctx->num_commit_graphs_after - 1) {
+ error(_("failed to write correct number of base graph ids"));
+ return -1;
+ }
+
+ return 0;
+}
+
+static void init_commit_graph_chain(struct write_commit_graph_context *ctx)
+{
+ struct commit_graph *g = ctx->r->objects->commit_graph;
+ uint32_t i;
+
+ ctx->new_base_graph = g;
+ ctx->base_graph_name = xstrdup(g->filename);
+ ctx->new_num_commits_in_base = g->num_commits + g->num_commits_in_base;
+
+ ctx->num_commit_graphs_after = ctx->num_commit_graphs_before + 1;
+
+ ALLOC_ARRAY(ctx->commit_graph_filenames_after, ctx->num_commit_graphs_after);
+ ALLOC_ARRAY(ctx->commit_graph_hash_after, ctx->num_commit_graphs_after);
+
+ for (i = 0; i < ctx->num_commit_graphs_before - 1; i++)
+ ctx->commit_graph_filenames_after[i] = xstrdup(ctx->commit_graph_filenames_before[i]);
+
+ if (ctx->num_commit_graphs_before)
+ ctx->commit_graph_filenames_after[ctx->num_commit_graphs_before - 1] =
+ get_split_graph_filename(ctx->obj_dir, oid_to_hex(&g->oid));
+
+ i = ctx->num_commit_graphs_before - 1;
+
+ while (g) {
+ ctx->commit_graph_hash_after[i] = xstrdup(oid_to_hex(&g->oid));
+ i--;
+ g = g->base_graph;
+ }
+}
+