Skip to content

Commit 964f364

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8565827 commit 964f364

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

builtin/reflog.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,21 @@ static int collect_reflog(const char *ref, void *cb_data)
8888
return 0;
8989
}
9090

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)
9993
{
100-
struct reflog_expire_cfg *ent;
94+
struct reflog_expire_entry_option *ent;
10195

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;
10498

105-
for (ent = reflog_expire_cfg; ent; ent = ent->next)
99+
for (ent = opts->entries; ent; ent = ent->next)
106100
if (!xstrncmpz(ent->pattern, pattern, len))
107101
return ent;
108102

109103
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);
112106
return ent;
113107
}
114108

@@ -124,7 +118,7 @@ static int reflog_expire_config(const char *var, const char *value,
124118
size_t pattern_len;
125119
timestamp_t expire;
126120
int slot;
127-
struct reflog_expire_cfg *ent;
121+
struct reflog_expire_entry_option *ent;
128122

129123
if (parse_config_key(var, "gc", &pattern, &pattern_len, &key) < 0)
130124
return git_default_config(var, value, ctx, cb);
@@ -152,7 +146,7 @@ static int reflog_expire_config(const char *var, const char *value,
152146
return 0;
153147
}
154148

155-
ent = find_cfg_ent(pattern, pattern_len);
149+
ent = find_cfg_ent(opts, pattern, pattern_len);
156150
if (!ent)
157151
return -1;
158152
switch (slot) {
@@ -168,12 +162,12 @@ static int reflog_expire_config(const char *var, const char *value,
168162

169163
static void set_reflog_expiry_param(struct reflog_expire_options *cb, const char *ref)
170164
{
171-
struct reflog_expire_cfg *ent;
165+
struct reflog_expire_entry_option *ent;
172166

173167
if (cb->explicit_expiry == (EXPIRE_TOTAL|EXPIRE_UNREACH))
174168
return; /* both given explicitly -- nothing to tweak */
175169

176-
for (ent = reflog_expire_cfg; ent; ent = ent->next) {
170+
for (ent = cb->entries; ent; ent = ent->next) {
177171
if (!wildmatch(ent->pattern, ref, 0)) {
178172
if (!(cb->explicit_expiry & EXPIRE_TOTAL))
179173
cb->expire_total = ent->expire_total;

reflog.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
#define REFLOG_H
33
#include "refs.h"
44

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+
512
struct reflog_expire_options {
13+
struct reflog_expire_entry_option *entries, **entries_tail;
614
int stalefix;
715
int explicit_expiry;
816
timestamp_t default_expire_total;

0 commit comments

Comments
 (0)