Subject: Re: [PATCH v3 1/5] refs: add struct repository parameter to branchname helpers

From: Patrick Steinhardt <[email-masked]>
Date: Thu, 2 Apr 2026 09:27:33 +0200

On Sun, Mar 29, 2026 at 03:46:39PM +0530, Shreyansh Paliwal wrote:
> diff --git a/refs.c b/refs.c
> index 685a0c247b..5cdc8858c5 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -758,10 +758,10 @@ void copy_branchname(struct strbuf *sb, const char *name,
>  	strbuf_add(sb, name + used, len - used);
>  }
>  
> -int check_branch_ref(struct strbuf *sb, const char *name)
> +int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)
>  {
>  	if (startup_info->have_repository)
> -		copy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
> +		copy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);
>  	else
>  		strbuf_addstr(sb, name);
>  

I have to agree with Tian's comment on v2, this part here looks wrong. I
don't think we should depend on `startup_info` here, but we should
exclusively rely on whether or not the caller has passed in a
repository. And that will likely require a bit more scrutiny to figure
out whether there are any callers that shouldn't pass in a repository
because it's not initialized.

Alternatively, we could go with Tian's suggestion of checking for `repo
&& repo->gitdir`.

Patrick