Skip to content

Commit ca41bf0

Browse files
committed
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]>
1 parent fe91ff5 commit ca41bf0

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
@@ -1672,6 +1672,12 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
16721672

16731673
if (ctx->split_opts && ctx->split_opts->expire_time)
16741674
expire_time -= ctx->split_opts->expire_time;
1675+
if (!ctx->split) {
1676+
char *chain_file_name = get_chain_filename(ctx->obj_dir);
1677+
unlink(chain_file_name);
1678+
free(chain_file_name);
1679+
ctx->num_commit_graphs_after = 0;
1680+
}
16751681

16761682
strbuf_addstr(&path, ctx->obj_dir);
16771683
strbuf_addstr(&path, "/info/commit-graphs");
@@ -1826,10 +1832,10 @@ int write_commit_graph(const char *obj_dir,
18261832

18271833
res = write_commit_graph_file(ctx);
18281834

1829-
if (ctx->split) {
1835+
if (ctx->split)
18301836
mark_commit_graphs(ctx);
1831-
expire_commit_graphs(ctx);
1832-
}
1837+
1838+
expire_commit_graphs(ctx);
18331839

18341840
cleanup:
18351841
free(ctx->graph_name);

t/t5323-split-commit-graph.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@ test_expect_success 'test merge stragety constants' '
204204
)
205205
'
206206

207+
test_expect_success 'remove commit-graph-chain file after flattening' '
208+
git clone . flatten &&
209+
(
210+
cd flatten &&
211+
test_line_count = 2 $graphdir/commit-graph-chain &&
212+
git commit-graph write --reachable &&
213+
test_path_is_missing $graphdir/commit-graph-chain &&
214+
ls $graphdir >graph-files &&
215+
test_line_count = 0 graph-files
216+
)
217+
'
218+
207219
corrupt_file() {
208220
file=$1
209221
pos=$2

0 commit comments

Comments
 (0)