]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/reflog: stop storing per-reflog expiry dates globally
authorPatrick Steinhardt <ps@pks.im>
Tue, 8 Apr 2025 06:22:14 +0000 (08:22 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2025 14:53:26 +0000 (07:53 -0700)
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/reflog.c
reflog.h

index 0910a4e25dcc41a40c8c6997487884f55f1e0ac9..a231cf4b85713ee0a43dda958dfb580f127d4726 100644 (file)
@@ -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;
index a9d464bbf8c4ed383d26d05f6f4d3a103e8555a4..b08780a30a7ccc180bbd8621501599a9312165ba 100644 (file)
--- 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;