Skip to content

Commit f31a871

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Merge branch 'jk/curl-avoid-deprecated-api'
This is needed to make the `linux-musl` and `osx-gcc` builds pass again. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 3cfe349 + 6c065f7 commit f31a871

File tree

6 files changed

+81
-44
lines changed

6 files changed

+81
-44
lines changed

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Issues of note:
139139
not need that functionality, use NO_CURL to build without
140140
it.
141141

142-
Git requires version "7.19.4" or later of "libcurl" to build
142+
Git requires version "7.19.5" or later of "libcurl" to build
143143
without NO_CURL. This version requirement may be bumped in
144144
the future.
145145

git-curl-compat.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,12 @@
126126
#define GIT_CURL_HAVE_CURLSSLSET_NO_BACKENDS
127127
#endif
128128

129+
/**
130+
* CURLOPT_PROTOCOLS_STR and CURLOPT_REDIR_PROTOCOLS_STR were added in 7.85.0,
131+
* released in August 2022.
132+
*/
133+
#if LIBCURL_VERSION_NUM >= 0x075500
134+
#define GIT_CURL_HAVE_CURLOPT_PROTOCOLS_STR 1
135+
#endif
136+
129137
#endif

http-push.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ static void curl_setup_http(CURL *curl, const char *url,
198198
const char *custom_req, struct buffer *buffer,
199199
curl_write_callback write_fn)
200200
{
201-
curl_easy_setopt(curl, CURLOPT_PUT, 1);
201+
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
202202
curl_easy_setopt(curl, CURLOPT_URL, url);
203203
curl_easy_setopt(curl, CURLOPT_INFILE, buffer);
204204
curl_easy_setopt(curl, CURLOPT_INFILESIZE, buffer->buf.len);
205205
curl_easy_setopt(curl, CURLOPT_READFUNCTION, fread_buffer);
206-
curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
207-
curl_easy_setopt(curl, CURLOPT_IOCTLDATA, buffer);
206+
curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, seek_buffer);
207+
curl_easy_setopt(curl, CURLOPT_SEEKDATA, buffer);
208208
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_fn);
209209
curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
210210
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, custom_req);

http.c

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,19 @@ size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
157157
return size / eltsize;
158158
}
159159

160-
curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp)
160+
int seek_buffer(void *clientp, curl_off_t offset, int origin)
161161
{
162162
struct buffer *buffer = clientp;
163163

164-
switch (cmd) {
165-
case CURLIOCMD_NOP:
166-
return CURLIOE_OK;
167-
168-
case CURLIOCMD_RESTARTREAD:
169-
buffer->posn = 0;
170-
return CURLIOE_OK;
171-
172-
default:
173-
return CURLIOE_UNKNOWNCMD;
164+
if (origin != SEEK_SET)
165+
BUG("seek_buffer only handles SEEK_SET");
166+
if (offset < 0 || offset >= buffer->buf.len) {
167+
error("curl seek would be outside of buffer");
168+
return CURL_SEEKFUNC_FAIL;
174169
}
170+
171+
buffer->posn = offset;
172+
return CURL_SEEKFUNC_OK;
175173
}
176174

177175
size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
@@ -766,20 +764,37 @@ void setup_curl_trace(CURL *handle)
766764
curl_easy_setopt(handle, CURLOPT_DEBUGDATA, NULL);
767765
}
768766

769-
static long get_curl_allowed_protocols(int from_user)
767+
static void proto_list_append(struct strbuf *list, const char *proto)
770768
{
771-
long allowed_protocols = 0;
769+
if (!list)
770+
return;
771+
if (list->len)
772+
strbuf_addch(list, ',');
773+
strbuf_addstr(list, proto);
774+
}
772775

773-
if (is_transport_allowed("http", from_user))
774-
allowed_protocols |= CURLPROTO_HTTP;
775-
if (is_transport_allowed("https", from_user))
776-
allowed_protocols |= CURLPROTO_HTTPS;
777-
if (is_transport_allowed("ftp", from_user))
778-
allowed_protocols |= CURLPROTO_FTP;
779-
if (is_transport_allowed("ftps", from_user))
780-
allowed_protocols |= CURLPROTO_FTPS;
776+
static long get_curl_allowed_protocols(int from_user, struct strbuf *list)
777+
{
778+
long bits = 0;
781779

782-
return allowed_protocols;
780+
if (is_transport_allowed("http", from_user)) {
781+
bits |= CURLPROTO_HTTP;
782+
proto_list_append(list, "http");
783+
}
784+
if (is_transport_allowed("https", from_user)) {
785+
bits |= CURLPROTO_HTTPS;
786+
proto_list_append(list, "https");
787+
}
788+
if (is_transport_allowed("ftp", from_user)) {
789+
bits |= CURLPROTO_FTP;
790+
proto_list_append(list, "ftp");
791+
}
792+
if (is_transport_allowed("ftps", from_user)) {
793+
bits |= CURLPROTO_FTPS;
794+
proto_list_append(list, "ftps");
795+
}
796+
797+
return bits;
783798
}
784799

785800
#ifdef GIT_CURL_HAVE_CURL_HTTP_VERSION_2
@@ -923,10 +938,26 @@ static CURL *get_curl_handle(void)
923938

924939
curl_easy_setopt(result, CURLOPT_MAXREDIRS, 20);
925940
curl_easy_setopt(result, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
941+
942+
#ifdef GIT_CURL_HAVE_CURLOPT_PROTOCOLS_STR
943+
{
944+
struct strbuf buf = STRBUF_INIT;
945+
946+
get_curl_allowed_protocols(0, &buf);
947+
curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS_STR, buf.buf);
948+
strbuf_reset(&buf);
949+
950+
get_curl_allowed_protocols(-1, &buf);
951+
curl_easy_setopt(result, CURLOPT_PROTOCOLS_STR, buf.buf);
952+
strbuf_release(&buf);
953+
}
954+
#else
926955
curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS,
927-
get_curl_allowed_protocols(0));
956+
get_curl_allowed_protocols(0, NULL));
928957
curl_easy_setopt(result, CURLOPT_PROTOCOLS,
929-
get_curl_allowed_protocols(-1));
958+
get_curl_allowed_protocols(-1, NULL));
959+
#endif
960+
930961
if (getenv("GIT_CURL_VERBOSE"))
931962
http_trace_curl_no_data();
932963
setup_curl_trace(result);

http.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct buffer {
4040
size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);
4141
size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);
4242
size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);
43-
curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp);
43+
int seek_buffer(void *clientp, curl_off_t offset, int origin);
4444

4545
/* Slot lifecycle functions */
4646
struct active_request_slot *get_active_slot(void);

remote-curl.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -717,25 +717,23 @@ static size_t rpc_out(void *ptr, size_t eltsize,
717717
return avail;
718718
}
719719

720-
static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp)
720+
static int rpc_seek(void *clientp, curl_off_t offset, int origin)
721721
{
722722
struct rpc_state *rpc = clientp;
723723

724-
switch (cmd) {
725-
case CURLIOCMD_NOP:
726-
return CURLIOE_OK;
724+
if (origin != SEEK_SET)
725+
BUG("rpc_seek only handles SEEK_SET, not %d", origin);
727726

728-
case CURLIOCMD_RESTARTREAD:
729-
if (rpc->initial_buffer) {
730-
rpc->pos = 0;
731-
return CURLIOE_OK;
727+
if (rpc->initial_buffer) {
728+
if (offset < 0 || offset > rpc->len) {
729+
error("curl seek would be outside of rpc buffer");
730+
return CURL_SEEKFUNC_FAIL;
732731
}
733-
error(_("unable to rewind rpc post data - try increasing http.postBuffer"));
734-
return CURLIOE_FAILRESTART;
735-
736-
default:
737-
return CURLIOE_UNKNOWNCMD;
732+
rpc->pos = offset;
733+
return CURL_SEEKFUNC_OK;
738734
}
735+
error(_("unable to rewind rpc post data - try increasing http.postBuffer"));
736+
return CURL_SEEKFUNC_FAIL;
739737
}
740738

741739
struct check_pktline_state {
@@ -959,8 +957,8 @@ static int post_rpc(struct rpc_state *rpc, int stateless_connect, int flush_rece
959957
rpc->initial_buffer = 1;
960958
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out);
961959
curl_easy_setopt(slot->curl, CURLOPT_INFILE, rpc);
962-
curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, rpc_ioctl);
963-
curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, rpc);
960+
curl_easy_setopt(slot->curl, CURLOPT_SEEKFUNCTION, rpc_seek);
961+
curl_easy_setopt(slot->curl, CURLOPT_SEEKDATA, rpc);
964962
if (options.verbosity > 1) {
965963
fprintf(stderr, "POST %s (chunked)\n", rpc->service_name);
966964
fflush(stderr);

0 commit comments

Comments
 (0)