Debian: packaging updates.
[gitweb.git] / http-fetch.c
index ed1053ade3e7e71251bfcf890cb304c7ce928222..ea8af1b2defaf7e11dff0a09952234f3c7626376 100644 (file)
@@ -520,12 +520,17 @@ static void start_request(struct transfer_request *request)
 
 static void finish_request(struct transfer_request *request)
 {
+       struct stat st;
+
        fchmod(request->local, 0444);
        close(request->local);
 
        if (request->http_code == 416) {
                fprintf(stderr, "Warning: requested range invalid; we may already have all the data.\n");
        } else if (request->curl_result != CURLE_OK) {
+               if (stat(request->tmpfile, &st) == 0)
+                       if (st.st_size == 0)
+                               unlink(request->tmpfile);
                return;
        }
 
@@ -573,6 +578,7 @@ void process_curl_messages(void)
 
        while (curl_message != NULL) {
                if (curl_message->msg == CURLMSG_DONE) {
+                       int curl_result = curl_message->data.result;
                        slot = active_queue_head;
                        while (slot != NULL &&
                               slot->curl != curl_message->easy_handle)
@@ -582,7 +588,7 @@ void process_curl_messages(void)
                                active_requests--;
                                slot->done = 1;
                                slot->in_use = 0;
-                               slot->curl_result = curl_message->data.result;
+                               slot->curl_result = curl_result;
                                curl_easy_getinfo(slot->curl,
                                                  CURLINFO_HTTP_CODE,
                                                  &slot->http_code);
@@ -594,8 +600,7 @@ void process_curl_messages(void)
                                fprintf(stderr, "Received DONE message for unknown request!\n");
                        }
                        if (request != NULL) {
-                               request->curl_result =
-                                       curl_message->data.result;
+                               request->curl_result = curl_result;
                                request->http_code = slot->http_code;
                                request->slot = NULL;
                                request->state = COMPLETE;
@@ -1095,9 +1100,12 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
        }
 
        if (request->curl_result != CURLE_OK && request->http_code != 416) {
-               ret = error("%s (curl_result = %d, http_code = %ld, sha1 = %s)",
-                           request->errorstr, request->curl_result,
-                           request->http_code, hex);
+               if (request->http_code == 404)
+                       ret = -1; /* Be silent, it is probably in a pack. */
+               else
+                       ret = error("%s (curl_result = %d, http_code = %ld, sha1 = %s)",
+                                   request->errorstr, request->curl_result,
+                                   request->http_code, hex);
                release_request(request);
                return ret;
        }
@@ -1226,6 +1234,8 @@ int main(int argc, char **argv)
        struct active_request_slot *slot;
        char *low_speed_limit;
        char *low_speed_time;
+       char *wait_url;
+       int rc = 0;
 
        while (arg < argc && argv[arg][0] == '-') {
                if (argv[arg][1] == 't') {
@@ -1313,7 +1323,7 @@ int main(int argc, char **argv)
        alt->next = NULL;
 
        if (pull(commit_id))
-               return 1;
+               rc = 1;
 
        curl_slist_free_all(pragma_header);
        curl_slist_free_all(no_pragma_header);
@@ -1323,6 +1333,15 @@ int main(int argc, char **argv)
 #endif
        slot = active_queue_head;
        while (slot != NULL) {
+               if (slot->in_use) {
+                       if (get_verbosely) {
+                               curl_easy_getinfo(slot->curl,
+                                                 CURLINFO_EFFECTIVE_URL,
+                                                 &wait_url);
+                               fprintf(stderr, "Waiting for %s\n", wait_url);
+                       }
+                       run_active_slot(slot);
+               }
                if (slot->curl != NULL)
                        curl_easy_cleanup(slot->curl);
                slot = slot->next;
@@ -1331,5 +1350,5 @@ int main(int argc, char **argv)
        curl_multi_cleanup(curlm);
 #endif
        curl_global_cleanup();
-       return 0;
+       return rc;
 }