http_init: accept separate URL parameter

The http_init function takes a "struct remote". Part of its initialization procedure is to look at the remote's url and grab some auth-related parameters. However, using the url included in the remote is: - wrong; the remote-curl helper may have a separate, unrelated URL (e.g., from remote.*.pushurl). Looking at the remote's configured url is incorrect. - incomplete; http-fetch doesn't have a remote, so passes NULL. So http_init never gets to see the URL we are actually going to use. - cumbersome; http-push has a similar problem to http-fetch, but actually builds a fake remote just to pass in the URL. Instead, let's just add a separate URL parameter to http_init, and all three callsites can pass in the appropriate information. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 14, 2011 at 09:40 UTC deba49377b717d1e26c342f65c7f5e75a2db8641
5 files changed +8 -16
http-fetch.c
+1 -1
@@ -63,7 +63,7 @@ int main(int argc, const char **argv)
63
64 git_config(git_default_config, NULL);
65
66 - http_init(NULL);
66 + http_init(NULL, url);
67 walker = get_http_walker(url);
68 walker->get_tree = get_tree;
69 walker->get_history = get_history;
http-push.c
+1 -9
@@ -1747,7 +1747,6 @@ int main(int argc, char **argv)
1747 int i;
1748 int new_refs;
1749 struct ref *ref, *local_refs;
1750 - struct remote *remote;
1750
1751 git_extract_argv0_path(argv[0]);
1752
@@ -1821,14 +1820,7 @@ int main(int argc, char **argv)
1820
1821 memset(remote_dir_exists, -1, 256);
1822
1824 - /*
1825 - * Create a minimum remote by hand to give to http_init(),
1826 - * primarily to allow it to look at the URL.
1827 - */
1828 - remote = xcalloc(sizeof(*remote), 1);
1829 - ALLOC_GROW(remote->url, remote->url_nr + 1, remote->url_alloc);
1830 - remote->url[remote->url_nr++] = repo->url;
1831 - http_init(remote);
1823 + http_init(NULL, repo->url);
1824
1825 #ifdef USE_CURL_MULTI
1826 is_running_queue = 0;
http.c
+4 -4
@@ -369,7 +369,7 @@ static void set_from_env(const char **var, const char *envname)
369 *var = val;
370 }
371
372 -void http_init(struct remote *remote)
372 +void http_init(struct remote *remote, const char *url)
373 {
374 char *low_speed_limit;
375 char *low_speed_time;
@@ -433,11 +433,11 @@ void http_init(struct remote *remote)
433 if (getenv("GIT_CURL_FTP_NO_EPSV"))
434 curl_ftp_no_epsv = 1;
435
436 - if (remote && remote->url && remote->url[0]) {
437 - http_auth_init(remote->url[0]);
436 + if (url) {
437 + http_auth_init(url);
438 if (!ssl_cert_password_required &&
439 getenv("GIT_SSL_CERT_PASSWORD_PROTECTED") &&
440 - !prefixcmp(remote->url[0], "https://"))
440 + !prefixcmp(url, "https://"))
441 ssl_cert_password_required = 1;
442 }
443
http.h
+1 -1
@@ -86,7 +86,7 @@ extern void add_fill_function(void *data, int (*fill)(void *));
86 extern void step_active_slots(void);
87 #endif
88
89 -extern void http_init(struct remote *remote);
89 +extern void http_init(struct remote *remote, const char *url);
90 extern void http_cleanup(void);
91
92 extern int data_received;
remote-curl.c
+1 -1
@@ -850,7 +850,7 @@ int main(int argc, const char **argv)
850
851 url = strbuf_detach(&buf, NULL);
852
853 - http_init(remote);
853 + http_init(remote, url);
854
855 do {
856 if (strbuf_getline(&buf, stdin, '\n') == EOF)