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>
This commit is contained in:
committed by
Junio C Hamano
parent
8565827570
commit
964f364de9
@@ -88,27 +88,21 @@ static int collect_reflog(const char *ref, void *cb_data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct reflog_expire_cfg {
|
static struct reflog_expire_entry_option *find_cfg_ent(struct reflog_expire_options *opts,
|
||||||
struct reflog_expire_cfg *next;
|
const char *pattern, size_t len)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
struct reflog_expire_cfg *ent;
|
struct reflog_expire_entry_option *ent;
|
||||||
|
|
||||||
if (!reflog_expire_cfg_tail)
|
if (!opts->entries_tail)
|
||||||
reflog_expire_cfg_tail = &reflog_expire_cfg;
|
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))
|
if (!xstrncmpz(ent->pattern, pattern, len))
|
||||||
return ent;
|
return ent;
|
||||||
|
|
||||||
FLEX_ALLOC_MEM(ent, pattern, pattern, len);
|
FLEX_ALLOC_MEM(ent, pattern, pattern, len);
|
||||||
*reflog_expire_cfg_tail = ent;
|
*opts->entries_tail = ent;
|
||||||
reflog_expire_cfg_tail = &(ent->next);
|
opts->entries_tail = &(ent->next);
|
||||||
return ent;
|
return ent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +118,7 @@ static int reflog_expire_config(const char *var, const char *value,
|
|||||||
size_t pattern_len;
|
size_t pattern_len;
|
||||||
timestamp_t expire;
|
timestamp_t expire;
|
||||||
int slot;
|
int slot;
|
||||||
struct reflog_expire_cfg *ent;
|
struct reflog_expire_entry_option *ent;
|
||||||
|
|
||||||
if (parse_config_key(var, "gc", &pattern, &pattern_len, &key) < 0)
|
if (parse_config_key(var, "gc", &pattern, &pattern_len, &key) < 0)
|
||||||
return git_default_config(var, value, ctx, cb);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ent = find_cfg_ent(pattern, pattern_len);
|
ent = find_cfg_ent(opts, pattern, pattern_len);
|
||||||
if (!ent)
|
if (!ent)
|
||||||
return -1;
|
return -1;
|
||||||
switch (slot) {
|
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)
|
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))
|
if (cb->explicit_expiry == (EXPIRE_TOTAL|EXPIRE_UNREACH))
|
||||||
return; /* both given explicitly -- nothing to tweak */
|
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 (!wildmatch(ent->pattern, ref, 0)) {
|
||||||
if (!(cb->explicit_expiry & EXPIRE_TOTAL))
|
if (!(cb->explicit_expiry & EXPIRE_TOTAL))
|
||||||
cb->expire_total = ent->expire_total;
|
cb->expire_total = ent->expire_total;
|
||||||
|
|||||||
8
reflog.h
8
reflog.h
@@ -2,7 +2,15 @@
|
|||||||
#define REFLOG_H
|
#define REFLOG_H
|
||||||
#include "refs.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_options {
|
||||||
|
struct reflog_expire_entry_option *entries, **entries_tail;
|
||||||
int stalefix;
|
int stalefix;
|
||||||
int explicit_expiry;
|
int explicit_expiry;
|
||||||
timestamp_t default_expire_total;
|
timestamp_t default_expire_total;
|
||||||
|
|||||||
Reference in New Issue
Block a user