Skip to content

Commit 32c55c0

Browse files
committed
commit-graph: fix buggy --expire-time option
The commit-graph builtin has an --expire-time option that takes a datetime using OPT_EXPIRY_DATE(). However, the implementation inside expire_commit_graphs() was treating a non-zero value as a number of seconds to subtract from "now". Update t5323-split-commit-graph.sh to demonstrate the correct value of the --expire-time option by actually creating a crud .graph file with mtime earlier than the expire time. Instead of using a super- early time (1980) we need to use a recent time or else the old logic actually passes by accident. This test will start passing again on the old logic in 40 years or so. I noticed this when inspecting some Scalar repos that had an excess number of commit-graph files. In Scalar, we were using this second interpretation by using "--expire-time=3600" to mean "delete graphs older than one hour ago" to avoid deleting a commit-graph that a foreground process may be trying to load. Also I noticed that the help text was copied from the --max-commits option. Fix that help text. Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
1 parent 274b9cc commit 32c55c0

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

builtin/commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static int graph_write(int argc, const char **argv)
140140
OPT_INTEGER(0, "size-multiple", &split_opts.size_multiple,
141141
N_("maximum ratio between two levels of a split commit-graph")),
142142
OPT_EXPIRY_DATE(0, "expire-time", &split_opts.expire_time,
143-
N_("maximum number of commits in a non-base split commit-graph")),
143+
N_("do not expire files newer than a number of seconds before now")),
144144
OPT_END(),
145145
};
146146

commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
17071707
timestamp_t expire_time = time(NULL);
17081708

17091709
if (ctx->split_opts && ctx->split_opts->expire_time)
1710-
expire_time -= ctx->split_opts->expire_time;
1710+
expire_time = ctx->split_opts->expire_time;
17111711
if (!ctx->split) {
17121712
char *chain_file_name = get_chain_filename(ctx->odb);
17131713
unlink(chain_file_name);

t/t5324-split-commit-graph.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,10 @@ test_expect_success 'test merge stragety constants' '
210210
git config core.commitGraph true &&
211211
test_line_count = 2 $graphdir/commit-graph-chain &&
212212
test_commit 15 &&
213-
git commit-graph write --reachable --split --size-multiple=10 --expire-time=1980-01-01 &&
213+
touch -m -t 201801010000.00 $graphdir/extra.graph &&
214+
git commit-graph write --reachable --split --size-multiple=10 --expire-time=2019-01-01 &&
214215
test_line_count = 1 $graphdir/commit-graph-chain &&
216+
test_path_is_missing $graphdir/extra.graph &&
215217
ls $graphdir/graph-*.graph >graph-files &&
216218
test_line_count = 3 graph-files
217219
) &&

0 commit comments

Comments
 (0)