866
867
if (edge_value >= 0)
868
edge_value += ctx->new_num_commits_in_base;
869
- else {
869
+ else if (ctx->new_base_graph) {
870
uint32_t pos;
871
if (find_commit_in_graph(parent->item,
872
ctx->new_base_graph,
897
898
if (edge_value >= 0)
899
edge_value += ctx->new_num_commits_in_base;
900
- else {
900
+ else if (ctx->new_base_graph) {
901
uint32_t pos;
902
if (find_commit_in_graph(parent->item,
903
ctx->new_base_graph,
964
965
if (edge_value >= 0)
966
edge_value += ctx->new_num_commits_in_base;
967
- else {
967
+ else if (ctx->new_base_graph) {
968
uint32_t pos;
969
if (find_commit_in_graph(parent->item,
970
ctx->new_base_graph,
1037
{
1038
int i;
1039
struct commit *commit;
1040
+ enum commit_graph_split_flags flags = ctx->split_opts ?
1041
+ ctx->split_opts->flags : COMMIT_GRAPH_SPLIT_UNSPECIFIED;
1042
1043
if (ctx->report_progress)
1044
ctx->progress = start_delayed_progress(
1068
if (!commit)
1069
continue;
1070
if (ctx->split) {
1069
- if (!parse_commit(commit) &&
1070
- commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
1071
+ if ((!parse_commit(commit) &&
1072
+ commit->graph_pos == COMMIT_NOT_FROM_GRAPH) ||
1073
+ flags == COMMIT_GRAPH_SPLIT_REPLACE)
1074
add_missing_parents(ctx, commit);
1075
} else if (!parse_commit_no_graph(commit))
1076
add_missing_parents(ctx, commit);
1290
static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
1291
{
1292
uint32_t i;
1293
+ enum commit_graph_split_flags flags = ctx->split_opts ?
1294
+ ctx->split_opts->flags : COMMIT_GRAPH_SPLIT_UNSPECIFIED;
1295
1296
ctx->num_extra_edges = 0;
1297
if (ctx->report_progress)
1308
ALLOC_GROW(ctx->commits.list, ctx->commits.nr + 1, ctx->commits.alloc);
1309
ctx->commits.list[ctx->commits.nr] = lookup_commit(ctx->r, &ctx->oids.list[i]);
1310
1306
- if (ctx->split &&
1311
+ if (ctx->split && flags != COMMIT_GRAPH_SPLIT_REPLACE &&
1312
ctx->commits.list[ctx->commits.nr]->graph_pos != COMMIT_NOT_FROM_GRAPH)
1313
continue;
1314
1310
- parse_commit_no_graph(ctx->commits.list[ctx->commits.nr]);
1315
+ if (ctx->split && flags == COMMIT_GRAPH_SPLIT_REPLACE)
1316
+ parse_commit(ctx->commits.list[ctx->commits.nr]);
1317
+ else
1318
+ parse_commit_no_graph(ctx->commits.list[ctx->commits.nr]);
1319
1320
num_parents = commit_list_count(ctx->commits.list[ctx->commits.nr]->parents);
1321
if (num_parents > 2)
1496
}
1497
1498
if (ctx->base_graph_name) {
1491
- const char *dest = ctx->commit_graph_filenames_after[
1492
- ctx->num_commit_graphs_after - 2];
1499
+ const char *dest;
1500
+ int idx = ctx->num_commit_graphs_after - 1;
1501
+ if (ctx->num_commit_graphs_after > 1)
1502
+ idx--;
1503
+
1504
+ dest = ctx->commit_graph_filenames_after[idx];
1505
1506
if (strcmp(ctx->base_graph_name, dest)) {
1507
result = rename(ctx->base_graph_name, dest);
1558
1559
g = ctx->r->objects->commit_graph;
1560
num_commits = ctx->commits.nr;
1549
- ctx->num_commit_graphs_after = ctx->num_commit_graphs_before + 1;
1561
+ if (flags == COMMIT_GRAPH_SPLIT_REPLACE)
1562
+ ctx->num_commit_graphs_after = 1;
1563
+ else
1564
+ ctx->num_commit_graphs_after = ctx->num_commit_graphs_before + 1;
1565
1551
- if (flags != COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED) {
1566
+ if (flags != COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED &&
1567
+ flags != COMMIT_GRAPH_SPLIT_REPLACE) {
1568
while (g && (g->num_commits <= size_mult * num_commits ||
1569
(max_commits && num_commits > max_commits))) {
1570
if (g->odb != ctx->odb)
1577
}
1578
}
1579
1564
- ctx->new_base_graph = g;
1580
+ if (flags != COMMIT_GRAPH_SPLIT_REPLACE)
1581
+ ctx->new_base_graph = g;
1582
+ else if (ctx->num_commit_graphs_after != 1)
1583
+ BUG("split_graph_merge_strategy: num_commit_graphs_after "
1584
+ "should be 1 with --split=replace");
1585
1586
if (ctx->num_commit_graphs_after == 2) {
1587
char *old_graph_name = get_commit_graph_filename(g->odb);
1792
struct write_commit_graph_context *ctx;
1793
uint32_t i, count_distinct = 0;
1794
int res = 0;
1795
+ int replace = 0;
1796
1797
if (!commit_graph_compatible(the_repository))
1798
return 0;
1827
g = g->base_graph;
1828
}
1829
}
1830
+
1831
+ if (ctx->split_opts)
1832
+ replace = ctx->split_opts->flags & COMMIT_GRAPH_SPLIT_REPLACE;
1833
}
1834
1835
ctx->approx_nr_objects = approximate_object_count();
1890
goto cleanup;
1891
}
1892
1869
- if (!ctx->commits.nr)
1893
+ if (!ctx->commits.nr && !replace)
1894
goto cleanup;
1895
1896
if (ctx->split) {
1897
split_graph_merge_strategy(ctx);
1898
1875
- merge_commit_graphs(ctx);
1899
+ if (!replace)
1900
+ merge_commit_graphs(ctx);
1901
} else
1902
ctx->num_commit_graphs_after = 1;
1903