reflog: rename cmd_reflog_expire_cb to reflog_expire_options

We're about to expose `struct cmd_reflog_expire_cb` via "reflog.h" so
that we can also use this structure in "builtin/gc.c". Once we make it
accessible to a wider scope though it becomes awkwardly named, as it
isn't only useful in the context of a callback. Instead, the function is
containing all kinds of options relevant to whether or not a reflog
entry should be expired.

Rename the structure to `reflog_expire_options` to prepare for this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2025-04-08 08:22:12 +02:00
committed by Junio C Hamano
parent 08bdfd4535
commit 2ed8008399
3 changed files with 36 additions and 36 deletions

View File

@@ -168,7 +168,7 @@ static int reflog_expire_config(const char *var, const char *value,
return 0; return 0;
} }
static void set_reflog_expiry_param(struct cmd_reflog_expire_cb *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_cfg *ent;
@@ -207,15 +207,15 @@ static int expire_unreachable_callback(const struct option *opt,
const char *arg, const char *arg,
int unset) int unset)
{ {
struct cmd_reflog_expire_cb *cmd = opt->value; struct reflog_expire_options *opts = opt->value;
BUG_ON_OPT_NEG(unset); BUG_ON_OPT_NEG(unset);
if (parse_expiry_date(arg, &cmd->expire_unreachable)) if (parse_expiry_date(arg, &opts->expire_unreachable))
die(_("invalid timestamp '%s' given to '--%s'"), die(_("invalid timestamp '%s' given to '--%s'"),
arg, opt->long_name); arg, opt->long_name);
cmd->explicit_expiry |= EXPIRE_UNREACH; opts->explicit_expiry |= EXPIRE_UNREACH;
return 0; return 0;
} }
@@ -223,15 +223,15 @@ static int expire_total_callback(const struct option *opt,
const char *arg, const char *arg,
int unset) int unset)
{ {
struct cmd_reflog_expire_cb *cmd = opt->value; struct reflog_expire_options *opts = opt->value;
BUG_ON_OPT_NEG(unset); BUG_ON_OPT_NEG(unset);
if (parse_expiry_date(arg, &cmd->expire_total)) if (parse_expiry_date(arg, &opts->expire_total))
die(_("invalid timestamp '%s' given to '--%s'"), die(_("invalid timestamp '%s' given to '--%s'"),
arg, opt->long_name); arg, opt->long_name);
cmd->explicit_expiry |= EXPIRE_TOTAL; opts->explicit_expiry |= EXPIRE_TOTAL;
return 0; return 0;
} }
@@ -276,7 +276,7 @@ static int cmd_reflog_list(int argc, const char **argv, const char *prefix,
static int cmd_reflog_expire(int argc, const char **argv, const char *prefix, static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED) struct repository *repo UNUSED)
{ {
struct cmd_reflog_expire_cb cmd = { 0 }; struct reflog_expire_options opts = { 0 };
timestamp_t now = time(NULL); timestamp_t now = time(NULL);
int i, status, do_all, single_worktree = 0; int i, status, do_all, single_worktree = 0;
unsigned int flags = 0; unsigned int flags = 0;
@@ -292,15 +292,15 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
N_("update the reference to the value of the top reflog entry"), N_("update the reference to the value of the top reflog entry"),
EXPIRE_REFLOGS_UPDATE_REF), EXPIRE_REFLOGS_UPDATE_REF),
OPT_BOOL(0, "verbose", &verbose, N_("print extra information on screen")), OPT_BOOL(0, "verbose", &verbose, N_("print extra information on screen")),
OPT_CALLBACK_F(0, "expire", &cmd, N_("timestamp"), OPT_CALLBACK_F(0, "expire", &opts, N_("timestamp"),
N_("prune entries older than the specified time"), N_("prune entries older than the specified time"),
PARSE_OPT_NONEG, PARSE_OPT_NONEG,
expire_total_callback), expire_total_callback),
OPT_CALLBACK_F(0, "expire-unreachable", &cmd, N_("timestamp"), OPT_CALLBACK_F(0, "expire-unreachable", &opts, N_("timestamp"),
N_("prune entries older than <time> that are not reachable from the current tip of the branch"), N_("prune entries older than <time> that are not reachable from the current tip of the branch"),
PARSE_OPT_NONEG, PARSE_OPT_NONEG,
expire_unreachable_callback), expire_unreachable_callback),
OPT_BOOL(0, "stale-fix", &cmd.stalefix, OPT_BOOL(0, "stale-fix", &opts.stalefix,
N_("prune any reflog entries that point to broken commits")), N_("prune any reflog entries that point to broken commits")),
OPT_BOOL(0, "all", &do_all, N_("process the reflogs of all references")), OPT_BOOL(0, "all", &do_all, N_("process the reflogs of all references")),
OPT_BOOL(0, "single-worktree", &single_worktree, OPT_BOOL(0, "single-worktree", &single_worktree,
@@ -315,9 +315,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
save_commit_buffer = 0; save_commit_buffer = 0;
do_all = status = 0; do_all = status = 0;
cmd.explicit_expiry = 0; opts.explicit_expiry = 0;
cmd.expire_total = default_reflog_expire; opts.expire_total = default_reflog_expire;
cmd.expire_unreachable = default_reflog_expire_unreachable; opts.expire_unreachable = default_reflog_expire_unreachable;
argc = parse_options(argc, argv, prefix, options, reflog_expire_usage, 0); argc = parse_options(argc, argv, prefix, options, reflog_expire_usage, 0);
@@ -329,7 +329,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
* even in older repository. We cannot trust what's reachable * even in older repository. We cannot trust what's reachable
* from reflog if the repository was pruned with older git. * from reflog if the repository was pruned with older git.
*/ */
if (cmd.stalefix) { if (opts.stalefix) {
struct rev_info revs; struct rev_info revs;
repo_init_revisions(the_repository, &revs, prefix); repo_init_revisions(the_repository, &revs, prefix);
@@ -363,11 +363,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
for_each_string_list_item(item, &collected.reflogs) { for_each_string_list_item(item, &collected.reflogs) {
struct expire_reflog_policy_cb cb = { struct expire_reflog_policy_cb cb = {
.cmd = cmd, .opts = opts,
.dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN), .dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN),
}; };
set_reflog_expiry_param(&cb.cmd, item->string); set_reflog_expiry_param(&cb.opts, item->string);
status |= refs_reflog_expire(get_main_ref_store(the_repository), status |= refs_reflog_expire(get_main_ref_store(the_repository),
item->string, flags, item->string, flags,
reflog_expiry_prepare, reflog_expiry_prepare,
@@ -380,13 +380,13 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
char *ref; char *ref;
struct expire_reflog_policy_cb cb = { .cmd = cmd }; struct expire_reflog_policy_cb cb = { .opts = opts };
if (!repo_dwim_log(the_repository, argv[i], strlen(argv[i]), NULL, &ref)) { if (!repo_dwim_log(the_repository, argv[i], strlen(argv[i]), NULL, &ref)) {
status |= error(_("%s points nowhere!"), argv[i]); status |= error(_("%s points nowhere!"), argv[i]);
continue; continue;
} }
set_reflog_expiry_param(&cb.cmd, ref); set_reflog_expiry_param(&cb.opts, ref);
status |= refs_reflog_expire(get_main_ref_store(the_repository), status |= refs_reflog_expire(get_main_ref_store(the_repository),
ref, flags, ref, flags,
reflog_expiry_prepare, reflog_expiry_prepare,

View File

@@ -252,15 +252,15 @@ int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
struct expire_reflog_policy_cb *cb = cb_data; struct expire_reflog_policy_cb *cb = cb_data;
struct commit *old_commit, *new_commit; struct commit *old_commit, *new_commit;
if (timestamp < cb->cmd.expire_total) if (timestamp < cb->opts.expire_total)
return 1; return 1;
old_commit = new_commit = NULL; old_commit = new_commit = NULL;
if (cb->cmd.stalefix && if (cb->opts.stalefix &&
(!keep_entry(&old_commit, ooid) || !keep_entry(&new_commit, noid))) (!keep_entry(&old_commit, ooid) || !keep_entry(&new_commit, noid)))
return 1; return 1;
if (timestamp < cb->cmd.expire_unreachable) { if (timestamp < cb->opts.expire_unreachable) {
switch (cb->unreachable_expire_kind) { switch (cb->unreachable_expire_kind) {
case UE_ALWAYS: case UE_ALWAYS:
return 1; return 1;
@@ -272,7 +272,7 @@ int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
} }
} }
if (cb->cmd.recno && --(cb->cmd.recno) == 0) if (cb->opts.recno && --(cb->opts.recno) == 0)
return 1; return 1;
return 0; return 0;
@@ -331,7 +331,7 @@ void reflog_expiry_prepare(const char *refname,
struct commit_list *elem; struct commit_list *elem;
struct commit *commit = NULL; struct commit *commit = NULL;
if (!cb->cmd.expire_unreachable || is_head(refname)) { if (!cb->opts.expire_unreachable || is_head(refname)) {
cb->unreachable_expire_kind = UE_HEAD; cb->unreachable_expire_kind = UE_HEAD;
} else { } else {
commit = lookup_commit_reference_gently(the_repository, commit = lookup_commit_reference_gently(the_repository,
@@ -341,7 +341,7 @@ void reflog_expiry_prepare(const char *refname,
cb->unreachable_expire_kind = commit ? UE_NORMAL : UE_ALWAYS; cb->unreachable_expire_kind = commit ? UE_NORMAL : UE_ALWAYS;
} }
if (cb->cmd.expire_unreachable <= cb->cmd.expire_total) if (cb->opts.expire_unreachable <= cb->opts.expire_total)
cb->unreachable_expire_kind = UE_ALWAYS; cb->unreachable_expire_kind = UE_ALWAYS;
switch (cb->unreachable_expire_kind) { switch (cb->unreachable_expire_kind) {
@@ -358,7 +358,7 @@ void reflog_expiry_prepare(const char *refname,
/* For reflog_expiry_cleanup() below */ /* For reflog_expiry_cleanup() below */
cb->tip_commit = commit; cb->tip_commit = commit;
} }
cb->mark_limit = cb->cmd.expire_total; cb->mark_limit = cb->opts.expire_total;
mark_reachable(cb); mark_reachable(cb);
} }
@@ -390,7 +390,7 @@ int count_reflog_ent(struct object_id *ooid UNUSED,
timestamp_t timestamp, int tz UNUSED, timestamp_t timestamp, int tz UNUSED,
const char *message UNUSED, void *cb_data) const char *message UNUSED, void *cb_data)
{ {
struct cmd_reflog_expire_cb *cb = cb_data; struct reflog_expire_options *cb = cb_data;
if (!cb->expire_total || timestamp < cb->expire_total) if (!cb->expire_total || timestamp < cb->expire_total)
cb->recno++; cb->recno++;
return 0; return 0;
@@ -398,7 +398,7 @@ int count_reflog_ent(struct object_id *ooid UNUSED,
int reflog_delete(const char *rev, enum expire_reflog_flags flags, int verbose) int reflog_delete(const char *rev, enum expire_reflog_flags flags, int verbose)
{ {
struct cmd_reflog_expire_cb cmd = { 0 }; struct reflog_expire_options opts = { 0 };
int status = 0; int status = 0;
reflog_expiry_should_prune_fn *should_prune_fn = should_expire_reflog_ent; reflog_expiry_should_prune_fn *should_prune_fn = should_expire_reflog_ent;
const char *spec = strstr(rev, "@{"); const char *spec = strstr(rev, "@{");
@@ -421,17 +421,17 @@ int reflog_delete(const char *rev, enum expire_reflog_flags flags, int verbose)
recno = strtoul(spec + 2, &ep, 10); recno = strtoul(spec + 2, &ep, 10);
if (*ep == '}') { if (*ep == '}') {
cmd.recno = -recno; opts.recno = -recno;
refs_for_each_reflog_ent(get_main_ref_store(the_repository), refs_for_each_reflog_ent(get_main_ref_store(the_repository),
ref, count_reflog_ent, &cmd); ref, count_reflog_ent, &opts);
} else { } else {
cmd.expire_total = approxidate(spec + 2); opts.expire_total = approxidate(spec + 2);
refs_for_each_reflog_ent(get_main_ref_store(the_repository), refs_for_each_reflog_ent(get_main_ref_store(the_repository),
ref, count_reflog_ent, &cmd); ref, count_reflog_ent, &opts);
cmd.expire_total = 0; opts.expire_total = 0;
} }
cb.cmd = cmd; cb.opts = opts;
status |= refs_reflog_expire(get_main_ref_store(the_repository), ref, status |= refs_reflog_expire(get_main_ref_store(the_repository), ref,
flags, flags,
reflog_expiry_prepare, reflog_expiry_prepare,

View File

@@ -2,7 +2,7 @@
#define REFLOG_H #define REFLOG_H
#include "refs.h" #include "refs.h"
struct cmd_reflog_expire_cb { struct reflog_expire_options {
int stalefix; int stalefix;
int explicit_expiry; int explicit_expiry;
timestamp_t expire_total; timestamp_t expire_total;
@@ -18,7 +18,7 @@ struct expire_reflog_policy_cb {
} unreachable_expire_kind; } unreachable_expire_kind;
struct commit_list *mark_list; struct commit_list *mark_list;
unsigned long mark_limit; unsigned long mark_limit;
struct cmd_reflog_expire_cb cmd; struct reflog_expire_options opts;
struct commit *tip_commit; struct commit *tip_commit;
struct commit_list *tips; struct commit_list *tips;
unsigned int dry_run:1; unsigned int dry_run:1;