From: Patrick Steinhardt Date: Tue, 8 Apr 2025 06:22:14 +0000 (+0200) Subject: builtin/reflog: stop storing per-reflog expiry dates globally X-Git-Tag: v2.50.0-rc0~106^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=964f364de9935592ff187cdf26b87a75e762c26c;p=thirdparty%2Fgit.git builtin/reflog: stop storing per-reflog expiry dates globally As described in the preceding commit, the per-reflog expiry dates are stored in a global pair of variables. Refactor the code so that they are contained in `struct reflog_expire_options` to make the structure useful in other contexts. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- diff --git a/builtin/reflog.c b/builtin/reflog.c index 0910a4e25d..a231cf4b85 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -88,27 +88,21 @@ static int collect_reflog(const char *ref, void *cb_data) return 0; } -static struct reflog_expire_cfg { - struct reflog_expire_cfg *next; - timestamp_t expire_total; - timestamp_t expire_unreachable; - char pattern[FLEX_ARRAY]; -} *reflog_expire_cfg, **reflog_expire_cfg_tail; - -static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len) +static struct reflog_expire_entry_option *find_cfg_ent(struct reflog_expire_options *opts, + const char *pattern, size_t len) { - struct reflog_expire_cfg *ent; + struct reflog_expire_entry_option *ent; - if (!reflog_expire_cfg_tail) - reflog_expire_cfg_tail = &reflog_expire_cfg; + if (!opts->entries_tail) + opts->entries_tail = &opts->entries; - for (ent = reflog_expire_cfg; ent; ent = ent->next) + for (ent = opts->entries; ent; ent = ent->next) if (!xstrncmpz(ent->pattern, pattern, len)) return ent; FLEX_ALLOC_MEM(ent, pattern, pattern, len); - *reflog_expire_cfg_tail = ent; - reflog_expire_cfg_tail = &(ent->next); + *opts->entries_tail = ent; + opts->entries_tail = &(ent->next); return ent; } @@ -124,7 +118,7 @@ static int reflog_expire_config(const char *var, const char *value, size_t pattern_len; timestamp_t expire; int slot; - struct reflog_expire_cfg *ent; + struct reflog_expire_entry_option *ent; if (parse_config_key(var, "gc", &pattern, &pattern_len, &key) < 0) return git_default_config(var, value, ctx, cb); @@ -152,7 +146,7 @@ static int reflog_expire_config(const char *var, const char *value, return 0; } - ent = find_cfg_ent(pattern, pattern_len); + ent = find_cfg_ent(opts, pattern, pattern_len); if (!ent) return -1; switch (slot) { @@ -168,12 +162,12 @@ static int reflog_expire_config(const char *var, const char *value, static void set_reflog_expiry_param(struct reflog_expire_options *cb, const char *ref) { - struct reflog_expire_cfg *ent; + struct reflog_expire_entry_option *ent; if (cb->explicit_expiry == (EXPIRE_TOTAL|EXPIRE_UNREACH)) return; /* both given explicitly -- nothing to tweak */ - for (ent = reflog_expire_cfg; ent; ent = ent->next) { + for (ent = cb->entries; ent; ent = ent->next) { if (!wildmatch(ent->pattern, ref, 0)) { if (!(cb->explicit_expiry & EXPIRE_TOTAL)) cb->expire_total = ent->expire_total; diff --git a/reflog.h b/reflog.h index a9d464bbf8..b08780a30a 100644 --- a/reflog.h +++ b/reflog.h @@ -2,7 +2,15 @@ #define REFLOG_H #include "refs.h" +struct reflog_expire_entry_option { + struct reflog_expire_entry_option *next; + timestamp_t expire_total; + timestamp_t expire_unreachable; + char pattern[FLEX_ARRAY]; +}; + struct reflog_expire_options { + struct reflog_expire_entry_option *entries, **entries_tail; int stalefix; int explicit_expiry; timestamp_t default_expire_total;