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>
Patrick Steinhardt committed
Apr 8, 2025 at 08:22 UTC
2ed800839904d598b6c67e6ed2d57276bef9777d
3 files changed
+36
-36
builtin/reflog.c
+19
-19
@@ -168,7 +168,7 @@ static int reflog_expire_config(const char *var, const char *value,
168
return 0;
169
}
170
171
-static void set_reflog_expiry_param(struct cmd_reflog_expire_cb *cb, const char *ref)
171
+static void set_reflog_expiry_param(struct reflog_expire_options *cb, const char *ref)
172
{
173
struct reflog_expire_cfg *ent;
174
@@ -207,15 +207,15 @@ static int expire_unreachable_callback(const struct option *opt,
207
const char *arg,
208
int unset)
209
{
210
- struct cmd_reflog_expire_cb *cmd = opt->value;
210
+ struct reflog_expire_options *opts = opt->value;
211
212
BUG_ON_OPT_NEG(unset);
213
214
- if (parse_expiry_date(arg, &cmd->expire_unreachable))
214
+ if (parse_expiry_date(arg, &opts->expire_unreachable))
215
die(_("invalid timestamp '%s' given to '--%s'"),
216
arg, opt->long_name);
217
218
- cmd->explicit_expiry |= EXPIRE_UNREACH;
218
+ opts->explicit_expiry |= EXPIRE_UNREACH;
219
return 0;
220
}
221
@@ -223,15 +223,15 @@ static int expire_total_callback(const struct option *opt,
223
const char *arg,
224
int unset)
225
{
226
- struct cmd_reflog_expire_cb *cmd = opt->value;
226
+ struct reflog_expire_options *opts = opt->value;
227
228
BUG_ON_OPT_NEG(unset);
229
230
- if (parse_expiry_date(arg, &cmd->expire_total))
230
+ if (parse_expiry_date(arg, &opts->expire_total))
231
die(_("invalid timestamp '%s' given to '--%s'"),
232
arg, opt->long_name);
233
234
- cmd->explicit_expiry |= EXPIRE_TOTAL;
234
+ opts->explicit_expiry |= EXPIRE_TOTAL;
235
return 0;
236
}
237
@@ -276,7 +276,7 @@ static int cmd_reflog_list(int argc, const char **argv, const char *prefix,
276
static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
277
struct repository *repo UNUSED)
278
{
279
- struct cmd_reflog_expire_cb cmd = { 0 };
279
+ struct reflog_expire_options opts = { 0 };
280
timestamp_t now = time(NULL);
281
int i, status, do_all, single_worktree = 0;
282
unsigned int flags = 0;
@@ -292,15 +292,15 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
292
N_("update the reference to the value of the top reflog entry"),
293
EXPIRE_REFLOGS_UPDATE_REF),
294
OPT_BOOL(0, "verbose", &verbose, N_("print extra information on screen")),
295
- OPT_CALLBACK_F(0, "expire", &cmd, N_("timestamp"),
295
+ OPT_CALLBACK_F(0, "expire", &opts, N_("timestamp"),
296
N_("prune entries older than the specified time"),
297
PARSE_OPT_NONEG,
298
expire_total_callback),
299
- OPT_CALLBACK_F(0, "expire-unreachable", &cmd, N_("timestamp"),
299
+ OPT_CALLBACK_F(0, "expire-unreachable", &opts, N_("timestamp"),
300
N_("prune entries older than <time> that are not reachable from the current tip of the branch"),
301
PARSE_OPT_NONEG,
302
expire_unreachable_callback),
303
- OPT_BOOL(0, "stale-fix", &cmd.stalefix,
303
+ OPT_BOOL(0, "stale-fix", &opts.stalefix,
304
N_("prune any reflog entries that point to broken commits")),
305
OPT_BOOL(0, "all", &do_all, N_("process the reflogs of all references")),
306
OPT_BOOL(0, "single-worktree", &single_worktree,
@@ -315,9 +315,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
315
save_commit_buffer = 0;
316
do_all = status = 0;
317
318
- cmd.explicit_expiry = 0;
319
- cmd.expire_total = default_reflog_expire;
320
- cmd.expire_unreachable = default_reflog_expire_unreachable;
318
+ opts.explicit_expiry = 0;
319
+ opts.expire_total = default_reflog_expire;
320
+ opts.expire_unreachable = default_reflog_expire_unreachable;
321
322
argc = parse_options(argc, argv, prefix, options, reflog_expire_usage, 0);
323
@@ -329,7 +329,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
329
* even in older repository. We cannot trust what's reachable
330
* from reflog if the repository was pruned with older git.
331
*/
332
- if (cmd.stalefix) {
332
+ if (opts.stalefix) {
333
struct rev_info revs;
334
335
repo_init_revisions(the_repository, &revs, prefix);
@@ -363,11 +363,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
363
364
for_each_string_list_item(item, &collected.reflogs) {
365
struct expire_reflog_policy_cb cb = {
366
- .cmd = cmd,
366
+ .opts = opts,
367
.dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN),
368
};
369
370
- set_reflog_expiry_param(&cb.cmd, item->string);
370
+ set_reflog_expiry_param(&cb.opts, item->string);
371
status |= refs_reflog_expire(get_main_ref_store(the_repository),
372
item->string, flags,
373
reflog_expiry_prepare,
@@ -380,13 +380,13 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
380
381
for (i = 0; i < argc; i++) {
382
char *ref;
383
- struct expire_reflog_policy_cb cb = { .cmd = cmd };
383
+ struct expire_reflog_policy_cb cb = { .opts = opts };
384
385
if (!repo_dwim_log(the_repository, argv[i], strlen(argv[i]), NULL, &ref)) {
386
status |= error(_("%s points nowhere!"), argv[i]);
387
continue;
388
}
389
- set_reflog_expiry_param(&cb.cmd, ref);
389
+ set_reflog_expiry_param(&cb.opts, ref);
390
status |= refs_reflog_expire(get_main_ref_store(the_repository),
391
ref, flags,
392
reflog_expiry_prepare,
reflog.c
+15
-15
@@ -252,15 +252,15 @@ int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
252
struct expire_reflog_policy_cb *cb = cb_data;
253
struct commit *old_commit, *new_commit;
254
255
- if (timestamp < cb->cmd.expire_total)
255
+ if (timestamp < cb->opts.expire_total)
256
return 1;
257
258
old_commit = new_commit = NULL;
259
- if (cb->cmd.stalefix &&
259
+ if (cb->opts.stalefix &&
260
(!keep_entry(&old_commit, ooid) || !keep_entry(&new_commit, noid)))
261
return 1;
262
263
- if (timestamp < cb->cmd.expire_unreachable) {
263
+ if (timestamp < cb->opts.expire_unreachable) {
264
switch (cb->unreachable_expire_kind) {
265
case UE_ALWAYS:
266
return 1;
@@ -272,7 +272,7 @@ int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
272
}
273
}
274
275
- if (cb->cmd.recno && --(cb->cmd.recno) == 0)
275
+ if (cb->opts.recno && --(cb->opts.recno) == 0)
276
return 1;
277
278
return 0;
@@ -331,7 +331,7 @@ void reflog_expiry_prepare(const char *refname,
331
struct commit_list *elem;
332
struct commit *commit = NULL;
333
334
- if (!cb->cmd.expire_unreachable || is_head(refname)) {
334
+ if (!cb->opts.expire_unreachable || is_head(refname)) {
335
cb->unreachable_expire_kind = UE_HEAD;
336
} else {
337
commit = lookup_commit_reference_gently(the_repository,
@@ -341,7 +341,7 @@ void reflog_expiry_prepare(const char *refname,
341
cb->unreachable_expire_kind = commit ? UE_NORMAL : UE_ALWAYS;
342
}
343
344
- if (cb->cmd.expire_unreachable <= cb->cmd.expire_total)
344
+ if (cb->opts.expire_unreachable <= cb->opts.expire_total)
345
cb->unreachable_expire_kind = UE_ALWAYS;
346
347
switch (cb->unreachable_expire_kind) {
@@ -358,7 +358,7 @@ void reflog_expiry_prepare(const char *refname,
358
/* For reflog_expiry_cleanup() below */
359
cb->tip_commit = commit;
360
}
361
- cb->mark_limit = cb->cmd.expire_total;
361
+ cb->mark_limit = cb->opts.expire_total;
362
mark_reachable(cb);
363
}
364
@@ -390,7 +390,7 @@ int count_reflog_ent(struct object_id *ooid UNUSED,
390
timestamp_t timestamp, int tz UNUSED,
391
const char *message UNUSED, void *cb_data)
392
{
393
- struct cmd_reflog_expire_cb *cb = cb_data;
393
+ struct reflog_expire_options *cb = cb_data;
394
if (!cb->expire_total || timestamp < cb->expire_total)
395
cb->recno++;
396
return 0;
@@ -398,7 +398,7 @@ int count_reflog_ent(struct object_id *ooid UNUSED,
398
399
int reflog_delete(const char *rev, enum expire_reflog_flags flags, int verbose)
400
{
401
- struct cmd_reflog_expire_cb cmd = { 0 };
401
+ struct reflog_expire_options opts = { 0 };
402
int status = 0;
403
reflog_expiry_should_prune_fn *should_prune_fn = should_expire_reflog_ent;
404
const char *spec = strstr(rev, "@{");
@@ -421,17 +421,17 @@ int reflog_delete(const char *rev, enum expire_reflog_flags flags, int verbose)
421
422
recno = strtoul(spec + 2, &ep, 10);
423
if (*ep == '}') {
424
- cmd.recno = -recno;
424
+ opts.recno = -recno;
425
refs_for_each_reflog_ent(get_main_ref_store(the_repository),
426
- ref, count_reflog_ent, &cmd);
426
+ ref, count_reflog_ent, &opts);
427
} else {
428
- cmd.expire_total = approxidate(spec + 2);
428
+ opts.expire_total = approxidate(spec + 2);
429
refs_for_each_reflog_ent(get_main_ref_store(the_repository),
430
- ref, count_reflog_ent, &cmd);
431
- cmd.expire_total = 0;
430
+ ref, count_reflog_ent, &opts);
431
+ opts.expire_total = 0;
432
}
433
434
- cb.cmd = cmd;
434
+ cb.opts = opts;
435
status |= refs_reflog_expire(get_main_ref_store(the_repository), ref,
436
flags,
437
reflog_expiry_prepare,
reflog.h
+2
-2
@@ -2,7 +2,7 @@
2
#define REFLOG_H
3
#include "refs.h"
4
5
-struct cmd_reflog_expire_cb {
5
+struct reflog_expire_options {
6
int stalefix;
7
int explicit_expiry;
8
timestamp_t expire_total;
@@ -18,7 +18,7 @@ struct expire_reflog_policy_cb {
18
} unreachable_expire_kind;
19
struct commit_list *mark_list;
20
unsigned long mark_limit;
21
- struct cmd_reflog_expire_cb cmd;
21
+ struct reflog_expire_options opts;
22
struct commit *tip_commit;
23
struct commit_list *tips;
24
unsigned int dry_run:1;