Git fork

http-walker: use object_id instead of bare hash

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>

authored by

Jeff King and committed by
Taylor Blau
0af861e0 6b2fc220

+17 -16
+13 -12
http-walker.c
··· 147 147 return 0; 148 148 } 149 149 150 - static void prefetch(struct walker *walker, unsigned char *sha1) 150 + static void prefetch(struct walker *walker, const struct object_id *oid) 151 151 { 152 152 struct object_request *newreq; 153 153 struct walker_data *data = walker->data; 154 154 155 155 newreq = xmalloc(sizeof(*newreq)); 156 156 newreq->walker = walker; 157 - oidread(&newreq->oid, sha1, the_repository->hash_algo); 157 + oidcpy(&newreq->oid, oid); 158 158 newreq->repo = data->alt; 159 159 newreq->state = WAITING; 160 160 newreq->req = NULL; ··· 422 422 return ret; 423 423 } 424 424 425 - static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigned char *sha1) 425 + static int http_fetch_pack(struct walker *walker, struct alt_base *repo, 426 + const struct object_id *oid) 426 427 { 427 428 struct packed_git *target; 428 429 int ret; ··· 431 432 432 433 if (fetch_indices(walker, repo)) 433 434 return -1; 434 - target = find_sha1_pack(sha1, repo->packs); 435 + target = find_sha1_pack(oid->hash, repo->packs); 435 436 if (!target) 436 437 return -1; 437 438 close_pack_index(target); ··· 440 441 fprintf(stderr, "Getting pack %s\n", 441 442 hash_to_hex(target->hash)); 442 443 fprintf(stderr, " which contains %s\n", 443 - hash_to_hex(sha1)); 444 + oid_to_hex(oid)); 444 445 } 445 446 446 447 preq = new_http_pack_request(target->hash, repo->base); ··· 477 478 release_object_request(obj_req); 478 479 } 479 480 480 - static int fetch_object(struct walker *walker, unsigned char *hash) 481 + static int fetch_object(struct walker *walker, const struct object_id *oid) 481 482 { 482 - char *hex = hash_to_hex(hash); 483 + char *hex = oid_to_hex(oid); 483 484 int ret = 0; 484 485 struct object_request *obj_req = NULL; 485 486 struct http_object_request *req; ··· 487 488 488 489 list_for_each(pos, head) { 489 490 obj_req = list_entry(pos, struct object_request, node); 490 - if (hasheq(obj_req->oid.hash, hash, the_repository->hash_algo)) 491 + if (oideq(&obj_req->oid, oid)) 491 492 break; 492 493 } 493 494 if (!obj_req) ··· 548 549 return ret; 549 550 } 550 551 551 - static int fetch(struct walker *walker, unsigned char *hash) 552 + static int fetch(struct walker *walker, const struct object_id *oid) 552 553 { 553 554 struct walker_data *data = walker->data; 554 555 struct alt_base *altbase = data->alt; 555 556 556 - if (!fetch_object(walker, hash)) 557 + if (!fetch_object(walker, oid)) 557 558 return 0; 558 559 while (altbase) { 559 - if (!http_fetch_pack(walker, altbase, hash)) 560 + if (!http_fetch_pack(walker, altbase, oid)) 560 561 return 0; 561 562 fetch_alternates(walker, data->alt->base); 562 563 altbase = altbase->next; 563 564 } 564 - return error("Unable to find %s under %s", hash_to_hex(hash), 565 + return error("Unable to find %s under %s", oid_to_hex(oid), 565 566 data->alt->base); 566 567 } 567 568
+2 -2
walker.c
··· 157 157 else { 158 158 if (obj->flags & COMPLETE) 159 159 return 0; 160 - walker->prefetch(walker, obj->oid.hash); 160 + walker->prefetch(walker, &obj->oid); 161 161 } 162 162 163 163 object_list_insert(obj, process_queue_end); ··· 186 186 * the queue because we needed to fetch it first. 187 187 */ 188 188 if (! (obj->flags & TO_SCAN)) { 189 - if (walker->fetch(walker, obj->oid.hash)) { 189 + if (walker->fetch(walker, &obj->oid)) { 190 190 stop_progress(&progress); 191 191 report_missing(obj); 192 192 return -1;
+2 -2
walker.h
··· 6 6 struct walker { 7 7 void *data; 8 8 int (*fetch_ref)(struct walker *, struct ref *ref); 9 - void (*prefetch)(struct walker *, unsigned char *sha1); 10 - int (*fetch)(struct walker *, unsigned char *sha1); 9 + void (*prefetch)(struct walker *, const struct object_id *oid); 10 + int (*fetch)(struct walker *, const struct object_id *oid); 11 11 void (*cleanup)(struct walker *); 12 12 int get_verbosely; 13 13 int get_progress;