All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "D. Ben Knoble" <ben.knoble@gmail.com>,
	Harald Nordgren <haraldnordgren@gmail.com>,
	Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v2 1/2] remote: move "simple" @{push} resolution into a helper
Date: Sat, 31 Oct 2026 08:04:00 +0000	[thread overview]
Message-ID: <151fef69b9ec221b39fdbab1d46f0b123f9079e4.1793433841.git.gitgitgadget@gmail.com> (raw)
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


  reply	other threads:[~2026-10-31  8:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 12:43 [PATCH] remote: resolve "simple" @{push} when pushing to another remote Harald Nordgren via GitGitGadget
2026-10-28 22:24 ` D. Ben Knoble
2026-10-29 10:34   ` Harald Nordgren
2026-10-29 17:48   ` Junio C Hamano
2026-10-29 22:15     ` Harald Nordgren
2026-10-31  8:03 ` [PATCH v2 0/2] " Harald Nordgren via GitGitGadget
2026-10-31  8:04   ` Harald Nordgren via GitGitGadget [this message]
2026-10-31  8:04   ` [PATCH v2 2/2] " Harald Nordgren via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=151fef69b9ec221b39fdbab1d46f0b123f9079e4.1793433841.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=ben.knoble@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=haraldnordgren@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.