http: use struct object_id instead of bare sha1
The dumb-http walker code still passes around and stores object ids as "unsigned char *sha1". Let's modernize it. There's probably still more work to be done to handle dumb-http fetches with a new, larger hash. But that can wait; this is enough that we can now convert some of the low-level object routines that we call into from here (and in fact, some of the "oid.hash" references added here will be further improved in the next patch). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jan 7, 2019 at 03:34 UTC
f0be0db13dbd2d96d2240374e0e9cb106bf6a614
4 files changed
+14
-14
http-push.c
+1
-1
@@ -255,7 +255,7 @@ static void start_fetch_loose(struct transfer_request *request)
255
struct active_request_slot *slot;
256
struct http_object_request *obj_req;
257
258
- obj_req = new_http_object_request(repo->url, request->obj->oid.hash);
258
+ obj_req = new_http_object_request(repo->url, &request->obj->oid);
259
if (obj_req == NULL) {
260
request->state = ABORTED;
261
return;
http-walker.c
+3
-3
@@ -58,7 +58,7 @@ static void start_object_request(struct walker *walker,
58
struct active_request_slot *slot;
59
struct http_object_request *req;
60
61
- req = new_http_object_request(obj_req->repo->base, obj_req->oid.hash);
61
+ req = new_http_object_request(obj_req->repo->base, &obj_req->oid);
62
if (req == NULL) {
63
obj_req->state = ABORTED;
64
return;
@@ -543,11 +543,11 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
543
} else if (req->zret != Z_STREAM_END) {
544
walker->corrupt_object_found++;
545
ret = error("File %s (%s) corrupt", hex, req->url);
546
- } else if (!hasheq(obj_req->oid.hash, req->real_sha1)) {
546
+ } else if (!oideq(&obj_req->oid, &req->real_oid)) {
547
ret = error("File %s has bad hash", hex);
548
} else if (req->rename < 0) {
549
struct strbuf buf = STRBUF_INIT;
550
- loose_object_path(the_repository, &buf, req->sha1);
550
+ loose_object_path(the_repository, &buf, req->oid.hash);
551
ret = error("unable to write sha1 filename %s", buf.buf);
552
strbuf_release(&buf);
553
}
http.c
+7
-7
@@ -2337,9 +2337,9 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
2337
}
2338
2339
struct http_object_request *new_http_object_request(const char *base_url,
2340
- unsigned char *sha1)
2340
+ const struct object_id *oid)
2341
{
2342
- char *hex = sha1_to_hex(sha1);
2342
+ char *hex = oid_to_hex(oid);
2343
struct strbuf filename = STRBUF_INIT;
2344
struct strbuf prevfile = STRBUF_INIT;
2345
int prevlocal;
@@ -2350,10 +2350,10 @@ struct http_object_request *new_http_object_request(const char *base_url,
2350
2351
freq = xcalloc(1, sizeof(*freq));
2352
strbuf_init(&freq->tmpfile, 0);
2353
- hashcpy(freq->sha1, sha1);
2353
+ oidcpy(&freq->oid, oid);
2354
freq->localfile = -1;
2355
2356
- loose_object_path(the_repository, &filename, sha1);
2356
+ loose_object_path(the_repository, &filename, oid->hash);
2357
strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
2358
2359
strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ -2495,16 +2495,16 @@ int finish_http_object_request(struct http_object_request *freq)
2495
}
2496
2497
git_inflate_end(&freq->stream);
2498
- git_SHA1_Final(freq->real_sha1, &freq->c);
2498
+ git_SHA1_Final(freq->real_oid.hash, &freq->c);
2499
if (freq->zret != Z_STREAM_END) {
2500
unlink_or_warn(freq->tmpfile.buf);
2501
return -1;
2502
}
2503
- if (!hasheq(freq->sha1, freq->real_sha1)) {
2503
+ if (!oideq(&freq->oid, &freq->real_oid)) {
2504
unlink_or_warn(freq->tmpfile.buf);
2505
return -1;
2506
}
2507
- loose_object_path(the_repository, &filename, freq->sha1);
2507
+ loose_object_path(the_repository, &filename, freq->oid.hash);
2508
freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
2509
strbuf_release(&filename);
2510
http.h
+3
-3
@@ -224,8 +224,8 @@ struct http_object_request {
224
CURLcode curl_result;
225
char errorstr[CURL_ERROR_SIZE];
226
long http_code;
227
- unsigned char sha1[20];
228
- unsigned char real_sha1[20];
227
+ struct object_id oid;
228
+ struct object_id real_oid;
229
git_SHA_CTX c;
230
git_zstream stream;
231
int zret;
@@ -234,7 +234,7 @@ struct http_object_request {
234
};
235
236
extern struct http_object_request *new_http_object_request(
237
- const char *base_url, unsigned char *sha1);
237
+ const char *base_url, const struct object_id *oid);
238
extern void process_http_object_request(struct http_object_request *freq);
239
extern int finish_http_object_request(struct http_object_request *freq);
240
extern void abort_http_object_request(struct http_object_request *freq);