]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reflog: rename `cmd_reflog_expire_cb` to `reflog_expire_options`
authorPatrick Steinhardt <ps@pks.im>
Tue, 8 Apr 2025 06:22:12 +0000 (08:22 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2025 14:53:25 +0000 (07:53 -0700)
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>
builtin/reflog.c
reflog.c
reflog.h

index 95f264989bbf1a955b3be528b84ce1fe525e8459..dee49881d326e296b3e15d9708b13dfcc991d4a5 100644 (file)
@@ -168,7 +168,7 @@ static int reflog_expire_config(const char *var, const char *value,
        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;
 
@@ -207,15 +207,15 @@ static int expire_unreachable_callback(const struct option *opt,
                                 const char *arg,
                                 int unset)
 {
-       struct cmd_reflog_expire_cb *cmd = opt->value;
+       struct reflog_expire_options *opts = opt->value;
 
        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'"),
                    arg, opt->long_name);
 
-       cmd->explicit_expiry |= EXPIRE_UNREACH;
+       opts->explicit_expiry |= EXPIRE_UNREACH;
        return 0;
 }
 
@@ -223,15 +223,15 @@ static int expire_total_callback(const struct option *opt,
                                 const char *arg,
                                 int unset)
 {
-       struct cmd_reflog_expire_cb *cmd = opt->value;
+       struct reflog_expire_options *opts = opt->value;
 
        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'"),
                    arg, opt->long_name);
 
-       cmd->explicit_expiry |= EXPIRE_TOTAL;
+       opts->explicit_expiry |= EXPIRE_TOTAL;
        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,
                             struct repository *repo UNUSED)
 {
-       struct cmd_reflog_expire_cb cmd = { 0 };
+       struct reflog_expire_options opts = { 0 };
        timestamp_t now = time(NULL);
        int i, status, do_all, single_worktree = 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"),
                        EXPIRE_REFLOGS_UPDATE_REF),
                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"),
                               PARSE_OPT_NONEG,
                               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"),
                               PARSE_OPT_NONEG,
                               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")),
                OPT_BOOL(0, "all", &do_all, N_("process the reflogs of all references")),
                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;
        do_all = status = 0;
 
-       cmd.explicit_expiry = 0;
-       cmd.expire_total = default_reflog_expire;
-       cmd.expire_unreachable = default_reflog_expire_unreachable;
+       opts.explicit_expiry = 0;
+       opts.expire_total = default_reflog_expire;
+       opts.expire_unreachable = default_reflog_expire_unreachable;
 
        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
         * from reflog if the repository was pruned with older git.
         */
-       if (cmd.stalefix) {
+       if (opts.stalefix) {
                struct rev_info revs;
 
                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) {
                        struct expire_reflog_policy_cb cb = {
-                               .cmd = cmd,
+                               .opts = opts,
                                .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),
                                                     item->string, flags,
                                                     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++) {
                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)) {
                        status |= error(_("%s points nowhere!"), argv[i]);
                        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),
                                             ref, flags,
                                             reflog_expiry_prepare,
index 1b5f031f6d787f3e454471252c7a600dcb765a15..bcdb75514d0f6d27b79f3476b88a89ff3484403e 100644 (file)
--- a/reflog.c
+++ b/reflog.c
@@ -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 commit *old_commit, *new_commit;
 
-       if (timestamp < cb->cmd.expire_total)
+       if (timestamp < cb->opts.expire_total)
                return 1;
 
        old_commit = new_commit = NULL;
-       if (cb->cmd.stalefix &&
+       if (cb->opts.stalefix &&
            (!keep_entry(&old_commit, ooid) || !keep_entry(&new_commit, noid)))
                return 1;
 
-       if (timestamp < cb->cmd.expire_unreachable) {
+       if (timestamp < cb->opts.expire_unreachable) {
                switch (cb->unreachable_expire_kind) {
                case UE_ALWAYS:
                        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 0;
@@ -331,7 +331,7 @@ void reflog_expiry_prepare(const char *refname,
        struct commit_list *elem;
        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;
        } else {
                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;
        }
 
-       if (cb->cmd.expire_unreachable <= cb->cmd.expire_total)
+       if (cb->opts.expire_unreachable <= cb->opts.expire_total)
                cb->unreachable_expire_kind = UE_ALWAYS;
 
        switch (cb->unreachable_expire_kind) {
@@ -358,7 +358,7 @@ void reflog_expiry_prepare(const char *refname,
                /* For reflog_expiry_cleanup() below */
                cb->tip_commit = commit;
        }
-       cb->mark_limit = cb->cmd.expire_total;
+       cb->mark_limit = cb->opts.expire_total;
        mark_reachable(cb);
 }
 
@@ -390,7 +390,7 @@ int count_reflog_ent(struct object_id *ooid UNUSED,
                     timestamp_t timestamp, int tz UNUSED,
                     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)
                cb->recno++;
        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)
 {
-       struct cmd_reflog_expire_cb cmd = { 0 };
+       struct reflog_expire_options opts = { 0 };
        int status = 0;
        reflog_expiry_should_prune_fn *should_prune_fn = should_expire_reflog_ent;
        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);
        if (*ep == '}') {
-               cmd.recno = -recno;
+               opts.recno = -recno;
                refs_for_each_reflog_ent(get_main_ref_store(the_repository),
-                                        ref, count_reflog_ent, &cmd);
+                                        ref, count_reflog_ent, &opts);
        } else {
-               cmd.expire_total = approxidate(spec + 2);
+               opts.expire_total = approxidate(spec + 2);
                refs_for_each_reflog_ent(get_main_ref_store(the_repository),
-                                        ref, count_reflog_ent, &cmd);
-               cmd.expire_total = 0;
+                                        ref, count_reflog_ent, &opts);
+               opts.expire_total = 0;
        }
 
-       cb.cmd = cmd;
+       cb.opts = opts;
        status |= refs_reflog_expire(get_main_ref_store(the_repository), ref,
                                     flags,
                                     reflog_expiry_prepare,
index d2906fb9f8dd8beb80e12f7af831adff7aeb8c75..eb948119e53a948309c996d8753428da41a49ab3 100644 (file)
--- a/reflog.h
+++ b/reflog.h
@@ -2,7 +2,7 @@
 #define REFLOG_H
 #include "refs.h"
 
-struct cmd_reflog_expire_cb {
+struct reflog_expire_options {
        int stalefix;
        int explicit_expiry;
        timestamp_t expire_total;
@@ -18,7 +18,7 @@ struct expire_reflog_policy_cb {
        } unreachable_expire_kind;
        struct commit_list *mark_list;
        unsigned long mark_limit;
-       struct cmd_reflog_expire_cb cmd;
+       struct reflog_expire_options opts;
        struct commit *tip_commit;
        struct commit_list *tips;
        unsigned int dry_run:1;