Skip to content

Commit ba41112

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3da4b60 commit ba41112

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

commit-graph.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,12 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
16871687

16881688
if (ctx->split_opts && ctx->split_opts->expire_time)
16891689
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+
}
16901696

16911697
strbuf_addstr(&path, ctx->obj_dir);
16921698
strbuf_addstr(&path, "/info/commit-graphs");
@@ -1841,10 +1847,10 @@ int write_commit_graph(const char *obj_dir,
18411847

18421848
res = write_commit_graph_file(ctx);
18431849

1844-
if (ctx->split) {
1850+
if (ctx->split)
18451851
mark_commit_graphs(ctx);
1846-
expire_commit_graphs(ctx);
1847-
}
1852+
1853+
expire_commit_graphs(ctx);
18481854

18491855
cleanup:
18501856
free(ctx->graph_name);

t/t5324-split-commit-graph.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ test_expect_success 'test merge stragety constants' '
216216
)
217217
'
218218

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+
219231
corrupt_file() {
220232
file=$1
221233
pos=$2

0 commit comments

Comments
 (0)