]> git.ipfire.org Git - thirdparty/git.git/commitdiff
http-walker: use object_id instead of bare hash
authorJeff King <peff@peff.net>
Fri, 25 Oct 2024 07:03:42 +0000 (03:03 -0400)
committerTaylor Blau <me@ttaylorr.com>
Fri, 25 Oct 2024 21:35:46 +0000 (17:35 -0400)
We long ago switched most code to using object_id structs instead of
bare "unsigned char *" hashes. This gives us more type safety from the
compiler, and generally makes it easier to understand what we expect in
each parameter.

But the dumb-http code has lagged behind. And indeed, the whole "walker"
subsystem interface has the same problem, though http-walker is the only
user left.

So let's update the walker interface to pass object_id structs (which we
already have anyway at all call sites!), and likewise use those within
the http-walker methods that it calls.

This cleans up the dumb-http code a bit, but will also let us fix a few
more commonly used helper functions.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
http-walker.c
walker.c
walker.h

index fb2d86d5e70f0e3b7a12ac74d910e032dff9a3a7..36dd1f33c0fe8156bd2eec5023eef1bb00a5838e 100644 (file)
@@ -147,14 +147,14 @@ static int fill_active_slot(void *data UNUSED)
        return 0;
 }
 
-static void prefetch(struct walker *walker, unsigned char *sha1)
+static void prefetch(struct walker *walker, const struct object_id *oid)
 {
        struct object_request *newreq;
        struct walker_data *data = walker->data;
 
        newreq = xmalloc(sizeof(*newreq));
        newreq->walker = walker;
-       oidread(&newreq->oid, sha1, the_repository->hash_algo);
+       oidcpy(&newreq->oid, oid);
        newreq->repo = data->alt;
        newreq->state = WAITING;
        newreq->req = NULL;
@@ -422,7 +422,8 @@ static int fetch_indices(struct walker *walker, struct alt_base *repo)
        return ret;
 }
 
-static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigned char *sha1)
+static int http_fetch_pack(struct walker *walker, struct alt_base *repo,
+                          const struct object_id *oid)
 {
        struct packed_git *target;
        int ret;
@@ -431,7 +432,7 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigne
 
        if (fetch_indices(walker, repo))
                return -1;
-       target = find_sha1_pack(sha1, repo->packs);
+       target = find_sha1_pack(oid->hash, repo->packs);
        if (!target)
                return -1;
        close_pack_index(target);
@@ -440,7 +441,7 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigne
                fprintf(stderr, "Getting pack %s\n",
                        hash_to_hex(target->hash));
                fprintf(stderr, " which contains %s\n",
-                       hash_to_hex(sha1));
+                       oid_to_hex(oid));
        }
 
        preq = new_http_pack_request(target->hash, repo->base);
@@ -477,9 +478,9 @@ static void abort_object_request(struct object_request *obj_req)
        release_object_request(obj_req);
 }
 
-static int fetch_object(struct walker *walker, unsigned char *hash)
+static int fetch_object(struct walker *walker, const struct object_id *oid)
 {
-       char *hex = hash_to_hex(hash);
+       char *hex = oid_to_hex(oid);
        int ret = 0;
        struct object_request *obj_req = NULL;
        struct http_object_request *req;
@@ -487,7 +488,7 @@ static int fetch_object(struct walker *walker, unsigned char *hash)
 
        list_for_each(pos, head) {
                obj_req = list_entry(pos, struct object_request, node);
-               if (hasheq(obj_req->oid.hash, hash, the_repository->hash_algo))
+               if (oideq(&obj_req->oid, oid))
                        break;
        }
        if (!obj_req)
@@ -548,20 +549,20 @@ static int fetch_object(struct walker *walker, unsigned char *hash)
        return ret;
 }
 
-static int fetch(struct walker *walker, unsigned char *hash)
+static int fetch(struct walker *walker, const struct object_id *oid)
 {
        struct walker_data *data = walker->data;
        struct alt_base *altbase = data->alt;
 
-       if (!fetch_object(walker, hash))
+       if (!fetch_object(walker, oid))
                return 0;
        while (altbase) {
-               if (!http_fetch_pack(walker, altbase, hash))
+               if (!http_fetch_pack(walker, altbase, oid))
                        return 0;
                fetch_alternates(walker, data->alt->base);
                altbase = altbase->next;
        }
-       return error("Unable to find %s under %s", hash_to_hex(hash),
+       return error("Unable to find %s under %s", oid_to_hex(oid),
                     data->alt->base);
 }
 
index 807a7a388131fe98de6fb7f24e0921e8d46bc8d6..5ea7e5b392b2bd49f249a9acc8d7ce8779357e1b 100644 (file)
--- a/walker.c
+++ b/walker.c
@@ -157,7 +157,7 @@ static int process(struct walker *walker, struct object *obj)
        else {
                if (obj->flags & COMPLETE)
                        return 0;
-               walker->prefetch(walker, obj->oid.hash);
+               walker->prefetch(walker, &obj->oid);
        }
 
        object_list_insert(obj, process_queue_end);
@@ -186,7 +186,7 @@ static int loop(struct walker *walker)
                 * the queue because we needed to fetch it first.
                 */
                if (! (obj->flags & TO_SCAN)) {
-                       if (walker->fetch(walker, obj->oid.hash)) {
+                       if (walker->fetch(walker, &obj->oid)) {
                                stop_progress(&progress);
                                report_missing(obj);
                                return -1;
index d40b016bab87980d814571fe8fd96b0f69b495e2..25aaa3631c425853f9645a4f429fa88214fca08c 100644 (file)
--- a/walker.h
+++ b/walker.h
@@ -6,8 +6,8 @@
 struct walker {
        void *data;
        int (*fetch_ref)(struct walker *, struct ref *ref);
-       void (*prefetch)(struct walker *, unsigned char *sha1);
-       int (*fetch)(struct walker *, unsigned char *sha1);
+       void (*prefetch)(struct walker *, const struct object_id *oid);
+       int (*fetch)(struct walker *, const struct object_id *oid);
        void (*cleanup)(struct walker *);
        int get_verbosely;
        int get_progress;