git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Justin Tobler <jltobler@gmail.com>
Date
Jul 28, 2025, 15:59 UTC
Message-ID
<vo4s7oj3ypcfnjgky6zlt3zjgqlwqzorvsmac55uajugafnrde@yzb3c4kwbk77>
In-Reply-To
<20250728-pks-remote-rename-improvements-v1-1-f654f2b5c5ae@pks.im>
On 25/07/28 03:08PM, Patrick Steinhardt wrote:
Show 11 quoted lines
> With `refs_for_each_reflog_ent()` callers can iterate through all the
> reflog entries for a given reference. The callback that is being invoked
> for each such entry does not receive the name of the reference that we
> are currently iterating through. This isn't really a limiting factor, as
> callers can simply pass the name via the callback data.
> 
> But this layout sometimes does make for a bit of an awkward calling
> pattern. One example: when iterating through all reflogs, and for each
> reflog we iterate through all refnames, we have to do some extra book
> keeping to track which reference name we are currently yielding reflog
> entries for.

Making the reference name part of the callback signature seems reasonable here. For the above mentioned example, it will certainly simplify things quite a bit.

Show 27 quoted lines
> Change the signature of the callback function so that the reference name
> of the reflog gets passed through to it. Adapt callers accordingly and
> start using the new parameter in trivial cases. The next commit will
> refactor the reference migration logic to make use of this parameter so
> that we can simplify its logic a bit.
> 
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  builtin/fsck.c            |  9 ++++-----
>  builtin/gc.c              |  3 ++-
>  builtin/stash.c           |  6 ++++--
>  commit.c                  |  3 ++-
>  object-name.c             |  3 ++-
>  reflog-walk.c             |  7 ++++---
>  reflog.c                  |  3 ++-
>  reflog.h                  |  3 ++-
>  refs.c                    | 19 +++++++++----------
>  refs.h                    |  1 +
>  refs/debug.c              |  5 +++--
>  refs/files-backend.c      | 15 +++++++++------
>  refs/reftable-backend.c   |  2 +-
>  remote.c                  |  6 ++++--
>  revision.c                |  3 ++-
>  t/helper/test-ref-store.c |  3 ++-
>  wt-status.c               |  6 ++++--
>  17 files changed, 57 insertions(+), 40 deletions(-)
> 
[snip]
Show 9 quoted lines
> diff --git a/refs.h b/refs.h
> index 99b58d0b73c..a39f873b1fe 100644
> --- a/refs.h
> +++ b/refs.h
> @@ -559,6 +559,7 @@ int refs_delete_reflog(struct ref_store *refs, const char *refname);
>   * functions.
>   */
>  typedef int each_reflog_ent_fn(
> +		const char *refname,

The callback function now propagates the reference name and each reference backend is updated accordingly. This patch looks good.

Show 100 quoted lines
>  		struct object_id *old_oid, struct object_id *new_oid,
>  		const char *committer, timestamp_t timestamp,
>  		int tz, const char *msg, void *cb_data);
> diff --git a/refs/debug.c b/refs/debug.c
> index 485e3079d7a..5e113db307a 100644
> --- a/refs/debug.c
> +++ b/refs/debug.c
> @@ -276,7 +276,8 @@ struct debug_reflog {
>  	void *cb_data;
>  };
>  
> -static int debug_print_reflog_ent(struct object_id *old_oid,
> +static int debug_print_reflog_ent(const char *refname,
> +				  struct object_id *old_oid,
>  				  struct object_id *new_oid,
>  				  const char *committer, timestamp_t timestamp,
>  				  int tz, const char *msg, void *cb_data)
> @@ -291,7 +292,7 @@ static int debug_print_reflog_ent(struct object_id *old_oid,
>  	if (new_oid)
>  		oid_to_hex_r(n, new_oid);
>  
> -	ret = dbg->fn(old_oid, new_oid, committer, timestamp, tz, msg,
> +	ret = dbg->fn(refname, old_oid, new_oid, committer, timestamp, tz, msg,
>  		      dbg->cb_data);
>  	trace_printf_key(&trace_refs,
>  			 "reflog_ent %s (ret %d): %s -> %s, %s %ld \"%.*s\"\n",
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index 3ebe0323d4e..24d0a8ebde0 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -2109,7 +2109,9 @@ static int files_delete_reflog(struct ref_store *ref_store,
>  	return ret;
>  }
>  
> -static int show_one_reflog_ent(struct files_ref_store *refs, struct strbuf *sb,
> +static int show_one_reflog_ent(struct files_ref_store *refs,
> +			       const char *refname,
> +			       struct strbuf *sb,
>  			       each_reflog_ent_fn fn, void *cb_data)
>  {
>  	struct object_id ooid, noid;
> @@ -2136,7 +2138,7 @@ static int show_one_reflog_ent(struct files_ref_store *refs, struct strbuf *sb,
>  		message += 6;
>  	else
>  		message += 7;
> -	return fn(&ooid, &noid, p, timestamp, tz, message, cb_data);
> +	return fn(refname, &ooid, &noid, p, timestamp, tz, message, cb_data);
>  }
>  
>  static char *find_beginning_of_line(char *bob, char *scan)
> @@ -2220,7 +2222,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
>  				strbuf_splice(&sb, 0, 0, bp + 1, endp - (bp + 1));
>  				scanp = bp;
>  				endp = bp + 1;
> -				ret = show_one_reflog_ent(refs, &sb, fn, cb_data);
> +				ret = show_one_reflog_ent(refs, refname, &sb, fn, cb_data);
>  				strbuf_reset(&sb);
>  				if (ret)
>  					break;
> @@ -2232,7 +2234,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
>  				 * Process it, and we can end the loop.
>  				 */
>  				strbuf_splice(&sb, 0, 0, buf, endp - buf);
> -				ret = show_one_reflog_ent(refs, &sb, fn, cb_data);
> +				ret = show_one_reflog_ent(refs, refname, &sb, fn, cb_data);
>  				strbuf_reset(&sb);
>  				break;
>  			}
> @@ -2282,7 +2284,7 @@ static int files_for_each_reflog_ent(struct ref_store *ref_store,
>  		return -1;
>  
>  	while (!ret && !strbuf_getwholeline(&sb, logfp, '\n'))
> -		ret = show_one_reflog_ent(refs, &sb, fn, cb_data);
> +		ret = show_one_reflog_ent(refs, refname, &sb, fn, cb_data);
>  	fclose(logfp);
>  	strbuf_release(&sb);
>  	return ret;
> @@ -3323,7 +3325,8 @@ struct expire_reflog_cb {
>  		     dry_run:1;
>  };
>  
> -static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
> +static int expire_reflog_ent(const char *refname UNUSED,
> +			     struct object_id *ooid, struct object_id *noid,
>  			     const char *email, timestamp_t timestamp, int tz,
>  			     const char *message, void *cb_data)
>  {
> diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> index 99fafd75ebe..25a1d516184 100644
> --- a/refs/reftable-backend.c
> +++ b/refs/reftable-backend.c
> @@ -2148,7 +2148,7 @@ static int yield_log_record(struct reftable_ref_store *refs,
>  
>  	full_committer = fmt_ident(log->value.update.name, log->value.update.email,
>  				   WANT_COMMITTER_IDENT, NULL, IDENT_NO_DATE);
> -	return fn(&old_oid, &new_oid, full_committer,
> +	return fn(log->refname, &old_oid, &new_oid, full_committer,
>  		  log->value.update.time, log->value.update.tz_offset,
>  		  log->value.update.message, cb_data);
>  }
Previous: Patrick SteinhardtNext: Junio C Hamano
Message 3 of 37 in “builtin/remote: rework how remote refs get renamed”
  1. 0/4 builtin/remote: rework how remote refs get renamedPatrick Steinhardt, Jul 28, 2025
  2. 1/4 refs: pass refname when invoking reflog entry callbackPatrick Steinhardt, Jul 28, 2025
  3. Justin ToblerJul 28, 2025
  4. Junio C HamanoJul 28, 2025
  5. Karthik NayakJul 29, 2025
  6. Patrick SteinhardtJul 31, 2025
  7. 2/4 refs: simplify logic when migrating reflog entriesPatrick Steinhardt, Jul 28, 2025
  8. Justin ToblerJul 28, 2025
  9. Junio C HamanoJul 28, 2025
  10. 3/4 builtin/remote: rework how remote refs get renamedPatrick Steinhardt, Jul 28, 2025
  11. Junio C HamanoJul 28, 2025
  12. Patrick SteinhardtJul 29, 2025
  13. Justin ToblerJul 28, 2025
  14. Junio C HamanoJul 28, 2025
  15. Patrick SteinhardtJul 29, 2025
  16. Jeff KingJul 29, 2025
  17. Patrick SteinhardtJul 29, 2025
  18. Jeff KingAug 2, 2025
  19. 4/4 builtin/remote: only iterate through refs that are to be renamedPatrick Steinhardt, Jul 28, 2025
  20. Junio C HamanoJul 28, 2025
  21. Karthik NayakJul 30, 2025
  22. Patrick SteinhardtJul 31, 2025
  23. Junio C HamanoJul 28, 2025
  24. 0/6 builtin/remote: rework how remote refs get renamedPatrick Steinhardt, Jul 31, 2025
  25. 1/6 refs: pass refname when invoking reflog entry callbackPatrick Steinhardt, Jul 31, 2025
  26. 2/6 refs: simplify logic when migrating reflog entriesPatrick Steinhardt, Jul 31, 2025
  27. 3/6 builtin/remote: fix sign comparison warningsPatrick Steinhardt, Jul 31, 2025
  28. 4/6 builtin/remote: determine whether refs need renaming early onPatrick Steinhardt, Jul 31, 2025
  29. 5/6 builtin/remote: rework how remote refs get renamedPatrick Steinhardt, Jul 31, 2025
  30. Jeff KingAug 2, 2025
  31. Patrick SteinhardtAug 4, 2025
  32. 6/6 builtin/remote: only iterate through refs that are to be renamedPatrick Steinhardt, Jul 31, 2025
  33. Junio C HamanoJul 31, 2025
  34. Patrick SteinhardtAug 1, 2025
  35. Junio C HamanoAug 1, 2025
  36. Patrick SteinhardtAug 4, 2025
  37. Junio C HamanoAug 4, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.