MCPcopy Index your code
hub / github.com/git/git / split_graph_merge_strategy

Function split_graph_merge_strategy

commit-graph.c:2280–2368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2278}
2279
2280static void split_graph_merge_strategy(struct write_commit_graph_context *ctx,
2281 struct commit_graph *graph_to_merge)
2282{
2283 struct commit_graph *g;
2284 uint32_t num_commits;
2285 enum commit_graph_split_flags flags = COMMIT_GRAPH_SPLIT_UNSPECIFIED;
2286 uint32_t i;
2287
2288 int max_commits = 0;
2289 int size_mult = 2;
2290
2291 if (ctx->opts) {
2292 max_commits = ctx->opts->max_commits;
2293
2294 if (ctx->opts->size_multiple)
2295 size_mult = ctx->opts->size_multiple;
2296
2297 flags = ctx->opts->split_flags;
2298 }
2299
2300 g = graph_to_merge;
2301 num_commits = ctx->commits.nr;
2302 if (flags == COMMIT_GRAPH_SPLIT_REPLACE)
2303 ctx->num_commit_graphs_after = 1;
2304 else
2305 ctx->num_commit_graphs_after = ctx->num_commit_graphs_before + 1;
2306
2307 if (flags != COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED &&
2308 flags != COMMIT_GRAPH_SPLIT_REPLACE) {
2309 while (g && (g->num_commits <= st_mult(size_mult, num_commits) ||
2310 (max_commits && num_commits > max_commits))) {
2311 if (g->odb_source != ctx->odb_source)
2312 break;
2313
2314 if (unsigned_add_overflows(num_commits, g->num_commits))
2315 die(_("cannot merge graphs with %"PRIuMAX", "
2316 "%"PRIuMAX" commits"),
2317 (uintmax_t)num_commits,
2318 (uintmax_t)g->num_commits);
2319 num_commits += g->num_commits;
2320 g = g->base_graph;
2321
2322 ctx->num_commit_graphs_after--;
2323 }
2324 }
2325
2326 if (flags != COMMIT_GRAPH_SPLIT_REPLACE)
2327 ctx->new_base_graph = g;
2328 else if (ctx->num_commit_graphs_after != 1)
2329 BUG("split_graph_merge_strategy: num_commit_graphs_after "
2330 "should be 1 with --split=replace");
2331
2332 if (ctx->num_commit_graphs_after == 2) {
2333 char *old_graph_name = get_commit_graph_filename(g->odb_source);
2334
2335 if (!strcmp(g->filename, old_graph_name) &&
2336 g->odb_source != ctx->odb_source) {
2337 ctx->num_commit_graphs_after = 1;

Callers 1

write_commit_graphFunction · 0.85

Calls 5

st_multFunction · 0.85
xstrdupFunction · 0.85
oid_to_hexFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected