Skip to content

Commit

Permalink
remote.c: hoist branch.*.remote lookup out of remote_get_1
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed May 21, 2015
1 parent 9e3751d commit f052154
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
21 changes: 14 additions & 7 deletions remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down

0 comments on commit f052154

Please sign in to comment.