sha1_file: convert check_sha1_signature to struct object_id
authorbrian m. carlson <sandals@crustytoothpaste.net>
Mon, 12 Mar 2018 02:27:39 +0000 (02:27 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Mar 2018 16:23:49 +0000 (09:23 -0700)
Convert this function to take a pointer to struct object_id and rename
it check_object_signature. Introduce temporaries to convert the return
values of lookup_replace_object and lookup_replace_object_extended into
struct object_id.

The temporaries are needed because in order to convert
lookup_replace_object, open_istream needs to be converted, and
open_istream needs check_sha1_signature to be converted, causing a loop
of dependencies. The temporaries will be removed in a future patch.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-export.c
builtin/index-pack.c
builtin/mktag.c
cache.h
object.c
pack-check.c
sha1_file.c
index 27b2cc138e67c013adbee3cbe152ca48c3d82ff5..9b049e9d081d16da0601f7e1bc112f6c3aad7a07 100644 (file)
@@ -240,7 +240,7 @@ static void export_blob(const struct object_id *oid)
                buf = read_sha1_file(oid->hash, &type, &size);
                if (!buf)
                        die ("Could not read blob %s", oid_to_hex(oid));
-               if (check_sha1_signature(oid->hash, buf, size, type_name(type)) < 0)
+               if (check_object_signature(oid, buf, size, type_name(type)) < 0)
                        die("sha1 mismatch in blob %s", oid_to_hex(oid));
                object = parse_object_buffer(oid, type, size, buf, &eaten);
        }
index 9744175e2314617a448a34370e3606c16209ef74..b28ebfadd433727a4d8344ecd56e458f3abc03a7 100644 (file)
@@ -1377,7 +1377,7 @@ static void fix_unresolved_deltas(struct hashfile *f)
                if (!base_obj->data)
                        continue;
 
-               if (check_sha1_signature(d->oid.hash, base_obj->data,
+               if (check_object_signature(&d->oid, base_obj->data,
                                base_obj->size, type_name(type)))
                        die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
                base_obj->obj = append_obj_to_pack(f, d->oid.hash,
index 65bb41e3cdd534c3dd48f772511f7ebd8c225813..810b24bef38b434c59718a6ac2883b7cfaafcd21 100644 (file)
@@ -27,8 +27,11 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
        const unsigned char *repl = lookup_replace_object(oid->hash);
 
        if (buffer) {
+               struct object_id reploid;
+               hashcpy(reploid.hash, repl);
+
                if (type == type_from_string(expected_type))
-                       ret = check_sha1_signature(repl, buffer, size, expected_type);
+                       ret = check_object_signature(&reploid, buffer, size, expected_type);
                free(buffer);
        }
        return ret;
diff --git a/cache.h b/cache.h
index 5a28e943181cd69cf25a28201d4fbb7d8f9016eb..27b5fd8a397f5622b32ea6fce6c8e635b2b7d75b 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1236,7 +1236,7 @@ extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);
 extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
 extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
 
-extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
+extern int check_object_signature(const struct object_id *oid, void *buf, unsigned long size, const char *type);
 
 extern int finalize_object_file(const char *tmpfile, const char *filename);
 
index e6ad3f61f03a98aa82dd901d96cbc230381c2e90..68bcf35d955a03f87ffe956de08fb3f7c30791a1 100644 (file)
--- a/object.c
+++ b/object.c
@@ -255,7 +255,10 @@ struct object *parse_object(const struct object_id *oid)
        if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
            (!obj && has_object_file(oid) &&
             sha1_object_info(oid->hash, NULL) == OBJ_BLOB)) {
-               if (check_sha1_signature(repl, NULL, 0, NULL) < 0) {
+               struct object_id reploid;
+               hashcpy(reploid.hash, repl);
+
+               if (check_object_signature(&reploid, NULL, 0, NULL) < 0) {
                        error("sha1 mismatch %s", oid_to_hex(oid));
                        return NULL;
                }
@@ -265,7 +268,10 @@ struct object *parse_object(const struct object_id *oid)
 
        buffer = read_sha1_file(oid->hash, &type, &size);
        if (buffer) {
-               if (check_sha1_signature(repl, buffer, size, type_name(type)) < 0) {
+               struct object_id reploid;
+               hashcpy(reploid.hash, repl);
+
+               if (check_object_signature(&reploid, buffer, size, type_name(type)) < 0) {
                        free(buffer);
                        error("sha1 mismatch %s", sha1_to_hex(repl));
                        return NULL;
index 8fc7dd1694cf1a67da69bc010879e0c54ee403be..d0591dd5e8f88b8b939c5720dac36a939fd1edf4 100644 (file)
@@ -126,7 +126,7 @@ static int verify_packfile(struct packed_git *p,
 
                if (type == OBJ_BLOB && big_file_threshold <= size) {
                        /*
-                        * Let check_sha1_signature() check it with
+                        * Let check_object_signature() check it with
                         * the streaming interface; no point slurping
                         * the data in-core only to discard.
                         */
@@ -141,7 +141,7 @@ static int verify_packfile(struct packed_git *p,
                        err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
                                    oid_to_hex(entries[i].oid.oid), p->pack_name,
                                    (uintmax_t)entries[i].offset);
-               else if (check_sha1_signature(entries[i].oid.hash, data, size, type_name(type)))
+               else if (check_object_signature(entries[i].oid.oid, data, size, type_name(type)))
                        err = error("packed %s from %s is corrupt",
                                    oid_to_hex(entries[i].oid.oid), p->pack_name);
                else if (fn) {
index 5081d585a2ee17f6f456867c6b321a2e5e9c1e0a..e4cb840661f799abb7a37e61bca269ee2443ba5c 100644 (file)
@@ -784,8 +784,8 @@ void *xmmap(void *start, size_t length,
  * With "map" == NULL, try reading the object named with "sha1" using
  * the streaming interface and rehash it to do the same.
  */
-int check_sha1_signature(const unsigned char *sha1, void *map,
-                        unsigned long size, const char *type)
+int check_object_signature(const struct object_id *oid, void *map,
+                          unsigned long size, const char *type)
 {
        struct object_id real_oid;
        enum object_type obj_type;
@@ -796,10 +796,10 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
 
        if (map) {
                hash_object_file(map, size, type, &real_oid);
-               return hashcmp(sha1, real_oid.hash) ? -1 : 0;
+               return oidcmp(oid, &real_oid) ? -1 : 0;
        }
 
-       st = open_istream(sha1, &obj_type, &size, NULL);
+       st = open_istream(oid->hash, &obj_type, &size, NULL);
        if (!st)
                return -1;
 
@@ -823,7 +823,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
        }
        the_hash_algo->final_fn(real_oid.hash, &c);
        close_istream(st);
-       return hashcmp(sha1, real_oid.hash) ? -1 : 0;
+       return oidcmp(oid, &real_oid) ? -1 : 0;
 }
 
 int git_open_cloexec(const char *name, int flags)
@@ -2217,7 +2217,7 @@ int read_loose_object(const char *path,
                        git_inflate_end(&stream);
                        goto out;
                }
-               if (check_sha1_signature(expected_oid->hash, *contents,
+               if (check_object_signature(expected_oid, *contents,
                                         *size, type_name(*type))) {
                        error("sha1 mismatch for %s (expected %s)", path,
                              oid_to_hex(expected_oid));