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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Apr 8, 2025 at 08:22 UTC
964f364de9935592ff187cdf26b87a75e762c26c
2 files changed
+20
-18
builtin/reflog.c
+12
-18
@@ -88,27 +88,21 @@ static int collect_reflog(const char *ref, void *cb_data)
88
return 0;
89
}
90
91
-static struct reflog_expire_cfg {
92
- struct reflog_expire_cfg *next;
93
- timestamp_t expire_total;
94
- timestamp_t expire_unreachable;
95
- char pattern[FLEX_ARRAY];
96
-} *reflog_expire_cfg, **reflog_expire_cfg_tail;
97
-
98
-static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)
91
+static struct reflog_expire_entry_option *find_cfg_ent(struct reflog_expire_options *opts,
92
+ const char *pattern, size_t len)
93
{
100
- struct reflog_expire_cfg *ent;
94
+ struct reflog_expire_entry_option *ent;
95
102
- if (!reflog_expire_cfg_tail)
103
- reflog_expire_cfg_tail = &reflog_expire_cfg;
96
+ if (!opts->entries_tail)
97
+ opts->entries_tail = &opts->entries;
98
105
- for (ent = reflog_expire_cfg; ent; ent = ent->next)
99
+ for (ent = opts->entries; ent; ent = ent->next)
100
if (!xstrncmpz(ent->pattern, pattern, len))
101
return ent;
102
103
FLEX_ALLOC_MEM(ent, pattern, pattern, len);
110
- *reflog_expire_cfg_tail = ent;
111
- reflog_expire_cfg_tail = &(ent->next);
104
+ *opts->entries_tail = ent;
105
+ opts->entries_tail = &(ent->next);
106
return ent;
107
}
108
@@ -124,7 +118,7 @@ static int reflog_expire_config(const char *var, const char *value,
118
size_t pattern_len;
119
timestamp_t expire;
120
int slot;
127
- struct reflog_expire_cfg *ent;
121
+ struct reflog_expire_entry_option *ent;
122
123
if (parse_config_key(var, "gc", &pattern, &pattern_len, &key) < 0)
124
return git_default_config(var, value, ctx, cb);
@@ -152,7 +146,7 @@ static int reflog_expire_config(const char *var, const char *value,
146
return 0;
147
}
148
155
- ent = find_cfg_ent(pattern, pattern_len);
149
+ ent = find_cfg_ent(opts, pattern, pattern_len);
150
if (!ent)
151
return -1;
152
switch (slot) {
@@ -168,12 +162,12 @@ static int reflog_expire_config(const char *var, const char *value,
162
163
static void set_reflog_expiry_param(struct reflog_expire_options *cb, const char *ref)
164
{
171
- struct reflog_expire_cfg *ent;
165
+ struct reflog_expire_entry_option *ent;
166
167
if (cb->explicit_expiry == (EXPIRE_TOTAL|EXPIRE_UNREACH))
168
return; /* both given explicitly -- nothing to tweak */
169
176
- for (ent = reflog_expire_cfg; ent; ent = ent->next) {
170
+ for (ent = cb->entries; ent; ent = ent->next) {
171
if (!wildmatch(ent->pattern, ref, 0)) {
172
if (!(cb->explicit_expiry & EXPIRE_TOTAL))
173
cb->expire_total = ent->expire_total;
reflog.h
+8
@@ -2,7 +2,15 @@
2
#define REFLOG_H
3
#include "refs.h"
4
5
+struct reflog_expire_entry_option {
6
+ struct reflog_expire_entry_option *next;
7
+ timestamp_t expire_total;
8
+ timestamp_t expire_unreachable;
9
+ char pattern[FLEX_ARRAY];
10
+};
11
+
12
struct reflog_expire_options {
13
+ struct reflog_expire_entry_option *entries, **entries_tail;
14
int stalefix;
15
int explicit_expiry;
16
timestamp_t default_expire_total;