Subject: Re: [PATCH v27 2/2] status: add status.compareBranches config for multiple branch comparisons

From: Junio C Hamano <[email-masked]>
Date: Thu, 22 Jan 2026 12:37:16 -0800

"Harald Nordgren via GitGitGadget" <[email-masked]> writes:

> diff --git a/remote.c b/remote.c
> index fd592ec659..e256cc9b81 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -29,6 +29,12 @@
>  
>  enum map_direction { FROM_SRC, FROM_DST };
>  
> +enum {
> +	ENABLE_ADVICE_PULL       = (1 << 0),
> +	ENABLE_ADVICE_PUSH       = (1 << 1),
> +	ENABLE_ADVICE_DIVERGENCE = (1 << 2),
> +};
> +
>  struct counted_string {
>  	size_t len;
>  	const char *s;
> @@ -2230,13 +2236,53 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
>  	return stat_branch_pair(branch->refname, base, num_ours, num_theirs, abf);
>  }
>  
> +static char *resolve_compare_branch(struct branch *branch, const char *name)
> +{
> +	struct strbuf buf = STRBUF_INIT;
> +	const char *resolved = NULL;
> +	char *ret;
> +
> +	if (!branch || !name)
> +		return NULL;
> +
> +	if (!strcasecmp(name, "@{upstream}") || !strcasecmp(name, "@{u}"))
> +		resolved = branch_get_upstream(branch, NULL);
> +	else if (!strcasecmp(name, "@{push}"))
> +		resolved = branch_get_push(branch, NULL);

OK.  Usually @{upstream} without anything before the at-sign means
the upstream of the current branch, but we need to force pretend
that branch were the current branch, so we'd need to special case
like this, which looks reasonable.

> +	if (resolved)
> +		return xstrdup(resolved);
> +
> +	strbuf_addf(&buf, "refs/remotes/%s", name);
> +	resolved = refs_resolve_ref_unsafe(
> +		get_main_ref_store(the_repository),
> +		buf.buf,
> +		RESOLVE_REF_READING,
> +		NULL, NULL);
> +	if (resolved) {
> +		ret = xstrdup(resolved);
> +		strbuf_release(&buf);
> +		return ret;
> +	}

It would be handy to be able to say "origin/master" (or even just
"origin", which is interpreted as "origin/HEAD" via the DWIM
machinery) and prepending of "refs/remotes/" above does help such
DWIMmery, but I wonder if it is too limiting?  Would there be
situations where you would want to compare with something outside
refs/remotes/ hierarchy?  

For example, writing "v2.52.0" there to see how far we came since
the last release would become impossible if we always force prepend
"refs/remotes/".  I wonder if we can reuse already existing DWIMmery
that uses refs.c::ref_rev_parse_rules[], which should allow such use
case, while still allowing you to write "origin/master"?