http: drop support for curl < 7.11.1

Drop support for this ancient version of curl and simplify the code by allowing us get rid of some "#ifdef"'s. Git will not build with vanilla curl older than 7.11.1 due our use of CURLOPT_POSTFIELDSIZE in 37ee680d9b (http.postbuffer: allow full range of ssize_t values, 2017-04-11). This field was introduced in curl 7.11.1. We could solve these compilation problems with more #ifdefs, but it's not worth the trouble. Version 7.11.1 came out in March of 2004, over 17 years ago. Let's declare that too old and drop any existing ifdefs that go further back. One obvious benefit is that we'll have fewer conditional bits cluttering the code. This patch drops all #ifdefs that reference older versions (note that curl's preprocessor macros are in hex, so we're looking for 070b01, not 071101). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 30, 2021 at 11:31 UTC 1119a15b5c8521e75c412a129cd6318285cac773
3 files changed +1 -67
http.c
-53
@@ -19,19 +19,11 @@
19 static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
20 static int trace_curl_data = 1;
21 static int trace_curl_redact = 1;
22 -#if LIBCURL_VERSION_NUM >= 0x070a08
22 long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER;
24 -#else
25 -long int git_curl_ipresolve;
26 -#endif
23 int active_requests;
24 int http_is_verbose;
25 ssize_t http_post_buffer = 16 * LARGE_PACKET_MAX;
26
31 -#if LIBCURL_VERSION_NUM >= 0x070a06
32 -#define LIBCURL_CAN_HANDLE_AUTH_ANY
33 -#endif
34 -
27 static int min_curl_sessions = 1;
28 static int curl_session_count;
29 #ifdef USE_CURL_MULTI
@@ -68,15 +60,9 @@ static struct {
60 { "tlsv1.3", CURL_SSLVERSION_TLSv1_3 },
61 #endif
62 };
71 -#if LIBCURL_VERSION_NUM >= 0x070903
63 static const char *ssl_key;
73 -#endif
74 -#if LIBCURL_VERSION_NUM >= 0x070908
64 static const char *ssl_capath;
76 -#endif
77 -#if LIBCURL_VERSION_NUM >= 0x071304
65 static const char *curl_no_proxy;
79 -#endif
66 #if LIBCURL_VERSION_NUM >= 0x072c00
67 static const char *ssl_pinnedkey;
68 #endif
@@ -101,9 +87,7 @@ static struct {
87 { "digest", CURLAUTH_DIGEST },
88 { "negotiate", CURLAUTH_GSSNEGOTIATE },
89 { "ntlm", CURLAUTH_NTLM },
104 -#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
90 { "anyauth", CURLAUTH_ANY },
106 -#endif
91 /*
92 * CURLAUTH_DIGEST_IE has no corresponding command-line option in
93 * curl(1) and is not included in CURLAUTH_ANY, so we leave it out
@@ -143,7 +127,6 @@ enum http_follow_config http_follow_config = HTTP_FOLLOW_INITIAL;
127
128 static struct credential cert_auth = CREDENTIAL_INIT;
129 static int ssl_cert_password_required;
146 -#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
130 static unsigned long http_auth_methods = CURLAUTH_ANY;
131 static int http_auth_methods_restricted;
132 /* Modes for which empty_auth cannot actually help us. */
@@ -153,7 +136,6 @@ static unsigned long empty_auth_useless =
136 | CURLAUTH_DIGEST_IE
137 #endif
138 | CURLAUTH_DIGEST;
156 -#endif
139
140 static struct curl_slist *pragma_header;
141 static struct curl_slist *no_pragma_header;
@@ -237,12 +219,8 @@ static void finish_active_slot(struct active_request_slot *slot)
219 if (slot->results != NULL) {
220 slot->results->curl_result = slot->curl_result;
221 slot->results->http_code = slot->http_code;
240 -#if LIBCURL_VERSION_NUM >= 0x070a08
222 curl_easy_getinfo(slot->curl, CURLINFO_HTTPAUTH_AVAIL,
223 &slot->results->auth_avail);
243 -#else
244 - slot->results->auth_avail = 0;
245 -#endif
224
225 curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CONNECTCODE,
226 &slot->results->http_connectcode);
@@ -305,14 +283,10 @@ static int http_options(const char *var, const char *value, void *cb)
283 return git_config_string(&ssl_version, var, value);
284 if (!strcmp("http.sslcert", var))
285 return git_config_pathname(&ssl_cert, var, value);
308 -#if LIBCURL_VERSION_NUM >= 0x070903
286 if (!strcmp("http.sslkey", var))
287 return git_config_pathname(&ssl_key, var, value);
311 -#endif
312 -#if LIBCURL_VERSION_NUM >= 0x070908
288 if (!strcmp("http.sslcapath", var))
289 return git_config_pathname(&ssl_capath, var, value);
315 -#endif
290 if (!strcmp("http.sslcainfo", var))
291 return git_config_pathname(&ssl_cainfo, var, value);
292 if (!strcmp("http.sslcertpasswordprotected", var)) {
@@ -461,12 +435,6 @@ static int curl_empty_auth_enabled(void)
435 if (curl_empty_auth >= 0)
436 return curl_empty_auth;
437
464 -#ifndef LIBCURL_CAN_HANDLE_AUTH_ANY
465 - /*
466 - * Our libcurl is too old to do AUTH_ANY in the first place;
467 - * just default to turning the feature off.
468 - */
469 -#else
438 /*
439 * In the automatic case, kick in the empty-auth
440 * hack as long as we would potentially try some
@@ -479,7 +447,6 @@ static int curl_empty_auth_enabled(void)
447 if (http_auth_methods_restricted &&
448 (http_auth_methods & ~empty_auth_useless))
449 return 1;
482 -#endif
450 return 0;
451 }
452
@@ -552,7 +519,6 @@ static void init_curl_proxy_auth(CURL *result)
519
520 var_override(&http_proxy_authmethod, getenv("GIT_HTTP_PROXY_AUTHMETHOD"));
521
555 -#if LIBCURL_VERSION_NUM >= 0x070a07 /* CURLOPT_PROXYAUTH and CURLAUTH_ANY */
522 if (http_proxy_authmethod) {
523 int i;
524 for (i = 0; i < ARRAY_SIZE(proxy_authmethods); i++) {
@@ -570,7 +536,6 @@ static void init_curl_proxy_auth(CURL *result)
536 }
537 else
538 curl_easy_setopt(result, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
573 -#endif
539 }
540
541 static int has_cert_password(void)
@@ -879,12 +844,8 @@ static CURL *get_curl_handle(void)
844 }
845 #endif
846
882 -#if LIBCURL_VERSION_NUM >= 0x070907
847 curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
884 -#endif
885 -#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
848 curl_easy_setopt(result, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
887 -#endif
849
850 #ifdef CURLGSSAPI_DELEGATION_FLAG
851 if (curl_deleg) {
@@ -940,14 +901,10 @@ static CURL *get_curl_handle(void)
901 curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);
902 if (has_cert_password())
903 curl_easy_setopt(result, CURLOPT_KEYPASSWD, cert_auth.password);
943 -#if LIBCURL_VERSION_NUM >= 0x070903
904 if (ssl_key != NULL)
905 curl_easy_setopt(result, CURLOPT_SSLKEY, ssl_key);
946 -#endif
947 -#if LIBCURL_VERSION_NUM >= 0x070908
906 if (ssl_capath != NULL)
907 curl_easy_setopt(result, CURLOPT_CAPATH, ssl_capath);
950 -#endif
908 #if LIBCURL_VERSION_NUM >= 0x072c00
909 if (ssl_pinnedkey != NULL)
910 curl_easy_setopt(result, CURLOPT_PINNEDPUBLICKEY, ssl_pinnedkey);
@@ -1180,12 +1137,8 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
1137 curl_ssl_verify = 0;
1138
1139 set_from_env(&ssl_cert, "GIT_SSL_CERT");
1183 -#if LIBCURL_VERSION_NUM >= 0x070903
1140 set_from_env(&ssl_key, "GIT_SSL_KEY");
1185 -#endif
1186 -#if LIBCURL_VERSION_NUM >= 0x070908
1141 set_from_env(&ssl_capath, "GIT_SSL_CAPATH");
1188 -#endif
1142 set_from_env(&ssl_cainfo, "GIT_SSL_CAINFO");
1143
1144 set_from_env(&user_agent, "GIT_HTTP_USER_AGENT");
@@ -1367,12 +1320,8 @@ struct active_request_slot *get_active_slot(void)
1320 else
1321 curl_easy_setopt(slot->curl, CURLOPT_FOLLOWLOCATION, 0);
1322
1370 -#if LIBCURL_VERSION_NUM >= 0x070a08
1323 curl_easy_setopt(slot->curl, CURLOPT_IPRESOLVE, git_curl_ipresolve);
1372 -#endif
1373 -#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
1324 curl_easy_setopt(slot->curl, CURLOPT_HTTPAUTH, http_auth_methods);
1375 -#endif
1325 if (http_auth.password || curl_empty_auth_enabled())
1326 init_curl_http_auth(slot->curl);
1327
@@ -1654,13 +1603,11 @@ static int handle_curl_result(struct slot_results *results)
1603 credential_reject(&http_auth);
1604 return HTTP_NOAUTH;
1605 } else {
1657 -#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
1606 http_auth_methods &= ~CURLAUTH_GSSNEGOTIATE;
1607 if (results->auth_avail) {
1608 http_auth_methods &= results->auth_avail;
1609 http_auth_methods_restricted = 1;
1610 }
1663 -#endif
1611 return HTTP_REAUTH;
1612 }
1613 } else {
http.h
+1 -11
@@ -22,13 +22,7 @@
22 #define DEFAULT_MAX_REQUESTS 5
23 #endif
24
25 -#if LIBCURL_VERSION_NUM < 0x070704
26 -#define curl_global_cleanup() do { /* nothing */ } while (0)
27 -#endif
28 -
29 -#if LIBCURL_VERSION_NUM < 0x070800
30 -#define curl_global_init(a) do { /* nothing */ } while (0)
31 -#elif LIBCURL_VERSION_NUM >= 0x070c00
25 +#if LIBCURL_VERSION_NUM >= 0x070c00
26 #define curl_global_init(a) curl_global_init_mem(a, xmalloc, free, \
27 xrealloc, xstrdup, xcalloc)
28 #endif
@@ -37,10 +31,6 @@
31 #define NO_CURL_EASY_DUPHANDLE
32 #endif
33
40 -#if LIBCURL_VERSION_NUM < 0x070a03
41 -#define CURLE_HTTP_RETURNED_ERROR CURLE_HTTP_NOT_FOUND
42 -#endif
43 -
34 #if LIBCURL_VERSION_NUM < 0x070c03
35 #define NO_CURL_IOCTL
36 #endif
remote-curl.c
-3
@@ -185,8 +185,6 @@ static int set_option(const char *name, const char *value)
185 strbuf_detach(&unquoted, NULL));
186 }
187 return 0;
188 -
189 -#if LIBCURL_VERSION_NUM >= 0x070a08
188 } else if (!strcmp(name, "family")) {
189 if (!strcmp(value, "ipv4"))
190 git_curl_ipresolve = CURL_IPRESOLVE_V4;
@@ -197,7 +195,6 @@ static int set_option(const char *name, const char *value)
195 else
196 return -1;
197 return 0;
200 -#endif /* LIBCURL_VERSION_NUM >= 0x070a08 */
198 } else if (!strcmp(name, "from-promisor")) {
199 options.from_promisor = 1;
200 return 0;