Skip to content

Commit f052154

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9e3751d commit f052154

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

remote.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,18 @@ static int valid_remote_nick(const char *name)
692692
return !strchr(name, '/'); /* no slash */
693693
}
694694

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+
695707
static struct remote *remote_get_1(const char *name, const char *pushremote_name)
696708
{
697709
struct remote *ret;
@@ -703,13 +715,8 @@ static struct remote *remote_get_1(const char *name, const char *pushremote_name
703715
if (pushremote_name) {
704716
name = pushremote_name;
705717
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);
713720
}
714721

715722
ret = make_remote(name, 0);

remote.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ struct branch {
211211
};
212212

213213
struct branch *branch_get(const char *name);
214+
const char *remote_for_branch(struct branch *branch, int *explicit);
214215

215216
int branch_has_merge_config(struct branch *branch);
216217
int branch_merge_matches(struct branch *, int n, const char *);

0 commit comments

Comments
 (0)