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

[PATCH 3/3] remote: introduce and fill branch->pushremote

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Jan 12, 2014, 17:11 UTC
Message-ID
<1389546666-17438-4-git-send-email-artagnon@gmail.com>
In-Reply-To
<1389546666-17438-1-git-send-email-artagnon@gmail.com>

When a caller uses branch_get() to retrieve a "struct branch", they get the per-branch remote name and a pointer to the remote struct. However, they have no way of knowing about the per-branch pushremote from this interface. So, let's expose that information via fields similar to "remote" and "remote_name"; "pushremote" and "pushremote_name".

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 remote.c | 15 ++++++++++++---
 remote.h |  3 +++
 2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/remote.c b/remote.c
index a89efab..286cdce 100644
--- a/remote.c
+++ b/remote.c
@@ -351,9 +351,10 @@ static int handle_config(const char *key, const char *value, void *cb)
 				explicit_default_remote_name = 1;
 			}
 		} else if (!strcmp(subkey, ".pushremote")) {
+			if (git_config_string(&branch->pushremote_name, key, value))
+				return -1;
 			if (branch == current_branch)
-				if (git_config_string(&pushremote_name, key, value))
-					return -1;
+				pushremote_name = branch->pushremote_name;
 		} else if (!strcmp(subkey, ".merge")) {
 			if (!value)
 				return config_error_nonbool(key);
@@ -1543,7 +1544,9 @@ struct branch *branch_get(const char *name)
 		ret = current_branch;
 	else
 		ret = make_branch(name, 0);
-	if (ret && ret->remote_name) {
+	if (!ret)
+		return ret;
+	if (ret->remote_name) {
 		ret->remote = remote_get(ret->remote_name);
 		if (ret->merge_nr) {
 			int i;
@@ -1557,6 +1560,12 @@ struct branch *branch_get(const char *name)
 			}
 		}
 	}
+	if (ret->pushremote_name)
+		ret->pushremote = remote_get(ret->pushremote_name);
+	else if (pushremote_name)
+		ret->pushremote = remote_get(pushremote_name);
+	else
+		ret->pushremote = ret->remote;
 	return ret;
 }
 
diff --git a/remote.h b/remote.h
index 00c6a76..ac5aadc 100644
--- a/remote.h
+++ b/remote.h
@@ -201,6 +201,9 @@ struct branch {
 	const char *remote_name;
 	struct remote *remote;
 
+	const char *pushremote_name;
+	struct remote *pushremote;
+
 	const char **merge_name;
 	struct refspec **merge;
 	int merge_nr;
-- 
1.8.5.2.313.g5abf4c0.dirty
Previous: Ramkumar RamachandraNext: Jeff King
Message 4 of 9 in “Minor preparation for @{publish}”
  1. 0/3 Minor preparation for @{publish}Ramkumar Ramachandra, Jan 12, 2014
  2. 1/3 t1507 (rev-parse-upstream): fix typo in test titleRamkumar Ramachandra, Jan 12, 2014
  3. 2/3 interpret_branch_name: factor out upstream handlingRamkumar Ramachandra, Jan 12, 2014
  4. 3/3 remote: introduce and fill branch->pushremoteRamkumar Ramachandra, Jan 12, 2014
  5. Jeff KingJan 13, 2014
  6. Ramkumar RamachandraJan 13, 2014
  7. Jeff KingJan 13, 2014
  8. Junio C HamanoJan 13, 2014
  9. Jeff KingJan 13, 2014

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.