Subject: Re: [PATCH 1/4] refs: pass refname when invoking reflog entry callback

From: Junio C Hamano <[email-masked]>
Date: Mon, 28 Jul 2025 09:07:44 -0700

Patrick Steinhardt <[email-masked]> writes:

> -static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noid,
> +static int fsck_handle_reflog_ent(const char *refname,
> +				  struct object_id *ooid, struct object_id *noid,
>  				  const char *email UNUSED,
>  				  timestamp_t timestamp, int tz UNUSED,
> -				  const char *message UNUSED, void *cb_data)
> +				  const char *message UNUSED, void *cb_data UNUSED)
>  {
> -	const char *refname = cb_data;
> -
>  	if (verbose)
>  		fprintf_ln(stderr, _("Checking reflog %s->%s"),
>  			   oid_to_hex(ooid), oid_to_hex(noid));
> @@ -525,7 +524,7 @@ static int fsck_handle_reflog(const char *logname, void *cb_data)
>  	strbuf_worktree_ref(cb_data, &refname, logname);
>  	refs_for_each_reflog_ent(get_main_ref_store(the_repository),
>  				 refname.buf, fsck_handle_reflog_ent,
> -				 refname.buf);
> +				 NULL);
>  	strbuf_release(&refname);
>  	return 0;
>  }

Nice.  There are a few callsites that passed refname as (a part of)
cb_data, like this one ...

> diff --git a/refs.c b/refs.c
> index 4bd80287054..fd9a5f36b20 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -1022,7 +1022,6 @@ int is_branch(const char *refname)
>  }
>  
>  struct read_ref_at_cb {
> -	const char *refname;
>  	timestamp_t at_time;
>  	int cnt;
>  	int reccnt;
> @@ -1052,7 +1051,8 @@ static void set_read_ref_cutoffs(struct read_ref_at_cb *cb,
>  		*cb->cutoff_cnt = cb->reccnt;
>  }
>  
> -static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
> +static int read_ref_at_ent(const char *refname,
> +			   struct object_id *ooid, struct object_id *noid,
>  			   const char *email UNUSED,
>  			   timestamp_t timestamp, int tz,
>  			   const char *message, void *cb_data)
> @@ -1072,13 +1072,13 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
>  			oidcpy(cb->oid, noid);
>  			if (!oideq(&cb->ooid, noid))
>  				warning(_("log for ref %s has gap after %s"),
> -					cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
> +					refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
>  		}

... that makes quite sense.