{"thread":{"id":"26936","subject":"[PATCH 2/2] http-push: refactor curl_easy_setup madness","startedAt":"2011-03-31T01:38:50Z","lastAt":"2011-04-16T18:24:14Z","messageCount":5,"participants":["Dan McGee","Junio C Hamano","Tay Ray Chuan"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"164750","messageId":"1301535531-1244-1-git-send-email-dpmcgee@gmail.com","threadId":"26936","inReplyTo":null,"subject":"[PATCH 1/2] http: make curl callbacks match contracts from curl header","fromName":"Dan McGee","fromEmail":"dpmcgee@gmail.com","sentAt":"2011-03-31T01:38:50Z","receivedAt":"2011-03-31T01:38:50Z","isPatch":true,"sender":{"key":"dpmcgee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/265817?v=4"},"body":"Yes, these don't match perfectly with the void* first parameter of the\nfread/fwrite in the standard library, but they do match the curl\nexpected method signature. This is needed when a refactor passes a\ncurl_write_callback around, which would otherwise give incorrect\nparameter warnings.\n\nSigned-off-by: Dan McGee <dpmcgee@gmail.com>\n---\n http-walker.c |    2 +-\n http.c        |   12 ++++++------\n http.h        |    6 +++---\n remote-curl.c |    2 +-\n 4 files changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/http-walker.c b/http-walker.c\nindex 9bc8114..c83df1b 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -185,7 +185,7 @@ static void process_alternates_response(void *callback_data)\n \tstruct active_request_slot *slot = alt_req->slot;\n \tstruct alt_base *tail = cdata->alt;\n \tconst char *base = alt_req->base;\n-\tstatic const char null_byte = '\\0';\n+\tchar null_byte = '\\0';\n \tchar *data;\n \tint i = 0;\n \ndiff --git a/http.c b/http.c\nindex 9e76772..f44816b 100644\n--- a/http.c\n+++ b/http.c\n@@ -60,7 +60,7 @@ static struct curl_slist *no_pragma_header;\n \n static struct active_request_slot *active_queue_head;\n \n-size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *buffer_)\n+size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)\n {\n \tsize_t size = eltsize * nmemb;\n \tstruct buffer *buffer = buffer_;\n@@ -92,7 +92,7 @@ curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp)\n }\n #endif\n \n-size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *buffer_)\n+size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)\n {\n \tsize_t size = eltsize * nmemb;\n \tstruct strbuf *buffer = buffer_;\n@@ -102,7 +102,7 @@ size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *buffer\n \treturn size;\n }\n \n-size_t fwrite_null(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf)\n+size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf)\n {\n \tdata_received++;\n \treturn eltsize * nmemb;\n@@ -1166,7 +1166,7 @@ abort:\n }\n \n /* Helpers for fetching objects (loose) */\n-static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,\n+static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,\n \t\t\t       void *data)\n {\n \tunsigned char expn[4096];\n@@ -1183,7 +1183,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,\n \t} while (posn < size);\n \n \tfreq->stream.avail_in = size;\n-\tfreq->stream.next_in = ptr;\n+\tfreq->stream.next_in = (void *)ptr;\n \tdo {\n \t\tfreq->stream.next_out = expn;\n \t\tfreq->stream.avail_out = sizeof(expn);\n@@ -1202,7 +1202,7 @@ struct http_object_request *new_http_object_request(const char *base_url,\n \tchar *filename;\n \tchar prevfile[PATH_MAX];\n \tint prevlocal;\n-\tunsigned char prev_buf[PREV_BUF_SIZE];\n+\tchar prev_buf[PREV_BUF_SIZE];\n \tssize_t prev_read = 0;\n \tlong prev_posn = 0;\n \tchar range[RANGE_HEADER_SIZE];\ndiff --git a/http.h b/http.h\nindex e9ed3c2..19b7134 100644\n--- a/http.h\n+++ b/http.h\n@@ -66,9 +66,9 @@ struct buffer {\n };\n \n /* Curl request read/write callbacks */\n-extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *strbuf);\n-extern size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);\n-extern size_t fwrite_null(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);\n+extern size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);\n+extern size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);\n+extern size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);\n #ifndef NO_CURL_IOCTL\n extern curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp);\n #endif\ndiff --git a/remote-curl.c b/remote-curl.c\nindex 775d614..17d8a9b 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -347,7 +347,7 @@ static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp)\n }\n #endif\n \n-static size_t rpc_in(const void *ptr, size_t eltsize,\n+static size_t rpc_in(char *ptr, size_t eltsize,\n \t\tsize_t nmemb, void *buffer_)\n {\n \tsize_t size = eltsize * nmemb;\n-- \n1.7.4.2\n"},{"id":"164749","messageId":"1301535531-1244-2-git-send-email-dpmcgee@gmail.com","threadId":"26936","inReplyTo":"1301535531-1244-1-git-send-email-dpmcgee@gmail.com","subject":"[PATCH 2/2] http-push: refactor curl_easy_setup madness","fromName":"Dan McGee","fromEmail":"dpmcgee@gmail.com","sentAt":"2011-03-31T01:38:51Z","receivedAt":"2011-03-31T01:38:51Z","isPatch":true,"sender":{"key":"dpmcgee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/265817?v=4"},"body":"We were doing (nearly) the same thing all over the place, in slightly\ndifferent orders, different variable names, etc. Refactor most calls\ninto two helper functions, one for GET and one for everything else, that\ndo the heavy lifting leaving most callsites a lot cleaner in the\nprocess.\n\nSigned-off-by: Dan McGee <dpmcgee@gmail.com>\n---\n http-push.c |  152 ++++++++++++++++++++---------------------------------------\n 1 files changed, 52 insertions(+), 100 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex d18346c..28bfe76 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -169,7 +169,7 @@ enum dav_header_flag {\n \tDAV_HEADER_TIMEOUT = (1u << 2)\n };\n \n-static char *xml_entities(char *s)\n+static char *xml_entities(const char *s)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \twhile (*s) {\n@@ -197,6 +197,34 @@ static char *xml_entities(char *s)\n \treturn strbuf_detach(&buf, NULL);\n }\n \n+static void curl_setup_http_get(CURL *curl, const char *url,\n+\t\tconst char *custom_req)\n+{\n+\tcurl_easy_setopt(curl, CURLOPT_HTTPGET, 1);\n+\tcurl_easy_setopt(curl, CURLOPT_URL, url);\n+\tcurl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, custom_req);\n+\tcurl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_null);\n+}\n+\n+static void curl_setup_http(CURL *curl, const char *url,\n+\t\tconst char *custom_req, struct buffer *buffer,\n+\t\tcurl_write_callback write_fn)\n+{\n+\tcurl_easy_setopt(curl, CURLOPT_PUT, 1);\n+\tcurl_easy_setopt(curl, CURLOPT_URL, url);\n+\tcurl_easy_setopt(curl, CURLOPT_INFILE, buffer);\n+\tcurl_easy_setopt(curl, CURLOPT_INFILESIZE, buffer->buf.len);\n+\tcurl_easy_setopt(curl, CURLOPT_READFUNCTION, fread_buffer);\n+#ifndef NO_CURL_IOCTL\n+\tcurl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);\n+\tcurl_easy_setopt(curl, CURLOPT_IOCTLDATA, &buffer);\n+#endif\n+\tcurl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_fn);\n+\tcurl_easy_setopt(curl, CURLOPT_NOBODY, 0);\n+\tcurl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, custom_req);\n+\tcurl_easy_setopt(curl, CURLOPT_UPLOAD, 1);\n+}\n+\n static struct curl_slist *get_dav_token_headers(struct remote_lock *lock, enum dav_header_flag options)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -272,11 +300,8 @@ static void start_mkcol(struct transfer_request *request)\n \tslot = get_active_slot();\n \tslot->callback_func = process_response;\n \tslot->callback_data = request;\n-\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1); /* undo PUT setup */\n-\tcurl_easy_setopt(slot->curl, CURLOPT_URL, request->url);\n+\tcurl_setup_http_get(slot->curl, request->url, DAV_MKCOL);\n \tcurl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, request->errorstr);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_MKCOL);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);\n \n \tif (start_active_slot(slot)) {\n \t\trequest->slot = slot;\n@@ -395,19 +420,8 @@ static void start_put(struct transfer_request *request)\n \tslot = get_active_slot();\n \tslot->callback_func = process_response;\n \tslot->callback_data = request;\n-\tcurl_easy_setopt(slot->curl, CURLOPT_INFILE, &request->buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, request->buffer.buf.len);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);\n-#ifndef NO_CURL_IOCTL\n-\tcurl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &request->buffer);\n-#endif\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_PUT, 1);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_URL, request->url);\n+\tcurl_setup_http(slot->curl, request->url, DAV_PUT,\n+\t\t\t&request->buffer, fwrite_null);\n \n \tif (start_active_slot(slot)) {\n \t\trequest->slot = slot;\n@@ -427,13 +441,10 @@ static void start_move(struct transfer_request *request)\n \tslot = get_active_slot();\n \tslot->callback_func = process_response;\n \tslot->callback_data = request;\n-\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1); /* undo PUT setup */\n-\tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_MOVE);\n+\tcurl_setup_http_get(slot->curl, request->url, DAV_MOVE);\n \tdav_headers = curl_slist_append(dav_headers, request->dest);\n \tdav_headers = curl_slist_append(dav_headers, \"Overwrite: T\");\n \tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_URL, request->url);\n \n \tif (start_active_slot(slot)) {\n \t\trequest->slot = slot;\n@@ -458,10 +469,7 @@ static int refresh_lock(struct remote_lock *lock)\n \n \tslot = get_active_slot();\n \tslot->results = &results;\n-\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_URL, lock->url);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_LOCK);\n+\tcurl_setup_http_get(slot->curl, lock->url, DAV_LOCK);\n \tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);\n \n \tif (start_active_slot(slot)) {\n@@ -797,7 +805,7 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)\n \t}\n }\n \n-static void one_remote_ref(char *refname);\n+static void one_remote_ref(const char *refname);\n \n static void\n xml_start_tag(void *userData, const char *name, const char **atts)\n@@ -876,10 +884,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)\n \t\tep[1] = '\\0';\n \t\tslot = get_active_slot();\n \t\tslot->results = &results;\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_MKCOL);\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);\n+\t\tcurl_setup_http_get(slot->curl, url, DAV_MKCOL);\n \t\tif (start_active_slot(slot)) {\n \t\t\trun_active_slot(slot);\n \t\t\tif (results.curl_result != CURLE_OK &&\n@@ -909,19 +914,9 @@ static struct remote_lock *lock_remote(const char *path, long timeout)\n \n \tslot = get_active_slot();\n \tslot->results = &results;\n-\tcurl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);\n-#ifndef NO_CURL_IOCTL\n-\tcurl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);\n-#endif\n-\tcurl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_LOCK);\n+\tcurl_setup_http(slot->curl, url, DAV_LOCK, &out_buffer, fwrite_buffer);\n \tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);\n \n \tlock = xcalloc(1, sizeof(*lock));\n \tlock->timeout = -1;\n@@ -987,9 +982,7 @@ static int unlock_remote(struct remote_lock *lock)\n \n \tslot = get_active_slot();\n \tslot->results = &results;\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_URL, lock->url);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_UNLOCK);\n+\tcurl_setup_http_get(slot->curl, lock->url, DAV_UNLOCK);\n \tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);\n \n \tif (start_active_slot(slot)) {\n@@ -1167,19 +1160,10 @@ static void remote_ls(const char *path, int flags,\n \n \tslot = get_active_slot();\n \tslot->results = &results;\n-\tcurl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);\n-#ifndef NO_CURL_IOCTL\n-\tcurl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);\n-#endif\n-\tcurl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PROPFIND);\n+\tcurl_setup_http(slot->curl, url, DAV_PROPFIND,\n+\t\t\t&out_buffer, fwrite_buffer);\n \tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);\n \n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n@@ -1250,19 +1234,10 @@ static int locking_available(void)\n \n \tslot = get_active_slot();\n \tslot->results = &results;\n-\tcurl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);\n-#ifndef NO_CURL_IOCTL\n-\tcurl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);\n-#endif\n-\tcurl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_URL, repo->url);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PROPFIND);\n+\tcurl_setup_http(slot->curl, repo->url, DAV_PROPFIND,\n+\t\t\t&out_buffer, fwrite_buffer);\n \tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);\n \n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n@@ -1436,19 +1411,9 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)\n \n \tslot = get_active_slot();\n \tslot->results = &results;\n-\tcurl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);\n-#ifndef NO_CURL_IOCTL\n-\tcurl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);\n-#endif\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);\n+\tcurl_setup_http(slot->curl, lock->url, DAV_PUT,\n+\t\t\t&out_buffer, fwrite_null);\n \tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_PUT, 1);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_URL, lock->url);\n \n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n@@ -1471,7 +1436,7 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)\n \n static struct ref *remote_refs;\n \n-static void one_remote_ref(char *refname)\n+static void one_remote_ref(const char *refname)\n {\n \tstruct ref *ref;\n \tstruct object *obj;\n@@ -1572,19 +1537,9 @@ static void update_remote_info_refs(struct remote_lock *lock)\n \n \t\tslot = get_active_slot();\n \t\tslot->results = &results;\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_INFILE, &buffer);\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, buffer.buf.len);\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);\n-#ifndef NO_CURL_IOCTL\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &buffer);\n-#endif\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);\n+\t\tcurl_setup_http(slot->curl, lock->url, DAV_PUT,\n+\t\t\t\t&buffer, fwrite_null);\n \t\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_PUT, 1);\n-\t\tcurl_easy_setopt(slot->curl, CURLOPT_URL, lock->url);\n \n \t\tif (start_active_slot(slot)) {\n \t\t\trun_active_slot(slot);\n@@ -1660,7 +1615,7 @@ static int verify_merge_base(unsigned char *head_sha1, unsigned char *branch_sha\n \treturn (merge_bases && !merge_bases->next && merge_bases->item == branch);\n }\n \n-static int delete_remote_branch(char *pattern, int force)\n+static int delete_remote_branch(const char *pattern, int force)\n {\n \tstruct ref *refs = remote_refs;\n \tstruct ref *remote_ref = NULL;\n@@ -1742,10 +1697,7 @@ static int delete_remote_branch(char *pattern, int force)\n \tsprintf(url, \"%s%s\", repo->url, remote_ref->name);\n \tslot = get_active_slot();\n \tslot->results = &results;\n-\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_DELETE);\n+\tcurl_setup_http_get(slot->curl, url, DAV_DELETE);\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n \t\tfree(url);\n-- \n1.7.4.2\n"},{"id":"165146","messageId":"7v8vvp7fr0.fsf@alter.siamese.dyndns.org","threadId":"26936","inReplyTo":"1301535531-1244-1-git-send-email-dpmcgee@gmail.com","subject":"Re: [PATCH 1/2] http: make curl callbacks match contracts from curl header","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-04T23:34:27Z","receivedAt":"2011-04-04T23:34:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dan McGee <dpmcgee@gmail.com> writes:\n\n> diff --git a/http-walker.c b/http-walker.c\n> index 9bc8114..c83df1b 100644\n> --- a/http-walker.c\n> +++ b/http-walker.c\n> @@ -185,7 +185,7 @@ static void process_alternates_response(void *callback_data)\n>  \tstruct active_request_slot *slot = alt_req->slot;\n>  \tstruct alt_base *tail = cdata->alt;\n>  \tconst char *base = alt_req->base;\n> -\tstatic const char null_byte = '\\0';\n> +\tchar null_byte = '\\0';\n\nI know you needed this change because later call to fwrite_buffer() uses a\npointer to this one byte, and the fwrite_buffer() takes \"char *\" not\n\"const char *\", but ...\n\n> @@ -1183,7 +1183,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,\n>  \t} while (posn < size);\n>  \n>  \tfreq->stream.avail_in = size;\n> -\tfreq->stream.next_in = ptr;\n> +\tfreq->stream.next_in = (void *)ptr;\n\n... if you are willing to cast the type away like this anyway, which is\nnot a bad thing at all, wouldn't it be better to keep the \"static const\nchar nul_byte = '\\0'\" as it was, and use it like\n\n\tfwrite_buffer((char *)&nul_byte, 1, 1, ...);\n\nfor consistency?\n"},{"id":"165150","messageId":"1301965579-5299-1-git-send-email-dpmcgee@gmail.com","threadId":"26936","inReplyTo":"7v8vvp7fr0.fsf@alter.siamese.dyndns.org","subject":"[PATCH] http: make curl callbacks match contracts from curl header","fromName":"Dan McGee","fromEmail":"dpmcgee@gmail.com","sentAt":"2011-04-05T01:06:19Z","receivedAt":"2011-04-05T01:06:19Z","isPatch":true,"sender":{"key":"dpmcgee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/265817?v=4"},"body":"Yes, these don't match perfectly with the void* first parameter of the\nfread/fwrite in the standard library, but they do match the curl\nexpected method signature. This is needed when a refactor passes a\ncurl_write_callback around, which would otherwise give incorrect\nparameter warnings.\n\nSigned-off-by: Dan McGee <dpmcgee@gmail.com>\n---\n\nCast the const-ness away in process_alternates_response with the call to\nfwrite_buffer() as suggested by Junio, which shows the correct intent rather\nthan making the variable non-const to begin with. The static modifier was still\ndropped.\n\n http-walker.c |    4 ++--\n http.c        |   12 ++++++------\n http.h        |    6 +++---\n remote-curl.c |    2 +-\n 4 files changed, 12 insertions(+), 12 deletions(-)\n\ndiff --git a/http-walker.c b/http-walker.c\nindex 9bc8114..51a906e 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -185,7 +185,7 @@ static void process_alternates_response(void *callback_data)\n \tstruct active_request_slot *slot = alt_req->slot;\n \tstruct alt_base *tail = cdata->alt;\n \tconst char *base = alt_req->base;\n-\tstatic const char null_byte = '\\0';\n+\tconst char null_byte = '\\0';\n \tchar *data;\n \tint i = 0;\n \n@@ -218,7 +218,7 @@ static void process_alternates_response(void *callback_data)\n \t\t}\n \t}\n \n-\tfwrite_buffer(&null_byte, 1, 1, alt_req->buffer);\n+\tfwrite_buffer((char *)&null_byte, 1, 1, alt_req->buffer);\n \talt_req->buffer->len--;\n \tdata = alt_req->buffer->buf;\n \ndiff --git a/http.c b/http.c\nindex 9e76772..f44816b 100644\n--- a/http.c\n+++ b/http.c\n@@ -60,7 +60,7 @@ static struct curl_slist *no_pragma_header;\n \n static struct active_request_slot *active_queue_head;\n \n-size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *buffer_)\n+size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)\n {\n \tsize_t size = eltsize * nmemb;\n \tstruct buffer *buffer = buffer_;\n@@ -92,7 +92,7 @@ curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp)\n }\n #endif\n \n-size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *buffer_)\n+size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)\n {\n \tsize_t size = eltsize * nmemb;\n \tstruct strbuf *buffer = buffer_;\n@@ -102,7 +102,7 @@ size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *buffer\n \treturn size;\n }\n \n-size_t fwrite_null(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf)\n+size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf)\n {\n \tdata_received++;\n \treturn eltsize * nmemb;\n@@ -1166,7 +1166,7 @@ abort:\n }\n \n /* Helpers for fetching objects (loose) */\n-static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,\n+static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,\n \t\t\t       void *data)\n {\n \tunsigned char expn[4096];\n@@ -1183,7 +1183,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,\n \t} while (posn < size);\n \n \tfreq->stream.avail_in = size;\n-\tfreq->stream.next_in = ptr;\n+\tfreq->stream.next_in = (void *)ptr;\n \tdo {\n \t\tfreq->stream.next_out = expn;\n \t\tfreq->stream.avail_out = sizeof(expn);\n@@ -1202,7 +1202,7 @@ struct http_object_request *new_http_object_request(const char *base_url,\n \tchar *filename;\n \tchar prevfile[PATH_MAX];\n \tint prevlocal;\n-\tunsigned char prev_buf[PREV_BUF_SIZE];\n+\tchar prev_buf[PREV_BUF_SIZE];\n \tssize_t prev_read = 0;\n \tlong prev_posn = 0;\n \tchar range[RANGE_HEADER_SIZE];\ndiff --git a/http.h b/http.h\nindex e9ed3c2..19b7134 100644\n--- a/http.h\n+++ b/http.h\n@@ -66,9 +66,9 @@ struct buffer {\n };\n \n /* Curl request read/write callbacks */\n-extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *strbuf);\n-extern size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);\n-extern size_t fwrite_null(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);\n+extern size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);\n+extern size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);\n+extern size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);\n #ifndef NO_CURL_IOCTL\n extern curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp);\n #endif\ndiff --git a/remote-curl.c b/remote-curl.c\nindex 775d614..17d8a9b 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -347,7 +347,7 @@ static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp)\n }\n #endif\n \n-static size_t rpc_in(const void *ptr, size_t eltsize,\n+static size_t rpc_in(char *ptr, size_t eltsize,\n \t\tsize_t nmemb, void *buffer_)\n {\n \tsize_t size = eltsize * nmemb;\n-- \n1.7.4.2\n"},{"id":"165980","messageId":"BANLkTinv4M7biQ_Wd3rWYbGLSwgGBmhbUA@mail.gmail.com","threadId":"26936","inReplyTo":"1301535531-1244-2-git-send-email-dpmcgee@gmail.com","subject":"Re: [PATCH 2/2] http-push: refactor curl_easy_setup madness","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2011-04-16T18:24:14Z","receivedAt":"2011-04-16T18:24:14Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"On Thu, Mar 31, 2011 at 9:38 AM, Dan McGee <dpmcgee@gmail.com> wrote:\n> We were doing (nearly) the same thing all over the place, in slightly\n> different orders, different variable names, etc. Refactor most calls\n> into two helper functions, one for GET and one for everything else, that\n> do the heavy lifting leaving most callsites a lot cleaner in the\n> process.\n>\n> Signed-off-by: Dan McGee <dpmcgee@gmail.com>\n\nNice work.\n\nPerhaps you should mention in the commit message that the setting of\nCURLOPT_PUT at the callsites of curl_setup_http() which previously\ndidn't do it (eg. locking_available(), remote_ls()) is ok, since that\noption is deprecated in place of, and has the same effect as,\nCURLOPT_UPLOAD.\n\n> --- a/http-push.c\n> +++ b/http-push.c\n> @@ -169,7 +169,7 @@ enum dav_header_flag {\n>        DAV_HEADER_TIMEOUT = (1u << 2)\n>  };\n>\n> -static char *xml_entities(char *s)\n> +static char *xml_entities(const char *s)\n>  {\n>        struct strbuf buf = STRBUF_INIT;\n>        while (*s) {\n\nPerhaps the addition of \"const\", and elsewhere in this patch, should\nbe placed in a separate patch.\n\n--\nCheers,\nRay Chuan\n"}]}