Skip to content

Commit 0af861e

Browse files
peffttaylorr
authored andcommitted
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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 6b2fc22 commit 0af861e

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

http-walker.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ static int fill_active_slot(void *data UNUSED)
147147
return 0;
148148
}
149149

150-
static void prefetch(struct walker *walker, unsigned char *sha1)
150+
static void prefetch(struct walker *walker, const struct object_id *oid)
151151
{
152152
struct object_request *newreq;
153153
struct walker_data *data = walker->data;
154154

155155
newreq = xmalloc(sizeof(*newreq));
156156
newreq->walker = walker;
157-
oidread(&newreq->oid, sha1, the_repository->hash_algo);
157+
oidcpy(&newreq->oid, oid);
158158
newreq->repo = data->alt;
159159
newreq->state = WAITING;
160160
newreq->req = NULL;
@@ -422,7 +422,8 @@ static int fetch_indices(struct walker *walker, struct alt_base *repo)
422422
return ret;
423423
}
424424

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)
426427
{
427428
struct packed_git *target;
428429
int ret;
@@ -431,7 +432,7 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigne
431432

432433
if (fetch_indices(walker, repo))
433434
return -1;
434-
target = find_sha1_pack(sha1, repo->packs);
435+
target = find_sha1_pack(oid->hash, repo->packs);
435436
if (!target)
436437
return -1;
437438
close_pack_index(target);
@@ -440,7 +441,7 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigne
440441
fprintf(stderr, "Getting pack %s\n",
441442
hash_to_hex(target->hash));
442443
fprintf(stderr, " which contains %s\n",
443-
hash_to_hex(sha1));
444+
oid_to_hex(oid));
444445
}
445446

446447
preq = new_http_pack_request(target->hash, repo->base);
@@ -477,17 +478,17 @@ static void abort_object_request(struct object_request *obj_req)
477478
release_object_request(obj_req);
478479
}
479480

480-
static int fetch_object(struct walker *walker, unsigned char *hash)
481+
static int fetch_object(struct walker *walker, const struct object_id *oid)
481482
{
482-
char *hex = hash_to_hex(hash);
483+
char *hex = oid_to_hex(oid);
483484
int ret = 0;
484485
struct object_request *obj_req = NULL;
485486
struct http_object_request *req;
486487
struct list_head *pos, *head = &object_queue_head;
487488

488489
list_for_each(pos, head) {
489490
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))
491492
break;
492493
}
493494
if (!obj_req)
@@ -548,20 +549,20 @@ static int fetch_object(struct walker *walker, unsigned char *hash)
548549
return ret;
549550
}
550551

551-
static int fetch(struct walker *walker, unsigned char *hash)
552+
static int fetch(struct walker *walker, const struct object_id *oid)
552553
{
553554
struct walker_data *data = walker->data;
554555
struct alt_base *altbase = data->alt;
555556

556-
if (!fetch_object(walker, hash))
557+
if (!fetch_object(walker, oid))
557558
return 0;
558559
while (altbase) {
559-
if (!http_fetch_pack(walker, altbase, hash))
560+
if (!http_fetch_pack(walker, altbase, oid))
560561
return 0;
561562
fetch_alternates(walker, data->alt->base);
562563
altbase = altbase->next;
563564
}
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),
565566
data->alt->base);
566567
}
567568

walker.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static int process(struct walker *walker, struct object *obj)
157157
else {
158158
if (obj->flags & COMPLETE)
159159
return 0;
160-
walker->prefetch(walker, obj->oid.hash);
160+
walker->prefetch(walker, &obj->oid);
161161
}
162162

163163
object_list_insert(obj, process_queue_end);
@@ -186,7 +186,7 @@ static int loop(struct walker *walker)
186186
* the queue because we needed to fetch it first.
187187
*/
188188
if (! (obj->flags & TO_SCAN)) {
189-
if (walker->fetch(walker, obj->oid.hash)) {
189+
if (walker->fetch(walker, &obj->oid)) {
190190
stop_progress(&progress);
191191
report_missing(obj);
192192
return -1;

walker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
struct walker {
77
void *data;
88
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);
1111
void (*cleanup)(struct walker *);
1212
int get_verbosely;
1313
int get_progress;

0 commit comments

Comments
 (0)