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

Re: [PATCH 3/4] builtin/remote: rework how remote refs get renamed

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 29, 2025, 08:43 UTC
Message-ID
<aIiJsdPrGrhZYis5@pks.im>
In-Reply-To
<xmqqbjp4w7uu.fsf@gitster.g>
On Mon, Jul 28, 2025 at 10:19:53AM -0700, Junio C Hamano wrote:
Show 5 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > But more importantly it is also extremely inperformant. The number of
> 
> Is "inperformant" a real word?  "it performs extremely poorly"?

Well, in my head it is :) But it doesn't seem to exist anywhere else, so I'll reword this.

Show 14 quoted lines
> > +static void renamed_refname(struct rename_info *rename,
> > +			    const char *refname,
> > +			    struct strbuf *out)
> > +{
> > +	strbuf_reset(out);
> > +	strbuf_addstr(out, refname);
> > +	strbuf_splice(out, strlen("refs/remotes/"), strlen(rename->old_name),
> > +		      rename->new_name, strlen(rename->new_name));
> > +}
> > +
> 
> The function name felt somewhat iffy (sounded as if you are letting
> a third-party know that you have renamed a ref), but I cannot come
> up with a better alternative X-<.

We could name it `compute_renamed_refname()` to make it a bit more verb-y.

Show 12 quoted lines
> > +static int rename_one_reflog_entry(const char *old_refname UNUSED,
> > +				   struct object_id *old_oid,
> > +				   struct object_id *new_oid,
> > +				   const char *committer,
> > +				   timestamp_t timestamp, int tz,
> > +				   const char *msg, void *cb_data)
> >  {
> >  	struct rename_info *rename = cb_data;
> 
> Using a name of a system call for an unrelated variable, even if a
> local one in a function scope, makes me nauseous.  Not a new problem
> introduced by this change, though.
Yeah, I don't love it, either.
Show 33 quoted lines
> > +static int rename_one_reflog(const char *old_refname,
> > +			     const struct object_id *old_oid,
> > +			     struct rename_info *rename)
> > +{
> > +	struct strbuf *message = rename->buf1;
> 
> As these temporary strbuf's passed around as part of the rename_info
> structure are never released or recreated during the run, this is
> safe, but feels dirty, because we saw rename_one_reflog_entry() uses
> this exact one for totally different purpose.  Perhaps it would make
> it easier to follow if you left "message" uninitialized here, before
> refs_for_each_reflog_ent() returns.  And then ...
> 
> > +	int error;
> > +
> > +	if (!refs_reflog_exists(get_main_ref_store(the_repository), old_refname))
> > +		return 0;
> > +
> > +	error = refs_for_each_reflog_ent(get_main_ref_store(the_repository),
> > +					 old_refname, rename_one_reflog_entry, rename);
> > +	if (error < 0)
> > +		return error;
> > +
> > +	/*
> > +	 * Manually write the reflog entry for the now-renamed ref. We cannot
> > +	 * rely on `rename_one_ref()` to do this for us as that would screw
> > +	 * over order in which reflog entries are being written.
> > +	 *
> > +	 * Furthermore, we only append the entry in case the reference
> > +	 * resolves. Missing references shouldn't have reflogs anyway.
> > +	 */
> 
> ... give the "message" synonym to rename->buf1 here.

I was quite on the edge whether these buffers are really worth it in the first place as an optimization -- I mostly adopted it from the migration code. But I've benchmarked it now and couldn't really make out much of a difference at all. So let's just drop all of this buffer reusing infra.

Show 34 quoted lines
> > +static int rename_one_ref(const char *old_refname, const char *referent,
> > +			  const struct object_id *oid,
> > +			  int flags, void *cb_data)
> > +{
> > +	struct rename_info *rename = cb_data;
> > +	struct strbuf *new_referent = rename->buf1;
> > +	const char *ptr = old_refname;
> > +	int error;
> > +
> > +	if (!skip_prefix(ptr, "refs/remotes/", &ptr) ||
> > +	    !skip_prefix(ptr, rename->old_name, &ptr) ||
> > +	    !skip_prefix(ptr, "/", &ptr)) {
> > +		error = 0;
> > +		goto out;
> >  	}
> > -	strbuf_release(&buf);
> >  
> > -	return 0;
> > +	renamed_refname(rename, old_refname, rename->new_refname);
> > +
> > +	if (flags & REF_ISSYMREF) {
> > +		/*
> > +		 * Stupidly enough `referent` is not pointing to the immediate
> > +		 * target of a symref, but it's the recursively resolved value.
> > +		 * So symrefs pointing to symrefs would be misresolved, and
> > +		 * unborn symrefs don't have any value for the `referent` at all.
> > +		 */
> > +		referent = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
> > +						   old_refname, RESOLVE_REF_NO_RECURSE,
> > +						   NULL, NULL);
> > +		renamed_refname(rename, referent, new_referent);
> > +		oid = NULL;
> 
> Yuck, but this cannot be helped, I guess X-<.

I dunno. I feel like this is something we should eventually fix. Currently this is misleading and basically useless.

#leftoverbits
Patrick
Previous: Junio C HamanoNext: Justin Tobler
Message 12 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.