Skip to content

Commit f24f715

Browse files
artagnongitster
authored andcommitted
remote.c: introduce a way to have different remotes for fetch/push
Currently, do_push() in push.c calls remote_get(), which gets the configured remote for fetching and pushing. Replace this call with a call to pushremote_get() instead, a new function that will return the remote configured specifically for pushing. This function tries to work with the string pushremote_name, before falling back to the codepath of remote_get(). This patch has no visible impact, but serves to enable future patches to introduce configuration variables to set pushremote_name. For example, you can now do the following in handle_config(): if (!strcmp(key, "remote.pushdefault")) git_config_string(&pushremote_name, key, value); Then, pushes will automatically go to the remote specified by remote.pushdefault. Signed-off-by: Ramkumar Ramachandra <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2e433b7 commit f24f715

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

builtin/push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static int push_with_options(struct transport *transport, int flags)
322322
static int do_push(const char *repo, int flags)
323323
{
324324
int i, errs;
325-
struct remote *remote = remote_get(repo);
325+
struct remote *remote = pushremote_get(repo);
326326
const char **url;
327327
int url_nr;
328328

remote.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static int branches_nr;
4949

5050
static struct branch *current_branch;
5151
static const char *default_remote_name;
52+
static const char *pushremote_name;
5253
static int explicit_default_remote_name;
5354

5455
static struct rewrites rewrites;
@@ -670,17 +671,21 @@ static int valid_remote_nick(const char *name)
670671
return !strchr(name, '/'); /* no slash */
671672
}
672673

673-
struct remote *remote_get(const char *name)
674+
static struct remote *remote_get_1(const char *name, const char *pushremote_name)
674675
{
675676
struct remote *ret;
676677
int name_given = 0;
677678

678-
read_config();
679679
if (name)
680680
name_given = 1;
681681
else {
682-
name = default_remote_name;
683-
name_given = explicit_default_remote_name;
682+
if (pushremote_name) {
683+
name = pushremote_name;
684+
name_given = 1;
685+
} else {
686+
name = default_remote_name;
687+
name_given = explicit_default_remote_name;
688+
}
684689
}
685690

686691
ret = make_remote(name, 0);
@@ -699,6 +704,18 @@ struct remote *remote_get(const char *name)
699704
return ret;
700705
}
701706

707+
struct remote *remote_get(const char *name)
708+
{
709+
read_config();
710+
return remote_get_1(name, NULL);
711+
}
712+
713+
struct remote *pushremote_get(const char *name)
714+
{
715+
read_config();
716+
return remote_get_1(name, pushremote_name);
717+
}
718+
702719
int remote_is_configured(const char *name)
703720
{
704721
int i;

remote.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct remote {
5151
};
5252

5353
struct remote *remote_get(const char *name);
54+
struct remote *pushremote_get(const char *name);
5455
int remote_is_configured(const char *name);
5556

5657
typedef int each_remote_fn(struct remote *remote, void *priv);

0 commit comments

Comments
 (0)