http-push, http-walker: style fixes
[gitweb.git] / http-push.c
index 29e8ebfebb8947cc76b5631ae143d0003e5b3d51..64c9bb0f90d70c414aa9cbb15f188789ce087ad1 100644 (file)
@@ -276,7 +276,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
        struct transfer_request *request = (struct transfer_request *)data;
        do {
                ssize_t retval = xwrite(request->local_fileno,
-                                      (char *) ptr + posn, size - posn);
+                                       (char *) ptr + posn, size - posn);
                if (retval < 0)
                        return posn;
                posn += retval;
@@ -289,7 +289,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
                request->stream.avail_out = sizeof(expn);
                request->zret = git_inflate(&request->stream, Z_SYNC_FLUSH);
                git_SHA1_Update(&request->c, expn,
-                           sizeof(expn) - request->stream.avail_out);
+                               sizeof(expn) - request->stream.avail_out);
        } while (request->stream.avail_in && request->zret == Z_OK);
        data_received++;
        return size;
@@ -323,7 +323,8 @@ static void start_fetch_loose(struct transfer_request *request)
                error("fd leakage in start: %d", request->local_fileno);
        request->local_fileno = open(request->tmpfile,
                                     O_WRONLY | O_CREAT | O_EXCL, 0666);
-       /* This could have failed due to the "lazy directory creation";
+       /*
+        * This could have failed due to the "lazy directory creation";
         * try to mkdir the last path component.
         */
        if (request->local_fileno < 0 && errno == ENOENT) {
@@ -353,8 +354,10 @@ static void start_fetch_loose(struct transfer_request *request)
        url = get_remote_object_url(repo->url, hex, 0);
        request->url = xstrdup(url);
 
-       /* If a previous temp file is present, process what was already
-          fetched. */
+       /*
+        * If a previous temp file is present, process what was already
+        * fetched.
+        */
        prevlocal = open(prevfile, O_RDONLY);
        if (prevlocal != -1) {
                do {
@@ -363,19 +366,20 @@ static void start_fetch_loose(struct transfer_request *request)
                                if (fwrite_sha1_file(prev_buf,
                                                     1,
                                                     prev_read,
-                                                    request) == prev_read) {
+                                                    request) == prev_read)
                                        prev_posn += prev_read;
-                               } else {
+                               else
                                        prev_read = -1;
-                               }
                        }
                } while (prev_read > 0);
                close(prevlocal);
        }
        unlink_or_warn(prevfile);
 
-       /* Reset inflate/SHA1 if there was an error reading the previous temp
-          file; also rewind to the beginning of the local file. */
+       /*
+        * Reset inflate/SHA1 if there was an error reading the previous temp
+        * file; also rewind to the beginning of the local file.
+        */
        if (prev_read == -1) {
                memset(&request->stream, 0, sizeof(request->stream));
                git_inflate_init(&request->stream);
@@ -398,8 +402,10 @@ static void start_fetch_loose(struct transfer_request *request)
        curl_easy_setopt(slot->curl, CURLOPT_URL, url);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
 
-       /* If we have successfully processed data from a previous fetch
-          attempt, only fetch the data we don't already have. */
+       /*
+        * If we have successfully processed data from a previous fetch
+        * attempt, only fetch the data we don't already have.
+        */
        if (prev_posn>0) {
                if (push_verbosely)
                        fprintf(stderr,
@@ -514,8 +520,10 @@ static void start_fetch_packed(struct transfer_request *request)
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
        slot->local = packfile;
 
-       /* If there is data present from a previous transfer attempt,
-          resume where it left off */
+       /*
+        * If there is data present from a previous transfer attempt,
+        * resume where it left off
+        */
        prev_posn = ftell(packfile);
        if (prev_posn>0) {
                if (push_verbosely)
@@ -724,9 +732,11 @@ static void finish_request(struct transfer_request *request)
        struct stat st;
        struct packed_git *target;
        struct packed_git **lst;
+       struct active_request_slot *slot;
 
        request->curl_result = request->slot->curl_result;
        request->http_code = request->slot->http_code;
+       slot = request->slot;
        request->slot = NULL;
 
        /* Keep locks active */
@@ -778,7 +788,8 @@ static void finish_request(struct transfer_request *request)
                        aborted = 1;
                }
        } else if (request->state == RUN_FETCH_LOOSE) {
-               close(request->local_fileno); request->local_fileno = -1;
+               close(request->local_fileno);
+               request->local_fileno = -1;
 
                if (request->curl_result != CURLE_OK &&
                    request->http_code != 416) {
@@ -801,9 +812,8 @@ static void finish_request(struct transfer_request *request)
                                        move_temp_to_file(
                                                request->tmpfile,
                                                request->filename);
-                               if (request->rename == 0) {
+                               if (request->rename == 0)
                                        request->obj->flags |= (LOCAL | REMOTE);
-                               }
                        }
                }
 
@@ -823,6 +833,7 @@ static void finish_request(struct transfer_request *request)
 
                        fclose(request->local_stream);
                        request->local_stream = NULL;
+                       slot->local = NULL;
                        if (!move_temp_to_file(request->tmpfile,
                                               request->filename)) {
                                target = (struct packed_git *)request->userData;
@@ -843,11 +854,12 @@ static void finish_request(struct transfer_request *request)
 }
 
 #ifdef USE_CURL_MULTI
+static int is_running_queue;
 static int fill_active_slot(void *unused)
 {
        struct transfer_request *request;
 
-       if (aborted)
+       if (aborted || !is_running_queue)
                return 0;
 
        for (request = request_queue_head; request; request = request->next) {
@@ -1006,8 +1018,10 @@ static int fetch_index(unsigned char *sha1)
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
        slot->local = indexfile;
 
-       /* If there is data present from a previous transfer attempt,
-          resume where it left off */
+       /*
+        * If there is data present from a previous transfer attempt,
+        * resume where it left off
+        */
        prev_posn = ftell(indexfile);
        if (prev_posn>0) {
                if (push_verbosely)
@@ -1024,17 +1038,20 @@ static int fetch_index(unsigned char *sha1)
                if (results.curl_result != CURLE_OK) {
                        free(url);
                        fclose(indexfile);
+                       slot->local = NULL;
                        return error("Unable to get pack index %s\n%s", url,
                                     curl_errorstr);
                }
        } else {
                free(url);
                fclose(indexfile);
+               slot->local = NULL;
                return error("Unable to start request");
        }
 
        free(url);
        fclose(indexfile);
+       slot->local = NULL;
 
        return move_temp_to_file(tmpfile, filename);
 }
@@ -2167,6 +2184,25 @@ static int delete_remote_branch(char *pattern, int force)
        return 0;
 }
 
+void run_request_queue(void)
+{
+#ifdef USE_CURL_MULTI
+       is_running_queue = 1;
+       fill_active_slots();
+       add_fill_function(NULL, fill_active_slot);
+#endif
+       do {
+               finish_all_active_slots();
+#ifdef USE_CURL_MULTI
+               fill_active_slots();
+#endif
+       } while (request_queue_head && !aborted);
+
+#ifdef USE_CURL_MULTI
+       is_running_queue = 0;
+#endif
+}
+
 int main(int argc, char **argv)
 {
        struct transfer_request *request;
@@ -2271,6 +2307,10 @@ int main(int argc, char **argv)
                repo->url = rewritten_url;
        }
 
+#ifdef USE_CURL_MULTI
+       is_running_queue = 0;
+#endif
+
        /* Verify DAV compliance/lock support */
        if (!locking_available()) {
                rc = 1;
@@ -2300,6 +2340,7 @@ int main(int argc, char **argv)
        local_refs = get_local_heads();
        fprintf(stderr, "Fetching remote heads...\n");
        get_dav_remote_heads();
+       run_request_queue();
 
        /* Remove a remote branch if -d or -D was specified */
        if (delete_branch) {
@@ -2429,16 +2470,8 @@ int main(int argc, char **argv)
                if (objects_to_send)
                        fprintf(stderr, "    sending %d objects\n",
                                objects_to_send);
-#ifdef USE_CURL_MULTI
-               fill_active_slots();
-               add_fill_function(NULL, fill_active_slot);
-#endif
-               do {
-                       finish_all_active_slots();
-#ifdef USE_CURL_MULTI
-                       fill_active_slots();
-#endif
-               } while (request_queue_head && !aborted);
+
+               run_request_queue();
 
                /* Update the remote branch if all went well */
                if (aborted || !update_remote(ref->new_sha1, ref_lock))