Skip to content

Commit 4a0339b

Browse files
avargitster
authored andcommitted
reflog delete: narrow scope of "cmd" passed to count_reflog_ent()
Change the "cb_data" we pass to the count_reflog_ent() to be the &cb.cmd itself, instead of passing &cb and having the callback lookup cb->cmd. This makes it clear that the "cb" itself is the same memzero'd structure on each iteration of the for-loop that uses &cb, except for the "cmd" member. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 597af31 commit 4a0339b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

builtin/reflog.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -662,20 +662,18 @@ static int count_reflog_ent(struct object_id *ooid, struct object_id *noid,
662662
const char *email, timestamp_t timestamp, int tz,
663663
const char *message, void *cb_data)
664664
{
665-
struct expire_reflog_policy_cb *cb = cb_data;
666-
if (!cb->cmd.expire_total || timestamp < cb->cmd.expire_total)
667-
cb->cmd.recno++;
665+
struct cmd_reflog_expire_cb *cb = cb_data;
666+
if (!cb->expire_total || timestamp < cb->expire_total)
667+
cb->recno++;
668668
return 0;
669669
}
670670

671671
static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
672672
{
673-
struct expire_reflog_policy_cb cb;
673+
struct cmd_reflog_expire_cb cmd = { 0 };
674674
int i, status = 0;
675675
unsigned int flags = 0;
676676

677-
memset(&cb, 0, sizeof(cb));
678-
679677
for (i = 1; i < argc; i++) {
680678
const char *arg = argv[i];
681679
if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
@@ -703,6 +701,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
703701
const char *spec = strstr(argv[i], "@{");
704702
char *ep, *ref;
705703
int recno;
704+
struct expire_reflog_policy_cb cb = { 0 };
706705

707706
if (!spec) {
708707
status |= error(_("not a reflog: %s"), argv[i]);
@@ -716,14 +715,15 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
716715

717716
recno = strtoul(spec + 2, &ep, 10);
718717
if (*ep == '}') {
719-
cb.cmd.recno = -recno;
720-
for_each_reflog_ent(ref, count_reflog_ent, &cb);
718+
cmd.recno = -recno;
719+
for_each_reflog_ent(ref, count_reflog_ent, &cmd);
721720
} else {
722-
cb.cmd.expire_total = approxidate(spec + 2);
723-
for_each_reflog_ent(ref, count_reflog_ent, &cb);
724-
cb.cmd.expire_total = 0;
721+
cmd.expire_total = approxidate(spec + 2);
722+
for_each_reflog_ent(ref, count_reflog_ent, &cmd);
723+
cmd.expire_total = 0;
725724
}
726725

726+
cb.cmd = cmd;
727727
status |= reflog_expire(ref, flags,
728728
reflog_expiry_prepare,
729729
should_expire_reflog_ent,

0 commit comments

Comments
 (0)