Thread (7 messages) 7 messages, 3 authors, 2026-02-08

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

From: Junio C Hamano <hidden>
Date: 2026-01-22 20:37:20

Possibly related (same subject, not in this thread)

"Harald Nordgren via GitGitGadget" [off-list ref] writes:
quoted hunk
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"?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help