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>
Jeff King committed
May 21, 2015 at 00:45 UTC
f052154db332e48ea35b1a0d783361a40a361250
2 files changed
+15
-7
remote.c
+14
-7
@@ -692,6 +692,18 @@ static int valid_remote_nick(const char *name)
692
return !strchr(name, '/'); /* no slash */
693
}
694
695
+const char *remote_for_branch(struct branch *branch, int *explicit)
696
+{
697
+ if (branch && branch->remote_name) {
698
+ if (explicit)
699
+ *explicit = 1;
700
+ return branch->remote_name;
701
+ }
702
+ if (explicit)
703
+ *explicit = 0;
704
+ return "origin";
705
+}
706
+
707
static struct remote *remote_get_1(const char *name, const char *pushremote_name)
708
{
709
struct remote *ret;
@@ -703,13 +715,8 @@ static struct remote *remote_get_1(const char *name, const char *pushremote_name
715
if (pushremote_name) {
716
name = pushremote_name;
717
name_given = 1;
706
- } else {
707
- if (current_branch && current_branch->remote_name) {
708
- name = current_branch->remote_name;
709
- name_given = 1;
710
- } else
711
- name = "origin";
712
- }
718
+ } else
719
+ name = remote_for_branch(current_branch, &name_given);
720
}
721
722
ret = make_remote(name, 0);
remote.h
+1
@@ -211,6 +211,7 @@ struct branch {
211
};
212
213
struct branch *branch_get(const char *name);
214
+const char *remote_for_branch(struct branch *branch, int *explicit);
215
216
int branch_has_merge_config(struct branch *branch);
217
int branch_merge_matches(struct branch *, int n, const char *);