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

[PATCH v2 1/2] remote: move "simple" @{push} resolution into a helper

From
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 31, 2026, 08:04 UTC
Message-ID
<151fef69b9ec221b39fdbab1d46f0b123f9079e4.1793433841.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2466.v2.git.git.1793433841.gitgitgadget@gmail.com>
From: Harald Nordgren <haraldnordgren@gmail.com>

The "simple" arm is the longest in the switch of branch_get_push_1() and needs an extra block to declare its variables. Give it its own function so that it reads at one level of indentation and the next commit can teach it about pushing to another remote without nesting it further.

No functional change.
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 remote.c | 40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)
diff --git a/remote.c b/remote.c
index 49ee2ea318..d15d34aad7 100644
--- a/remote.c
+++ b/remote.c
@@ -1967,6 +1967,28 @@ static char *tracking_for_push_dest(struct repository *repo,
 	return ret;
 }
 
+static char *branch_get_push_simple(struct repository *repo,
+				    struct remote *remote,
+				    struct branch *branch,
+				    struct strbuf *err)
+{
+	const char *up;
+	char *cur;
+
+	up = branch_get_upstream(branch, err);
+	if (!up)
+		return NULL;
+	cur = tracking_for_push_dest(repo, remote, branch->refname, err);
+	if (!cur)
+		return NULL;
+	if (strcmp(cur, up)) {
+		free(cur);
+		return error_buf(err,
+				 _("cannot resolve 'simple' push to a single destination"));
+	}
+	return cur;
+}
+
 static char *branch_get_push_1(struct repository *repo,
 			       struct branch *branch, struct strbuf *err)
 {
@@ -2012,23 +2034,7 @@ static char *branch_get_push_1(struct repository *repo,
 
 	case PUSH_DEFAULT_UNSPECIFIED:
 	case PUSH_DEFAULT_SIMPLE:
-		{
-			const char *up;
-			char *cur;
-
-			up = branch_get_upstream(branch, err);
-			if (!up)
-				return NULL;
-			cur = tracking_for_push_dest(repo, remote, branch->refname, err);
-			if (!cur)
-				return NULL;
-			if (strcmp(cur, up)) {
-				free(cur);
-				return error_buf(err,
-						 _("cannot resolve 'simple' push to a single destination"));
-			}
-			return cur;
-		}
+		return branch_get_push_simple(repo, remote, branch, err);
 	}
 
 	BUG("unhandled push situation");
-- 
gitgitgadget
Previous: Harald Nordgren via GitGitGadgetNext: Harald Nordgren via GitGitGadget
Message 7 of 8 in “remote: resolve "simple" @{push} when pushing to another remote”
  1. remote: resolve "simple" @{push} when pushing to another remoteHarald Nordgren via GitGitGadget, Oct 27, 2026
  2. D. Ben KnobleOct 28, 2026
  3. Harald NordgrenOct 29, 2026
  4. Junio C HamanoOct 29, 2026
  5. Harald NordgrenOct 29, 2026
  6. 0/2 remote: resolve "simple" @{push} when pushing to another remoteHarald Nordgren via GitGitGadget, Oct 31, 2026
  7. 1/2 remote: move "simple" @{push} resolution into a helperHarald Nordgren via GitGitGadget, Oct 31, 2026
  8. 2/2 remote: resolve "simple" @{push} when pushing to another remoteHarald Nordgren via GitGitGadget, Oct 31, 2026

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.