sha1_file: convert read_loose_object to use struct object_id
authorbrian m. carlson <sandals@crustytoothpaste.net>
Mon, 12 Mar 2018 02:27:38 +0000 (02:27 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Mar 2018 16:23:48 +0000 (09:23 -0700)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fsck.c
cache.h
sha1_file.c
index ef78c6c00cbf4401ed672d6ad954bbbc68c9c115..eae018e3fb06c1a9c1bd472fc077869aafbc5693 100644 (file)
@@ -513,7 +513,7 @@ static struct object *parse_loose_object(const struct object_id *oid,
        unsigned long size;
        int eaten;
 
-       if (read_loose_object(path, oid->hash, &type, &size, &contents) < 0)
+       if (read_loose_object(path, oid, &type, &size, &contents) < 0)
                return NULL;
 
        if (!contents && type != OBJ_BLOB)
diff --git a/cache.h b/cache.h
index fe8b2c2676837f4b706f5e18db1e30056b7b59ba..5a28e943181cd69cf25a28201d4fbb7d8f9016eb 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1241,14 +1241,14 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l
 extern int finalize_object_file(const char *tmpfile, const char *filename);
 
 /*
- * Open the loose object at path, check its sha1, and return the contents,
+ * Open the loose object at path, check its hash, and return the contents,
  * type, and size. If the object is a blob, then "contents" may return NULL,
  * to allow streaming of large blobs.
  *
  * Returns 0 on success, negative on error (details may be written to stderr).
  */
 int read_loose_object(const char *path,
-                     const unsigned char *expected_sha1,
+                     const struct object_id *expected_oid,
                      enum object_type *type,
                      unsigned long *size,
                      void **contents);
index 6b887f8aaf06226b1a758b18176263a7f9b1a3a2..5081d585a2ee17f6f456867c6b321a2e5e9c1e0a 100644 (file)
@@ -2176,7 +2176,7 @@ static int check_stream_sha1(git_zstream *stream,
 }
 
 int read_loose_object(const char *path,
-                     const unsigned char *expected_sha1,
+                     const struct object_id *expected_oid,
                      enum object_type *type,
                      unsigned long *size,
                      void **contents)
@@ -2208,19 +2208,19 @@ int read_loose_object(const char *path,
        }
 
        if (*type == OBJ_BLOB) {
-               if (check_stream_sha1(&stream, hdr, *size, path, expected_sha1) < 0)
+               if (check_stream_sha1(&stream, hdr, *size, path, expected_oid->hash) < 0)
                        goto out;
        } else {
-               *contents = unpack_sha1_rest(&stream, hdr, *size, expected_sha1);
+               *contents = unpack_sha1_rest(&stream, hdr, *size, expected_oid->hash);
                if (!*contents) {
                        error("unable to unpack contents of %s", path);
                        git_inflate_end(&stream);
                        goto out;
                }
-               if (check_sha1_signature(expected_sha1, *contents,
+               if (check_sha1_signature(expected_oid->hash, *contents,
                                         *size, type_name(*type))) {
                        error("sha1 mismatch for %s (expected %s)", path,
-                             sha1_to_hex(expected_sha1));
+                             oid_to_hex(expected_oid));
                        free(*contents);
                        goto out;
                }