]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote.c: hoist branch.*.remote lookup out of remote_get_1
authorJeff King <peff@peff.net>
Thu, 21 May 2015 04:45:16 +0000 (00:45 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 May 2015 18:03:49 +0000 (11:03 -0700)
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>
remote.c
remote.h

index c298a43a1cb4e54858b99b4ee7d768935fabfa28..0d2976b36b8378b9143b616a27deea4647c37b73 100644 (file)
--- 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);
index 4bb667273575c038b4238dc14b1181cd07582b68..2a7e7a698b92afc722247be578a442f0b0f60bda 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -211,6 +211,7 @@ struct branch {
 };
 
 struct branch *branch_get(const char *name);
+const char *remote_for_branch(struct branch *branch, int *explicit);
 
 int branch_has_merge_config(struct branch *branch);
 int branch_merge_matches(struct branch *, int n, const char *);