[PATCH v2] reflog: fix default expiry periods
- From
Pushkar Singh <pushkarkumarsingh1970@gmail.com>
- Date
- Sep 23, 2026, 10:21 UTC
- Message-ID
- <20260923102140.25475-2-pushkarkumarsingh1970@gmail.com>
- In-Reply-To
- <20260922165433.591551-2-pushkarkumarsingh1970@gmail.com>
The default reflog expiry periods were swapped when they were moved to REFLOG_EXPIRE_OPTIONS_INIT() by 85658275702b (builtin/reflog: stop storing default reflog expiry dates globally).
This caused reachable entries to expire after 30 days instead of 90 days, and unreachable entries after 90 days instead of 30 days.
Reported-by: r.norouzi <r.norouzi@proton.me> Signed-off-by: Pushkar Singh <pushkarkumarsingh1970@gmail.com> --- Changes in v2: - Expand the regression test to cover both reachable and unreachable entries before and after their respective expiry periods.
reflog.h | 4 ++-- t/t1410-reflog.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/reflog.h b/reflog.h index b996712c00..3bdd1ca8a5 100644 --- a/reflog.h +++ b/reflog.h @@ -23,8 +23,8 @@ struct reflog_expire_options { int recno; }; #define REFLOG_EXPIRE_OPTIONS_INIT(now) { \ - .default_expire_total = now - 30 * 24 * 3600, \ - .default_expire_unreachable = now - 90 * 24 * 3600, \ + .default_expire_total = now - 90 * 24 * 3600, \ + .default_expire_unreachable = now - 30 * 24 * 3600, \ } /* diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 8f78cf4b01..c494aa5ef0 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -153,6 +153,51 @@ test_expect_success 'reflog expire should not barf on an annotated tag' ' test_grep ! "error: [Oo]bject .* not a commit" err ' +test_expect_success 'reflog expire uses the correct default expiry periods' ' + test_when_finished "rm -rf reachable-keep reachable-expire unreachable" && + git init reachable-keep && + ( + cd reachable-keep && + timestamp=$(test-tool date timestamp "60.days.ago") && + timestamp=${timestamp#* -> } && + test_commit --no-tag --date "$timestamp +0000" old && + git reflog expire --all && + test_stdout_line_count = 1 git reflog refs/heads/main + ) && + git init reachable-expire && + ( + cd reachable-expire && + timestamp=$(test-tool date timestamp "100.days.ago") && + timestamp=${timestamp#* -> } && + test_commit --no-tag --date "$timestamp +0000" old && + git reflog expire --all && + test_stdout_line_count = 0 git reflog refs/heads/main + ) && + git init unreachable && + ( + cd unreachable && + test_commit --no-tag base && + base=$(git rev-parse HEAD) && + timestamp=$(test-tool date timestamp "20.days.ago") && + timestamp=${timestamp#* -> } && + test_commit --no-tag --date "$timestamp +0000" old-20 && + old20=$(git rev-parse HEAD) && + git update-ref refs/heads/main "$base" && + timestamp=$(test-tool date timestamp "40.days.ago") && + timestamp=${timestamp#* -> } && + test_commit --no-tag --date "$timestamp +0000" old-40 && + old40=$(git rev-parse HEAD) && + git update-ref refs/heads/main "$base" && + git rev-list --all --objects >reachable && + test_grep ! "$old20" reachable && + test_grep ! "$old40" reachable && + git reflog expire --all && + git reflog --format='%H' refs/heads/main >actual && + test_grep "$old20" actual && + test_grep ! "$old40" actual + ) +' + test_expect_success 'corrupt and check' ' corrupt $F &&
-- 2.53.0