Sparse fixes for http-fetch
PATCH 1/1 Sparse fixes for http-fetch
This patch cleans out all sparse warnings from http-fetch.c
I'm a bit uncomfortable with adding extra #ifdefs to avoid either 'mixing declaration with code' or 'unused variable' warnings, but I figured that since those functions are already littered with #ifdefs I might just get away with it. Comments?
---
* ANSI:fy a few function definitions
* Make needlessly global functions static
* Move variable declarations to beginning of enclosing block
---
http-fetch.c +15 -10
@@ -143,7 +143,7 @@ void process_curl_messages();void process_request_queue ();#endif -struct active_request_slot *get_active_slot () +static struct active_request_slot *get_active_slot (void ) {struct active_request_slot *slot = active_queue_head;struct active_request_slot *newslot;
@@ -192,7 +192,7 @@ struct active_request_slot *get_active_sreturn slot; } -int start_active_slot (struct active_request_slot *slot) +static int start_active_slot (struct active_request_slot *slot) {#ifdef USE_CURL_MULTI CURLMcode curlm_result =curl_multi_add_handle (curlm, slot->curl);
@@ -207,7 +207,7 @@ int start_active_slot(struct active_requreturn 1 ; } -void run_active_slot (struct active_request_slot *slot) +static void run_active_slot (struct active_request_slot *slot) {#ifdef USE_CURL_MULTI int num_transfers;
@@ -255,7 +255,7 @@ void run_active_slot(struct active_reque#endif } -void start_request (struct transfer_request *request) +static void start_request (struct transfer_request *request) {char *hex =sha1_to_hex (request->sha1);char prevfile[PATH_MAX ];
@@ -381,7 +381,7 @@ void start_request(struct transfer_reque request->state =ACTIVE ; } -void finish_request (struct transfer_request *request) +static void finish_request (struct transfer_request *request) {fchmod (request->local,0444 );close (request->local);
@@ -409,7 +409,7 @@ void finish_request(struct transfer_requpull_say ("got %s\n" ,sha1_to_hex (request->sha1)); } -void release_request (struct transfer_request *request) +static void release_request (struct transfer_request *request) {struct transfer_request *entry = request_queue_head;
@@ -427,7 +427,7 @@ void release_request(struct transfer_req }#ifdef USE_CURL_MULTI -void process_curl_messages () +void process_curl_messages (void ) {int num_messages;struct active_request_slot *slot;
@@ -479,7 +479,7 @@ void process_curl_messages() } } -void process_request_queue () +void process_request_queue (void ) {struct transfer_request *request = request_queue_head;int num_transfers;
@@ -875,6 +875,9 @@ static int fetch_object(struct alt_basechar *hex =sha1_to_hex (sha1);int ret;struct transfer_request *request = request_queue_head; +#ifdef USE_CURL_MULTI +int num_transfers; +#endif while (request !=NULL &&memcmp (request->sha1, sha1,20 )) request = request->next;
@@ -887,7 +890,6 @@ static int fetch_object(struct alt_base }#ifdef USE_CURL_MULTI -int num_transfers;while (request->state ==WAITING ) {curl_multi_perform (curlm, &num_transfers);if (num_transfers < active_requests) {
@@ -1052,6 +1054,9 @@ int main(int argc, char **argv)char *url;int arg =1 ;struct active_request_slot *slot; +#ifdef USE_CURL_MULTI +char *http_max_requests; +#endif while (arg < argc && argv[arg][0 ] =='-' ) {if (argv[arg][1 ] =='t' ) {
@@ -1082,7 +1087,7 @@ int main(int argc, char **argv)curl_global_init (CURL_GLOBAL_ALL );#ifdef USE_CURL_MULTI -char *http_max_requests =getenv ("GIT_HTTP_MAX_REQUESTS" ); + http_max_requests =getenv ("GIT_HTTP_MAX_REQUESTS" );if (http_max_requests !=NULL ) max_requests =atoi (http_max_requests);if (max_requests <1 )
Quoted 7 lines · Peter Hagervall
This patch cleans out all sparse warnings from
http-fetch.cI'm a bit uncomfortable with adding extra #ifdefs to avoid either 'mixing declaration with code' or 'unused variable' warnings, but I figured that since those functions are already littered with #ifdefs I might just get away with it. Comments?
For the first, you can use extra brackets to create blocks in which declarations can happen; for the latter, you can (void)var; to specify that a certain variable may be legitimately unused under some circumstances.
-hpa
Quoted 4 lines · Peter Hagervall
I'm a bit uncomfortable with adding extra #ifdefs to avoid either 'mixing declaration with code' or 'unused variable' warnings, but I figured that since those functions are already littered with #ifdefs I might just get away with it. Comments?
How about something like this on top of what you posted? There still is one in main(), but...
---
cd /opt/packrat/playpen/public/in-place/git/git.junio/ git diff
http-fetch.c +5 -10
@@ -27,6 +27,8 @@ static int data_received;#ifdef USE_CURL_MULTI static int max_requests =DEFAULT_MAX_REQUESTS ;static CURLM *curlm; +static void process_curl_messages (); +static void process_request_queue ();#endif static CURL *curl_default;static struct curl_slist *pragma_header;
@@ -154,11 +156,6 @@ static size_t fwrite_sha1_file(void *ptrreturn size; } -#ifdef USE_CURL_MULTI -void process_curl_messages (); -void process_request_queue (); -#endif -static struct active_request_slot *get_active_slot (void ) {struct active_request_slot *slot = active_queue_head;
@@ -443,7 +440,7 @@ static void release_request(struct trans }#ifdef USE_CURL_MULTI -void process_curl_messages (void ) +static void process_curl_messages (void ) {int num_messages;struct active_request_slot *slot;
@@ -495,7 +492,7 @@ void process_curl_messages(void) } } -void process_request_queue (void ) +static void process_request_queue (void ) {struct transfer_request *request = request_queue_head;int num_transfers;
@@ -904,9 +901,6 @@ static int fetch_object(struct alt_basechar *hex =sha1_to_hex (sha1);int ret;struct transfer_request *request = request_queue_head; -#ifdef USE_CURL_MULTI -int num_transfers; -#endif while (request !=NULL &&memcmp (request->sha1, sha1,20 )) request = request->next;
@@ -920,6 +914,7 @@ static int fetch_object(struct alt_base#ifdef USE_CURL_MULTI while (request->state ==WAITING ) { +int num_transfers;curl_multi_perform (curlm, &num_transfers);if (num_transfers < active_requests) {process_curl_messages ();
Compilation finished at Thu Oct 13 11:14:23