Skip to content

Commit 2ed8008

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

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

builtin/reflog.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static int reflog_expire_config(const char *var, const char *value,
168168
return 0;
169169
}
170170

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)
172172
{
173173
struct reflog_expire_cfg *ent;
174174

@@ -207,31 +207,31 @@ static int expire_unreachable_callback(const struct option *opt,
207207
const char *arg,
208208
int unset)
209209
{
210-
struct cmd_reflog_expire_cb *cmd = opt->value;
210+
struct reflog_expire_options *opts = opt->value;
211211

212212
BUG_ON_OPT_NEG(unset);
213213

214-
if (parse_expiry_date(arg, &cmd->expire_unreachable))
214+
if (parse_expiry_date(arg, &opts->expire_unreachable))
215215
die(_("invalid timestamp '%s' given to '--%s'"),
216216
arg, opt->long_name);
217217

218-
cmd->explicit_expiry |= EXPIRE_UNREACH;
218+
opts->explicit_expiry |= EXPIRE_UNREACH;
219219
return 0;
220220
}
221221

222222
static int expire_total_callback(const struct option *opt,
223223
const char *arg,
224224
int unset)
225225
{
226-
struct cmd_reflog_expire_cb *cmd = opt->value;
226+
struct reflog_expire_options *opts = opt->value;
227227

228228
BUG_ON_OPT_NEG(unset);
229229

230-
if (parse_expiry_date(arg, &cmd->expire_total))
230+
if (parse_expiry_date(arg, &opts->expire_total))
231231
die(_("invalid timestamp '%s' given to '--%s'"),
232232
arg, opt->long_name);
233233

234-
cmd->explicit_expiry |= EXPIRE_TOTAL;
234+
opts->explicit_expiry |= EXPIRE_TOTAL;
235235
return 0;
236236
}
237237

@@ -276,7 +276,7 @@ static int cmd_reflog_list(int argc, const char **argv, const char *prefix,
276276
static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
277277
struct repository *repo UNUSED)
278278
{
279-
struct cmd_reflog_expire_cb cmd = { 0 };
279+
struct reflog_expire_options opts = { 0 };
280280
timestamp_t now = time(NULL);
281281
int i, status, do_all, single_worktree = 0;
282282
unsigned int flags = 0;
@@ -292,15 +292,15 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
292292
N_("update the reference to the value of the top reflog entry"),
293293
EXPIRE_REFLOGS_UPDATE_REF),
294294
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"),
296296
N_("prune entries older than the specified time"),
297297
PARSE_OPT_NONEG,
298298
expire_total_callback),
299-
OPT_CALLBACK_F(0, "expire-unreachable", &cmd, N_("timestamp"),
299+
OPT_CALLBACK_F(0, "expire-unreachable", &opts, N_("timestamp"),
300300
N_("prune entries older than <time> that are not reachable from the current tip of the branch"),
301301
PARSE_OPT_NONEG,
302302
expire_unreachable_callback),
303-
OPT_BOOL(0, "stale-fix", &cmd.stalefix,
303+
OPT_BOOL(0, "stale-fix", &opts.stalefix,
304304
N_("prune any reflog entries that point to broken commits")),
305305
OPT_BOOL(0, "all", &do_all, N_("process the reflogs of all references")),
306306
OPT_BOOL(0, "single-worktree", &single_worktree,
@@ -315,9 +315,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
315315
save_commit_buffer = 0;
316316
do_all = status = 0;
317317

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;
321321

322322
argc = parse_options(argc, argv, prefix, options, reflog_expire_usage, 0);
323323

@@ -329,7 +329,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
329329
* even in older repository. We cannot trust what's reachable
330330
* from reflog if the repository was pruned with older git.
331331
*/
332-
if (cmd.stalefix) {
332+
if (opts.stalefix) {
333333
struct rev_info revs;
334334

335335
repo_init_revisions(the_repository, &revs, prefix);
@@ -363,11 +363,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
363363

364364
for_each_string_list_item(item, &collected.reflogs) {
365365
struct expire_reflog_policy_cb cb = {
366-
.cmd = cmd,
366+
.opts = opts,
367367
.dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN),
368368
};
369369

370-
set_reflog_expiry_param(&cb.cmd, item->string);
370+
set_reflog_expiry_param(&cb.opts, item->string);
371371
status |= refs_reflog_expire(get_main_ref_store(the_repository),
372372
item->string, flags,
373373
reflog_expiry_prepare,
@@ -380,13 +380,13 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
380380

381381
for (i = 0; i < argc; i++) {
382382
char *ref;
383-
struct expire_reflog_policy_cb cb = { .cmd = cmd };
383+
struct expire_reflog_policy_cb cb = { .opts = opts };
384384

385385
if (!repo_dwim_log(the_repository, argv[i], strlen(argv[i]), NULL, &ref)) {
386386
status |= error(_("%s points nowhere!"), argv[i]);
387387
continue;
388388
}
389-
set_reflog_expiry_param(&cb.cmd, ref);
389+
set_reflog_expiry_param(&cb.opts, ref);
390390
status |= refs_reflog_expire(get_main_ref_store(the_repository),
391391
ref, flags,
392392
reflog_expiry_prepare,

reflog.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,15 @@ int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
252252
struct expire_reflog_policy_cb *cb = cb_data;
253253
struct commit *old_commit, *new_commit;
254254

255-
if (timestamp < cb->cmd.expire_total)
255+
if (timestamp < cb->opts.expire_total)
256256
return 1;
257257

258258
old_commit = new_commit = NULL;
259-
if (cb->cmd.stalefix &&
259+
if (cb->opts.stalefix &&
260260
(!keep_entry(&old_commit, ooid) || !keep_entry(&new_commit, noid)))
261261
return 1;
262262

263-
if (timestamp < cb->cmd.expire_unreachable) {
263+
if (timestamp < cb->opts.expire_unreachable) {
264264
switch (cb->unreachable_expire_kind) {
265265
case UE_ALWAYS:
266266
return 1;
@@ -272,7 +272,7 @@ int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
272272
}
273273
}
274274

275-
if (cb->cmd.recno && --(cb->cmd.recno) == 0)
275+
if (cb->opts.recno && --(cb->opts.recno) == 0)
276276
return 1;
277277

278278
return 0;
@@ -331,7 +331,7 @@ void reflog_expiry_prepare(const char *refname,
331331
struct commit_list *elem;
332332
struct commit *commit = NULL;
333333

334-
if (!cb->cmd.expire_unreachable || is_head(refname)) {
334+
if (!cb->opts.expire_unreachable || is_head(refname)) {
335335
cb->unreachable_expire_kind = UE_HEAD;
336336
} else {
337337
commit = lookup_commit_reference_gently(the_repository,
@@ -341,7 +341,7 @@ void reflog_expiry_prepare(const char *refname,
341341
cb->unreachable_expire_kind = commit ? UE_NORMAL : UE_ALWAYS;
342342
}
343343

344-
if (cb->cmd.expire_unreachable <= cb->cmd.expire_total)
344+
if (cb->opts.expire_unreachable <= cb->opts.expire_total)
345345
cb->unreachable_expire_kind = UE_ALWAYS;
346346

347347
switch (cb->unreachable_expire_kind) {
@@ -358,7 +358,7 @@ void reflog_expiry_prepare(const char *refname,
358358
/* For reflog_expiry_cleanup() below */
359359
cb->tip_commit = commit;
360360
}
361-
cb->mark_limit = cb->cmd.expire_total;
361+
cb->mark_limit = cb->opts.expire_total;
362362
mark_reachable(cb);
363363
}
364364

@@ -390,15 +390,15 @@ int count_reflog_ent(struct object_id *ooid UNUSED,
390390
timestamp_t timestamp, int tz UNUSED,
391391
const char *message UNUSED, void *cb_data)
392392
{
393-
struct cmd_reflog_expire_cb *cb = cb_data;
393+
struct reflog_expire_options *cb = cb_data;
394394
if (!cb->expire_total || timestamp < cb->expire_total)
395395
cb->recno++;
396396
return 0;
397397
}
398398

399399
int reflog_delete(const char *rev, enum expire_reflog_flags flags, int verbose)
400400
{
401-
struct cmd_reflog_expire_cb cmd = { 0 };
401+
struct reflog_expire_options opts = { 0 };
402402
int status = 0;
403403
reflog_expiry_should_prune_fn *should_prune_fn = should_expire_reflog_ent;
404404
const char *spec = strstr(rev, "@{");
@@ -421,17 +421,17 @@ int reflog_delete(const char *rev, enum expire_reflog_flags flags, int verbose)
421421

422422
recno = strtoul(spec + 2, &ep, 10);
423423
if (*ep == '}') {
424-
cmd.recno = -recno;
424+
opts.recno = -recno;
425425
refs_for_each_reflog_ent(get_main_ref_store(the_repository),
426-
ref, count_reflog_ent, &cmd);
426+
ref, count_reflog_ent, &opts);
427427
} else {
428-
cmd.expire_total = approxidate(spec + 2);
428+
opts.expire_total = approxidate(spec + 2);
429429
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;
432432
}
433433

434-
cb.cmd = cmd;
434+
cb.opts = opts;
435435
status |= refs_reflog_expire(get_main_ref_store(the_repository), ref,
436436
flags,
437437
reflog_expiry_prepare,

reflog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define REFLOG_H
33
#include "refs.h"
44

5-
struct cmd_reflog_expire_cb {
5+
struct reflog_expire_options {
66
int stalefix;
77
int explicit_expiry;
88
timestamp_t expire_total;
@@ -18,7 +18,7 @@ struct expire_reflog_policy_cb {
1818
} unreachable_expire_kind;
1919
struct commit_list *mark_list;
2020
unsigned long mark_limit;
21-
struct cmd_reflog_expire_cb cmd;
21+
struct reflog_expire_options opts;
2222
struct commit *tip_commit;
2323
struct commit_list *tips;
2424
unsigned int dry_run:1;

0 commit comments

Comments
 (0)