builtin-push: also ask config for remote information
Now you can store your remote information in the config file like this: [remote.upstream] url = me@company.com:the-project push = master:iceballs [jc: fixed up to adjust a different fix for Push: lines earlier.] Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Apr 30, 2006 at 15:23 UTC
97d4df0b29d262df291985aed486e226b43132d0
1 file changed
+39
builtin-push.c
+39
@@ -115,6 +115,41 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])
115
return n;
116
}
117
118
+static const char **config_uri;
119
+static const char *config_repo;
120
+static int config_repo_len;
121
+static int config_current_uri;
122
+static int config_get_refspecs;
123
+
124
+static int get_remote_config(const char* key, const char* value)
125
+{
126
+ if (!strncmp(key, "remote.", 7) &&
127
+ !strncmp(key + 7, config_repo, config_repo_len)) {
128
+ if (!strcmp(key + 7 + config_repo_len, ".url")) {
129
+ if (config_current_uri < MAX_URI)
130
+ config_uri[config_current_uri++] = strdup(value);
131
+ else
132
+ error("more than %d URL's specified, ignoring the rest", MAX_URI);
133
+ }
134
+ else if (config_get_refspecs &&
135
+ !strcmp(key + 7 + config_repo_len, ".push"))
136
+ add_refspec(strdup(value));
137
+ }
138
+ return 0;
139
+}
140
+
141
+static int get_config_remotes_uri(const char *repo, const char *uri[MAX_URI])
142
+{
143
+ config_repo_len = strlen(repo);
144
+ config_repo = repo;
145
+ config_current_uri = 0;
146
+ config_uri = uri;
147
+ config_get_refspecs = !refspec_nr;
148
+
149
+ git_config(get_remote_config);
150
+ return config_current_uri;
151
+}
152
+
153
static int get_branches_uri(const char *repo, const char *uri[MAX_URI])
154
{
155
const char *slash = strchr(repo, '/');
@@ -162,6 +197,10 @@ static int read_config(const char *repo, const char *uri[MAX_URI])
197
if (n > 0)
198
return n;
199
200
+ n = get_config_remotes_uri(repo, uri);
201
+ if (n > 0)
202
+ return n;
203
+
204
n = get_branches_uri(repo, uri);
205
if (n > 0)
206
return n;