]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-graph: fix buggy --expire-time option
authorDerrick Stolee <dstolee@microsoft.com>
Wed, 1 Apr 2020 21:00:44 +0000 (21:00 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Apr 2020 21:36:26 +0000 (14:36 -0700)
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 use an explicit, and recent, time. Using
test-tool chmtime to create two files on either end of an exact
second, we create a test that catches this failure no matter the
current time. Using a fixed date is more portable than trying to
format a relative date string into the --expiry-date input.

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit-graph.c
commit-graph.c
t/t5324-split-commit-graph.sh

index 38027b83d9d8329a1dc2e47b236a985e4ce71060..7339f87c2dff5359217040b932e31b01f04987b9 100644 (file)
@@ -175,7 +175,7 @@ static int graph_write(int argc, const char **argv)
                OPT_INTEGER(0, "size-multiple", &split_opts.size_multiple,
                        N_("maximum ratio between two levels of a split commit-graph")),
                OPT_EXPIRY_DATE(0, "expire-time", &split_opts.expire_time,
-                       N_("maximum number of commits in a non-base split commit-graph")),
+                       N_("only expire files older than a given date-time")),
                OPT_END(),
        };
 
index c91e6f0fb821582706b3c9ee232da1335ea7427d..4df4326b50d342ff7406c5dacbe44df144a324e7 100644 (file)
@@ -1694,7 +1694,7 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
        timestamp_t expire_time = time(NULL);
 
        if (ctx->split_opts && ctx->split_opts->expire_time)
-               expire_time -= ctx->split_opts->expire_time;
+               expire_time = ctx->split_opts->expire_time;
        if (!ctx->split) {
                char *chain_file_name = get_chain_filename(ctx->obj_dir);
                unlink(chain_file_name);
index 03f45a1ed9023c2b3371bdac70f7abadd14b4202..8e9cb23e2a117a089a03c51912ec830dd9d07bf2 100755 (executable)
@@ -202,8 +202,14 @@ test_expect_success 'test merge stragety constants' '
                git config core.commitGraph true &&
                test_line_count = 2 $graphdir/commit-graph-chain &&
                test_commit 15 &&
-               git commit-graph write --reachable --split --size-multiple=10 --expire-time=1980-01-01 &&
+               touch $graphdir/to-delete.graph $graphdir/to-keep.graph &&
+               test-tool chmtime =1546362000 $graphdir/to-delete.graph &&
+               test-tool chmtime =1546362001 $graphdir/to-keep.graph &&
+               git commit-graph write --reachable --split --size-multiple=10 \
+                       --expire-time="2019-01-01 12:00 -05:00" &&
                test_line_count = 1 $graphdir/commit-graph-chain &&
+               test_path_is_missing $graphdir/to-delete.graph &&
+               test_path_is_file $graphdir/to-keep.graph &&
                ls $graphdir/graph-*.graph >graph-files &&
                test_line_count = 3 graph-files
        ) &&