]> git.ipfire.org Git - thirdparty/git.git/commitdiff
http: use struct object_id instead of bare sha1
authorJeff King <peff@peff.net>
Mon, 7 Jan 2019 08:34:40 +0000 (03:34 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Jan 2019 17:40:19 +0000 (09:40 -0800)
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>
http-push.c
http-walker.c
http.c
http.h

index cd485909127a79afcbb58ef18cd28977b65efb79..0141b0ad537589296a43bff2b99df148e7346b91 100644 (file)
@@ -255,7 +255,7 @@ static void start_fetch_loose(struct transfer_request *request)
        struct active_request_slot *slot;
        struct http_object_request *obj_req;
 
-       obj_req = new_http_object_request(repo->url, request->obj->oid.hash);
+       obj_req = new_http_object_request(repo->url, &request->obj->oid);
        if (obj_req == NULL) {
                request->state = ABORTED;
                return;
index 0a392c85b67af254ddeca382faa79458c4ec3ca8..856716c63d0c1c806b63ec3f8c655b43fc23a403 100644 (file)
@@ -58,7 +58,7 @@ static void start_object_request(struct walker *walker,
        struct active_request_slot *slot;
        struct http_object_request *req;
 
-       req = new_http_object_request(obj_req->repo->base, obj_req->oid.hash);
+       req = new_http_object_request(obj_req->repo->base, &obj_req->oid);
        if (req == NULL) {
                obj_req->state = ABORTED;
                return;
@@ -543,11 +543,11 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
        } else if (req->zret != Z_STREAM_END) {
                walker->corrupt_object_found++;
                ret = error("File %s (%s) corrupt", hex, req->url);
-       } else if (!hasheq(obj_req->oid.hash, req->real_sha1)) {
+       } else if (!oideq(&obj_req->oid, &req->real_oid)) {
                ret = error("File %s has bad hash", hex);
        } else if (req->rename < 0) {
                struct strbuf buf = STRBUF_INIT;
-               loose_object_path(the_repository, &buf, req->sha1);
+               loose_object_path(the_repository, &buf, req->oid.hash);
                ret = error("unable to write sha1 filename %s", buf.buf);
                strbuf_release(&buf);
        }
diff --git a/http.c b/http.c
index 0b6807cef9aa0994be486581ecf18f7829ee4e19..8d42154792094fb2abdbb050fe5192bb271deadd 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2337,9 +2337,9 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
 }
 
 struct http_object_request *new_http_object_request(const char *base_url,
-       unsigned char *sha1)
+                                                   const struct object_id *oid)
 {
-       char *hex = sha1_to_hex(sha1);
+       char *hex = oid_to_hex(oid);
        struct strbuf filename = STRBUF_INIT;
        struct strbuf prevfile = STRBUF_INIT;
        int prevlocal;
@@ -2350,10 +2350,10 @@ struct http_object_request *new_http_object_request(const char *base_url,
 
        freq = xcalloc(1, sizeof(*freq));
        strbuf_init(&freq->tmpfile, 0);
-       hashcpy(freq->sha1, sha1);
+       oidcpy(&freq->oid, oid);
        freq->localfile = -1;
 
-       loose_object_path(the_repository, &filename, sha1);
+       loose_object_path(the_repository, &filename, oid->hash);
        strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
 
        strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ -2495,16 +2495,16 @@ int finish_http_object_request(struct http_object_request *freq)
        }
 
        git_inflate_end(&freq->stream);
-       git_SHA1_Final(freq->real_sha1, &freq->c);
+       git_SHA1_Final(freq->real_oid.hash, &freq->c);
        if (freq->zret != Z_STREAM_END) {
                unlink_or_warn(freq->tmpfile.buf);
                return -1;
        }
-       if (!hasheq(freq->sha1, freq->real_sha1)) {
+       if (!oideq(&freq->oid, &freq->real_oid)) {
                unlink_or_warn(freq->tmpfile.buf);
                return -1;
        }
-       loose_object_path(the_repository, &filename, freq->sha1);
+       loose_object_path(the_repository, &filename, freq->oid.hash);
        freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
        strbuf_release(&filename);
 
diff --git a/http.h b/http.h
index d305ca1dc7a3f931a81353c56060e98f4039c692..66c52b2e1e7dcf0f7ea27d056b8d144cb5375cf2 100644 (file)
--- a/http.h
+++ b/http.h
@@ -224,8 +224,8 @@ struct http_object_request {
        CURLcode curl_result;
        char errorstr[CURL_ERROR_SIZE];
        long http_code;
-       unsigned char sha1[20];
-       unsigned char real_sha1[20];
+       struct object_id oid;
+       struct object_id real_oid;
        git_SHA_CTX c;
        git_zstream stream;
        int zret;
@@ -234,7 +234,7 @@ struct http_object_request {
 };
 
 extern struct http_object_request *new_http_object_request(
-       const char *base_url, unsigned char *sha1);
+       const char *base_url, const struct object_id *oid);
 extern void process_http_object_request(struct http_object_request *freq);
 extern int finish_http_object_request(struct http_object_request *freq);
 extern void abort_http_object_request(struct http_object_request *freq);