commit-graph: clean up chains after flattened write

If we write a commit-graph file without the split option, then we write to $OBJDIR/info/commit-graph and start to ignore the chains in $OBJDIR/info/commit-graphs/. Unlink the commit-graph-chain file and expire the graph-{hash}.graph files in $OBJDIR/info/commit-graphs/ during every write. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jun 18, 2019 at 11:14 UTC ba41112a6331e8b454cac6cfd3ee67ae93957a2c
2 files changed +21 -3
commit-graph.c
+9 -3
@@ -1687,6 +1687,12 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
1687
1688 if (ctx->split_opts && ctx->split_opts->expire_time)
1689 expire_time -= ctx->split_opts->expire_time;
1690 + if (!ctx->split) {
1691 + char *chain_file_name = get_chain_filename(ctx->obj_dir);
1692 + unlink(chain_file_name);
1693 + free(chain_file_name);
1694 + ctx->num_commit_graphs_after = 0;
1695 + }
1696
1697 strbuf_addstr(&path, ctx->obj_dir);
1698 strbuf_addstr(&path, "/info/commit-graphs");
@@ -1841,10 +1847,10 @@ int write_commit_graph(const char *obj_dir,
1847
1848 res = write_commit_graph_file(ctx);
1849
1844 - if (ctx->split) {
1850 + if (ctx->split)
1851 mark_commit_graphs(ctx);
1846 - expire_commit_graphs(ctx);
1847 - }
1852 +
1853 + expire_commit_graphs(ctx);
1854
1855 cleanup:
1856 free(ctx->graph_name);
t/t5324-split-commit-graph.sh
+12
@@ -216,6 +216,18 @@ test_expect_success 'test merge stragety constants' '
216 )
217 '
218
219 +test_expect_success 'remove commit-graph-chain file after flattening' '
220 + git clone . flatten &&
221 + (
222 + cd flatten &&
223 + test_line_count = 2 $graphdir/commit-graph-chain &&
224 + git commit-graph write --reachable &&
225 + test_path_is_missing $graphdir/commit-graph-chain &&
226 + ls $graphdir >graph-files &&
227 + test_line_count = 0 graph-files
228 + )
229 +'
230 +
231 corrupt_file() {
232 file=$1
233 pos=$2