Skip to content

Commit 8565827

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

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

builtin/reflog.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ static const char *const reflog_usage[] = {
6363
NULL
6464
};
6565

66-
static timestamp_t default_reflog_expire;
67-
static timestamp_t default_reflog_expire_unreachable;
68-
6966
struct worktree_reflogs {
7067
struct worktree *worktree;
7168
struct string_list reflogs;
@@ -122,6 +119,7 @@ static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)
122119
static int reflog_expire_config(const char *var, const char *value,
123120
const struct config_context *ctx, void *cb)
124121
{
122+
struct reflog_expire_options *opts = cb;
125123
const char *pattern, *key;
126124
size_t pattern_len;
127125
timestamp_t expire;
@@ -145,10 +143,10 @@ static int reflog_expire_config(const char *var, const char *value,
145143
if (!pattern) {
146144
switch (slot) {
147145
case EXPIRE_TOTAL:
148-
default_reflog_expire = expire;
146+
opts->default_expire_total = expire;
149147
break;
150148
case EXPIRE_UNREACH:
151-
default_reflog_expire_unreachable = expire;
149+
opts->default_expire_unreachable = expire;
152150
break;
153151
}
154152
return 0;
@@ -198,9 +196,9 @@ static void set_reflog_expiry_param(struct reflog_expire_options *cb, const char
198196

199197
/* Nothing matched -- use the default value */
200198
if (!(cb->explicit_expiry & EXPIRE_TOTAL))
201-
cb->expire_total = default_reflog_expire;
199+
cb->expire_total = cb->default_expire_total;
202200
if (!(cb->explicit_expiry & EXPIRE_UNREACH))
203-
cb->expire_unreachable = default_reflog_expire_unreachable;
201+
cb->expire_unreachable = cb->default_expire_unreachable;
204202
}
205203

206204
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,
276274
static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
277275
struct repository *repo UNUSED)
278276
{
279-
struct reflog_expire_options opts = { 0 };
280277
timestamp_t now = time(NULL);
278+
struct reflog_expire_options opts = REFLOG_EXPIRE_OPTIONS_INIT(now);
281279
int i, status, do_all, single_worktree = 0;
282280
unsigned int flags = 0;
283281
int verbose = 0;
@@ -308,17 +306,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
308306
OPT_END()
309307
};
310308

311-
default_reflog_expire_unreachable = now - 30 * 24 * 3600;
312-
default_reflog_expire = now - 90 * 24 * 3600;
313-
git_config(reflog_expire_config, NULL);
309+
git_config(reflog_expire_config, &opts);
314310

315311
save_commit_buffer = 0;
316312
do_all = status = 0;
317313

318-
opts.explicit_expiry = 0;
319-
opts.expire_total = default_reflog_expire;
320-
opts.expire_unreachable = default_reflog_expire_unreachable;
321-
322314
argc = parse_options(argc, argv, prefix, options, reflog_expire_usage, 0);
323315

324316
if (verbose)

reflog.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
struct reflog_expire_options {
66
int stalefix;
77
int explicit_expiry;
8+
timestamp_t default_expire_total;
89
timestamp_t expire_total;
10+
timestamp_t default_expire_unreachable;
911
timestamp_t expire_unreachable;
1012
int recno;
1113
};
14+
#define REFLOG_EXPIRE_OPTIONS_INIT(now) { \
15+
.default_expire_total = now - 30 * 24 * 3600, \
16+
.default_expire_unreachable = now - 90 * 24 * 3600, \
17+
}
1218

1319
struct expire_reflog_policy_cb {
1420
enum {

0 commit comments

Comments
 (0)