summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-05-21 04:45:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-05-21 18:03:49 (GMT)
commitf052154db332e48ea35b1a0d783361a40a361250 (patch)
tree142d8071a45e5c69bb3deae603a1443a3e8717b9 /remote.c
parent9e3751d4437b43e72497178774c74be1ceac28b9 (diff)
downloadgit-f052154db332e48ea35b1a0d783361a40a361250.zip
git-f052154db332e48ea35b1a0d783361a40a361250.tar.gz
git-f052154db332e48ea35b1a0d783361a40a361250.tar.bz2
remote.c: hoist branch.*.remote lookup out of remote_get_1
We'll want to use this logic as a fallback when looking up the pushremote, so let's pull it out into its own function. We don't technically need to make this available outside of remote.c, but doing so will provide a consistent API with pushremote_for_branch, which we will add later. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/remote.c b/remote.c
index c298a43..0d2976b 100644
--- a/remote.c
+++ b/remote.c
@@ -692,6 +692,18 @@ static int valid_remote_nick(const char *name)
return !strchr(name, '/'); /* no slash */
}
+const char *remote_for_branch(struct branch *branch, int *explicit)
+{
+ if (branch && branch->remote_name) {
+ if (explicit)
+ *explicit = 1;
+ return branch->remote_name;
+ }
+ if (explicit)
+ *explicit = 0;
+ return "origin";
+}
+
static struct remote *remote_get_1(const char *name, const char *pushremote_name)
{
struct remote *ret;
@@ -703,13 +715,8 @@ static struct remote *remote_get_1(const char *name, const char *pushremote_name
if (pushremote_name) {
name = pushremote_name;
name_given = 1;
- } else {
- if (current_branch && current_branch->remote_name) {
- name = current_branch->remote_name;
- name_given = 1;
- } else
- name = "origin";
- }
+ } else
+ name = remote_for_branch(current_branch, &name_given);
}
ret = make_remote(name, 0);