http-push: enable "proactive auth"

Before commit 986bbc08, git was proactive about asking for http passwords. It assumed that if you had a username in your URL, you would also want a password, and asked for it before making any http requests. However, this could interfere with the use of .netrc (see 986bbc08 for details). And it was also unnecessary, since the http fetching code had learned to recognize an HTTP 401 and prompt the user then. Furthermore, the proactive prompt could interfere with the usage of .netrc (see 986bbc08 for details). Unfortunately, the http push-over-DAV code never learned to recognize HTTP 401, and so was broken by this change. This patch does a quick fix of re-enabling the "proactive auth" strategy only for http-push, leaving the dumb http fetch and smart-http as-is. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Dec 13, 2011 at 19:11 UTC a4ddbc33d7906f0e10c68c140a9a1003d9715a77
6 files changed +13 -6
http-fetch.c
+1 -1
@@ -67,7 +67,7 @@ int main(int argc, const char **argv)
67
68 git_config(git_default_config, NULL);
69
70 - http_init(NULL, url);
70 + http_init(NULL, url, 0);
71 walker = get_http_walker(url);
72 walker->get_tree = get_tree;
73 walker->get_history = get_history;
http-push.c
+1 -1
@@ -1820,7 +1820,7 @@ int main(int argc, char **argv)
1820
1821 memset(remote_dir_exists, -1, 256);
1822
1823 - http_init(NULL, repo->url);
1823 + http_init(NULL, repo->url, 1);
1824
1825 #ifdef USE_CURL_MULTI
1826 is_running_queue = 0;
http.c
+7 -1
@@ -43,6 +43,7 @@ static int curl_ftp_no_epsv;
43 static const char *curl_http_proxy;
44 static const char *curl_cookie_file;
45 static char *user_name, *user_pass, *description;
46 +static int http_proactive_auth;
47 static const char *user_agent;
48
49 #if LIBCURL_VERSION_NUM >= 0x071700
@@ -279,6 +280,9 @@ static CURL *get_curl_handle(void)
280 curl_easy_setopt(result, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
281 #endif
282
283 + if (http_proactive_auth)
284 + init_curl_http_auth(result);
285 +
286 if (ssl_cert != NULL)
287 curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);
288 if (has_cert_password())
@@ -367,7 +371,7 @@ static void set_from_env(const char **var, const char *envname)
371 *var = val;
372 }
373
370 -void http_init(struct remote *remote, const char *url)
374 +void http_init(struct remote *remote, const char *url, int proactive_auth)
375 {
376 char *low_speed_limit;
377 char *low_speed_time;
@@ -378,6 +382,8 @@ void http_init(struct remote *remote, const char *url)
382
383 curl_global_init(CURL_GLOBAL_ALL);
384
385 + http_proactive_auth = proactive_auth;
386 +
387 if (remote && remote->http_proxy)
388 curl_http_proxy = xstrdup(remote->http_proxy);
389
http.h
+2 -1
@@ -86,7 +86,8 @@ 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, const char *url);
89 +extern void http_init(struct remote *remote, const char *url,
90 + int proactive_auth);
91 extern void http_cleanup(void);
92
93 extern int data_received;
remote-curl.c
+1 -1
@@ -859,7 +859,7 @@ int main(int argc, const char **argv)
859
860 url = strbuf_detach(&buf, NULL);
861
862 - http_init(remote, url);
862 + http_init(remote, url, 0);
863
864 do {
865 if (strbuf_getline(&buf, stdin, '\n') == EOF) {
t/t5540-http-push.sh
+1 -1
@@ -160,7 +160,7 @@ test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
160 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
161 "$ROOT_PATH"/test_repo_clone master
162
163 -test_expect_failure 'push to password-protected repository (user in URL)' '
163 +test_expect_success 'push to password-protected repository (user in URL)' '
164 test_commit pw-user &&
165 git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
166 git rev-parse --verify HEAD >expect &&