]> git.ipfire.org Git - thirdparty/git.git/blobdiff - http-walker.c
describe: fix --no-exact-match
[thirdparty/git.git] / http-walker.c
index 90d8ecb57ef8629e1691f7e785fea1446c09017c..bba306b2d5e18b94aaa41e8fdce30321034feaea 100644 (file)
@@ -1,6 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "repository.h"
 #include "commit.h"
+#include "hex.h"
 #include "walker.h"
 #include "http.h"
 #include "list.h"
@@ -52,14 +53,13 @@ static void fetch_alternates(struct walker *walker, const char *base);
 
 static void process_object_response(void *callback_data);
 
-static void start_object_request(struct walker *walker,
-                                struct object_request *obj_req)
+static void start_object_request(struct object_request *obj_req)
 {
        struct active_request_slot *slot;
        struct http_object_request *req;
 
        req = new_http_object_request(obj_req->repo->base, &obj_req->oid);
-       if (req == NULL) {
+       if (!req) {
                obj_req->state = ABORTED;
                return;
        }
@@ -106,11 +106,11 @@ static void process_object_response(void *callback_data)
        /* Use alternates if necessary */
        if (missing_target(obj_req->req)) {
                fetch_alternates(walker, alt->base);
-               if (obj_req->repo->next != NULL) {
+               if (obj_req->repo->next) {
                        obj_req->repo =
                                obj_req->repo->next;
                        release_http_object_request(obj_req->req);
-                       start_object_request(walker, obj_req);
+                       start_object_request(obj_req);
                        return;
                }
        }
@@ -127,8 +127,7 @@ static void release_object_request(struct object_request *obj_req)
        free(obj_req);
 }
 
-#ifdef USE_CURL_MULTI
-static int fill_active_slot(struct walker *walker)
+static int fill_active_slot(void *data UNUSED)
 {
        struct object_request *obj_req;
        struct list_head *pos, *tmp, *head = &object_queue_head;
@@ -136,17 +135,16 @@ static int fill_active_slot(struct walker *walker)
        list_for_each_safe(pos, tmp, head) {
                obj_req = list_entry(pos, struct object_request, node);
                if (obj_req->state == WAITING) {
-                       if (has_object_file(&obj_req->oid))
+                       if (repo_has_object_file(the_repository, &obj_req->oid))
                                obj_req->state = COMPLETE;
                        else {
-                               start_object_request(walker, obj_req);
+                               start_object_request(obj_req);
                                return 1;
                        }
                }
        }
        return 0;
 }
-#endif
 
 static void prefetch(struct walker *walker, unsigned char *sha1)
 {
@@ -163,10 +161,8 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
        http_is_verbose = walker->get_verbosely;
        list_add_tail(&newreq->node, &object_queue_head);
 
-#ifdef USE_CURL_MULTI
        fill_active_slots();
        step_active_slots();
-#endif
 }
 
 static int is_alternate_allowed(const char *url)
@@ -229,12 +225,12 @@ static void process_alternates_response(void *callback_data)
                                         alt_req->url->buf);
                        active_requests++;
                        slot->in_use = 1;
-                       if (slot->finished != NULL)
+                       if (slot->finished)
                                (*slot->finished) = 0;
                        if (!start_active_slot(slot)) {
                                cdata->got_alternates = -1;
                                slot->in_use = 0;
-                               if (slot->finished != NULL)
+                               if (slot->finished)
                                        (*slot->finished) = 1;
                        }
                        return;
@@ -357,11 +353,9 @@ static void fetch_alternates(struct walker *walker, const char *base)
         * wait for them to arrive and return to processing this request's
         * curl message
         */
-#ifdef USE_CURL_MULTI
        while (cdata->got_alternates == 0) {
                step_active_slots();
        }
-#endif
 
        /* Nothing to do if they've already been fetched */
        if (cdata->got_alternates == 1)
@@ -384,7 +378,7 @@ static void fetch_alternates(struct walker *walker, const char *base)
        alt_req.walker = walker;
        slot->callback_data = &alt_req;
 
-       curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
+       curl_easy_setopt(slot->curl, CURLOPT_WRITEDATA, &buffer);
        curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
        curl_easy_setopt(slot->curl, CURLOPT_URL, url.buf);
 
@@ -449,7 +443,7 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigne
        }
 
        preq = new_http_pack_request(target->hash, repo->base);
-       if (preq == NULL)
+       if (!preq)
                goto abort;
        preq->slot->results = &results;
 
@@ -495,22 +489,18 @@ static int fetch_object(struct walker *walker, unsigned char *hash)
                if (hasheq(obj_req->oid.hash, hash))
                        break;
        }
-       if (obj_req == NULL)
+       if (!obj_req)
                return error("Couldn't find request for %s in the queue", hex);
 
-       if (has_object_file(&obj_req->oid)) {
-               if (obj_req->req != NULL)
+       if (repo_has_object_file(the_repository, &obj_req->oid)) {
+               if (obj_req->req)
                        abort_http_object_request(obj_req->req);
                abort_object_request(obj_req);
                return 0;
        }
 
-#ifdef USE_CURL_MULTI
        while (obj_req->state == WAITING)
                step_active_slots();
-#else
-       start_object_request(walker, obj_req);
-#endif
 
        /*
         * obj_req->req might change when fetching alternates in the callback
@@ -623,9 +613,7 @@ struct walker *get_http_walker(const char *url)
        walker->cleanup = cleanup;
        walker->data = data;
 
-#ifdef USE_CURL_MULTI
-       add_fill_function(walker, (int (*)(void *)) fill_active_slot);
-#endif
+       add_fill_function(NULL, fill_active_slot);
 
        return walker;
 }