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 <artagnon@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed Apr 2, 2013 at 13:10 UTC f24f715e05399cba19cb9455fdd7d8a9806fe61b
3 files changed +23 -5
builtin/push.c
+1 -1
@@ -322,7 +322,7 @@ static int push_with_options(struct transport *transport, int flags)
322 static int do_push(const char *repo, int flags)
323 {
324 int i, errs;
325 - struct remote *remote = remote_get(repo);
325 + struct remote *remote = pushremote_get(repo);
326 const char **url;
327 int url_nr;
328
remote.c
+21 -4
@@ -49,6 +49,7 @@ static int branches_nr;
49
50 static struct branch *current_branch;
51 static const char *default_remote_name;
52 +static const char *pushremote_name;
53 static int explicit_default_remote_name;
54
55 static struct rewrites rewrites;
@@ -670,17 +671,21 @@ static int valid_remote_nick(const char *name)
671 return !strchr(name, '/'); /* no slash */
672 }
673
673 -struct remote *remote_get(const char *name)
674 +static struct remote *remote_get_1(const char *name, const char *pushremote_name)
675 {
676 struct remote *ret;
677 int name_given = 0;
678
678 - read_config();
679 if (name)
680 name_given = 1;
681 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 + }
689 }
690
691 ret = make_remote(name, 0);
@@ -699,6 +704,18 @@ struct remote *remote_get(const char *name)
704 return ret;
705 }
706
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 +
719 int remote_is_configured(const char *name)
720 {
721 int i;
remote.h
+1
@@ -51,6 +51,7 @@ struct remote {
51 };
52
53 struct remote *remote_get(const char *name);
54 +struct remote *pushremote_get(const char *name);
55 int remote_is_configured(const char *name);
56
57 typedef int each_remote_fn(struct remote *remote, void *priv);