From: Patrick Steinhardt Date: Tue, 8 Apr 2025 06:22:13 +0000 (+0200) Subject: builtin/reflog: stop storing default reflog expiry dates globally X-Git-Tag: v2.50.0-rc0~106^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=85658275702bad04c916e2709fe33d2efc6de5e4;p=thirdparty%2Fgit.git builtin/reflog: stop storing default reflog expiry dates globally When expiring reflog entries, it is possible to configure expiry dates that depend on the name of the reflog. This requires us to store a couple of different expiry dates: - The default expiry date for reflog entries that aren't otherwise specified. - The per-reflog expiry date. - The currently active set of expiry dates for a given reference. While the last item is stored in `struct reflog_expire_options`, the other items aren't, which makes it hard to reuse the structure in other places. Refactor the code so that the default expiry date is stored as part of the structure. The per-reflog expiry dates will be adapted accordingly in the subsequent commit. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- diff --git a/builtin/reflog.c b/builtin/reflog.c index dee49881d3..0910a4e25d 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -63,9 +63,6 @@ static const char *const reflog_usage[] = { NULL }; -static timestamp_t default_reflog_expire; -static timestamp_t default_reflog_expire_unreachable; - struct worktree_reflogs { struct worktree *worktree; struct string_list reflogs; @@ -122,6 +119,7 @@ static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len) static int reflog_expire_config(const char *var, const char *value, const struct config_context *ctx, void *cb) { + struct reflog_expire_options *opts = cb; const char *pattern, *key; size_t pattern_len; timestamp_t expire; @@ -145,10 +143,10 @@ static int reflog_expire_config(const char *var, const char *value, if (!pattern) { switch (slot) { case EXPIRE_TOTAL: - default_reflog_expire = expire; + opts->default_expire_total = expire; break; case EXPIRE_UNREACH: - default_reflog_expire_unreachable = expire; + opts->default_expire_unreachable = expire; break; } return 0; @@ -198,9 +196,9 @@ static void set_reflog_expiry_param(struct reflog_expire_options *cb, const char /* Nothing matched -- use the default value */ if (!(cb->explicit_expiry & EXPIRE_TOTAL)) - cb->expire_total = default_reflog_expire; + cb->expire_total = cb->default_expire_total; if (!(cb->explicit_expiry & EXPIRE_UNREACH)) - cb->expire_unreachable = default_reflog_expire_unreachable; + cb->expire_unreachable = cb->default_expire_unreachable; } static int expire_unreachable_callback(const struct option *opt, @@ -276,8 +274,8 @@ static int cmd_reflog_list(int argc, const char **argv, const char *prefix, static int cmd_reflog_expire(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) { - struct reflog_expire_options opts = { 0 }; timestamp_t now = time(NULL); + struct reflog_expire_options opts = REFLOG_EXPIRE_OPTIONS_INIT(now); int i, status, do_all, single_worktree = 0; unsigned int flags = 0; int verbose = 0; @@ -308,17 +306,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix, OPT_END() }; - default_reflog_expire_unreachable = now - 30 * 24 * 3600; - default_reflog_expire = now - 90 * 24 * 3600; - git_config(reflog_expire_config, NULL); + git_config(reflog_expire_config, &opts); save_commit_buffer = 0; do_all = status = 0; - opts.explicit_expiry = 0; - opts.expire_total = default_reflog_expire; - opts.expire_unreachable = default_reflog_expire_unreachable; - argc = parse_options(argc, argv, prefix, options, reflog_expire_usage, 0); if (verbose) diff --git a/reflog.h b/reflog.h index eb948119e5..a9d464bbf8 100644 --- a/reflog.h +++ b/reflog.h @@ -5,10 +5,16 @@ struct reflog_expire_options { int stalefix; int explicit_expiry; + timestamp_t default_expire_total; timestamp_t expire_total; + timestamp_t default_expire_unreachable; timestamp_t expire_unreachable; int recno; }; +#define REFLOG_EXPIRE_OPTIONS_INIT(now) { \ + .default_expire_total = now - 30 * 24 * 3600, \ + .default_expire_unreachable = now - 90 * 24 * 3600, \ +} struct expire_reflog_policy_cb { enum {