{"thread":{"id":"19586","subject":"[PATCH 07/17] http*: move common variables and macros to http.[ch]","startedAt":"2009-05-29T17:59:07Z","lastAt":"2009-05-29T17:59:07Z","messageCount":1,"participants":["Tay Ray Chuan"],"isPatch":true,"patchVersion":1,"patchTotal":17},"messages":[{"id":"115028","messageId":"20090530015907.55ef2c89.rctay89@gmail.com","threadId":"19586","inReplyTo":null,"subject":"[PATCH 07/17] http*: move common variables and macros to http.[ch]","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-05-29T17:59:07Z","receivedAt":"2009-05-29T17:59:07Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Move RANGE_HEADER_SIZE to http.h.\n\nCreate no_pragma_header, the curl header list containing the header\n\"Pragma:\" in http.[ch]. It is allocated in http_init, and freed in\nhttp_cleanup. This replaces the no_pragma_header in http-push.c, and\nthe no_pragma_header member in walker_data in http-walker.c.\n\nCreate http_is_verbose. It is to be used by methods in http.c, and is\nmodified at the entry points of http.c's users, namely http-push.c\n(when parsing options) and http-walker.c (in get_http_walker).\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n http-push.c   |    8 +-------\n http-walker.c |   18 +++++-------------\n http.c        |    9 +++++++++\n http.h        |    5 +++++\n 4 files changed, 20 insertions(+), 20 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex c48bb73..f2c8a97 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -27,7 +27,6 @@ enum XML_Status {\n #endif\n\n #define PREV_BUF_SIZE 4096\n-#define RANGE_HEADER_SIZE 30\n\n /* DAV methods */\n #define DAV_LOCK \"LOCK\"\n@@ -76,8 +75,6 @@ static int pushing;\n static int aborted;\n static signed char remote_dir_exists[256];\n\n-static struct curl_slist *no_pragma_header;\n-\n static int push_verbosely;\n static int push_all = MATCH_REFS_NONE;\n static int force_all;\n@@ -2246,6 +2243,7 @@ int main(int argc, char **argv)\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--verbose\")) {\n \t\t\t\tpush_verbosely = 1;\n+\t\t\t\thttp_is_verbose = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"-d\")) {\n@@ -2295,8 +2293,6 @@ int main(int argc, char **argv)\n \tremote->url[remote->url_nr++] = repo->url;\n \thttp_init(remote);\n\n-\tno_pragma_header = curl_slist_append(no_pragma_header, \"Pragma:\");\n-\n \tif (repo->url && repo->url[strlen(repo->url)-1] != '/') {\n \t\trewritten_url = xmalloc(strlen(repo->url)+2);\n \t\tstrcpy(rewritten_url, repo->url);\n@@ -2500,8 +2496,6 @@ int main(int argc, char **argv)\n \t\tunlock_remote(info_ref_lock);\n \tfree(repo);\n\n-\tcurl_slist_free_all(no_pragma_header);\n-\n \thttp_cleanup();\n\n \trequest = request_queue_head;\ndiff --git a/http-walker.c b/http-walker.c\nindex a2c9810..7d6795c 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -5,7 +5,6 @@\n #include \"http.h\"\n\n #define PREV_BUF_SIZE 4096\n-#define RANGE_HEADER_SIZE 30\n\n struct alt_base\n {\n@@ -57,7 +56,6 @@ struct walker_data {\n \tconst char *url;\n \tint got_alternates;\n \tstruct alt_base *alt;\n-\tstruct curl_slist *no_pragma_header;\n };\n\n static struct object_request *object_queue_head;\n@@ -108,7 +106,6 @@ static void start_object_request(struct walker *walker,\n \tchar range[RANGE_HEADER_SIZE];\n \tstruct curl_slist *range_header = NULL;\n \tstruct active_request_slot *slot;\n-\tstruct walker_data *data = walker->data;\n\n \tsnprintf(prevfile, sizeof(prevfile), \"%s.prev\", obj_req->filename);\n \tunlink_or_warn(prevfile);\n@@ -205,7 +202,7 @@ static void start_object_request(struct walker *walker,\n \tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);\n \tcurl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, obj_req->errorstr);\n \tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);\n\n \t/*\n \t * If we have successfully processed data from a previous fetch\n@@ -354,6 +351,8 @@ static void prefetch(struct walker *walker, unsigned char *sha1)\n \tnewreq->slot = NULL;\n \tnewreq->next = NULL;\n\n+\thttp_is_verbose = walker->get_verbosely;\n+\n \tif (object_queue_head == NULL) {\n \t\tobject_queue_head = newreq;\n \t} else {\n@@ -379,7 +378,6 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch\n \tlong prev_posn = 0;\n \tchar range[RANGE_HEADER_SIZE];\n \tstruct curl_slist *range_header = NULL;\n-\tstruct walker_data *data = walker->data;\n\n \tFILE *indexfile;\n \tstruct active_request_slot *slot;\n@@ -430,7 +428,7 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch\n \tcurl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);\n \tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);\n \tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);\n \tslot->local = indexfile;\n\n \t/*\n@@ -767,7 +765,6 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha\n \tlong prev_posn = 0;\n \tchar range[RANGE_HEADER_SIZE];\n \tstruct curl_slist *range_header = NULL;\n-\tstruct walker_data *data = walker->data;\n\n \tstruct active_request_slot *slot;\n \tstruct slot_results results;\n@@ -801,7 +798,7 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha\n \tcurl_easy_setopt(slot->curl, CURLOPT_FILE, packfile);\n \tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);\n \tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n-\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);\n \tslot->local = packfile;\n\n \t/*\n@@ -944,10 +941,7 @@ static int fetch_ref(struct walker *walker, struct ref *ref)\n\n static void cleanup(struct walker *walker)\n {\n-\tstruct walker_data *data = walker->data;\n \thttp_cleanup();\n-\n-\tcurl_slist_free_all(data->no_pragma_header);\n }\n\n struct walker *get_http_walker(const char *url, struct remote *remote)\n@@ -958,8 +952,6 @@ struct walker *get_http_walker(const char *url, struct remote *remote)\n\n \thttp_init(remote);\n\n-\tdata->no_pragma_header = curl_slist_append(NULL, \"Pragma:\");\n-\n \tdata->alt = xmalloc(sizeof(*data->alt));\n \tdata->alt->base = xmalloc(strlen(url) + 1);\n \tstrcpy(data->alt->base, url);\ndiff --git a/http.c b/http.c\nindex 2e3d649..3ca60bb 100644\n--- a/http.c\n+++ b/http.c\n@@ -2,6 +2,7 @@\n\n int data_received;\n int active_requests;\n+int http_is_verbose;\n\n #ifdef USE_CURL_MULTI\n static int max_requests = -1;\n@@ -29,6 +30,8 @@ static char *user_name, *user_pass;\n\n static struct curl_slist *pragma_header;\n\n+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@@ -276,6 +279,8 @@ void http_init(struct remote *remote)\n \tchar *low_speed_limit;\n \tchar *low_speed_time;\n\n+\thttp_is_verbose = 0;\n+\n \tgit_config(http_options, NULL);\n\n \tcurl_global_init(CURL_GLOBAL_ALL);\n@@ -284,6 +289,7 @@ void http_init(struct remote *remote)\n \t\tcurl_http_proxy = xstrdup(remote->http_proxy);\n\n \tpragma_header = curl_slist_append(pragma_header, \"Pragma: no-cache\");\n+\tno_pragma_header = curl_slist_append(no_pragma_header, \"Pragma:\");\n\n #ifdef USE_CURL_MULTI\n \t{\n@@ -366,6 +372,9 @@ void http_cleanup(void)\n \tcurl_slist_free_all(pragma_header);\n \tpragma_header = NULL;\n\n+\tcurl_slist_free_all(no_pragma_header);\n+\tno_pragma_header = NULL;\n+\n \tif (curl_http_proxy) {\n \t\tfree((void *)curl_http_proxy);\n \t\tcurl_http_proxy = NULL;\ndiff --git a/http.h b/http.h\nindex 26abebe..1ef7dc1 100644\n--- a/http.h\n+++ b/http.h\n@@ -88,11 +88,16 @@ extern void add_fill_function(void *data, int (*fill)(void *));\n extern void step_active_slots(void);\n #endif\n\n+extern struct curl_slist *no_pragma_header;\n+\n+#define RANGE_HEADER_SIZE 30\n+\n extern void http_init(struct remote *remote);\n extern void http_cleanup(void);\n\n extern int data_received;\n extern int active_requests;\n+extern int http_is_verbose;\n\n extern char curl_errorstr[CURL_ERROR_SIZE];\n\n--\n1.6.3.1\n"}]}