sha1_file: convert read_loose_object to use struct object_id

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Mar 12, 2018 at 02:27 UTC d61d87bd156a1d49b827d1b26f023fd70febfa06
3 files changed +8 -8
builtin/fsck.c
+1 -1
@@ -513,7 +513,7 @@ static struct object *parse_loose_object(const struct object_id *oid,
513 unsigned long size;
514 int eaten;
515
516 - if (read_loose_object(path, oid->hash, &type, &size, &contents) < 0)
516 + if (read_loose_object(path, oid, &type, &size, &contents) < 0)
517 return NULL;
518
519 if (!contents && type != OBJ_BLOB)
cache.h
+2 -2
@@ -1241,14 +1241,14 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l
1241 extern int finalize_object_file(const char *tmpfile, const char *filename);
1242
1243 /*
1244 - * Open the loose object at path, check its sha1, and return the contents,
1244 + * Open the loose object at path, check its hash, and return the contents,
1245 * type, and size. If the object is a blob, then "contents" may return NULL,
1246 * to allow streaming of large blobs.
1247 *
1248 * Returns 0 on success, negative on error (details may be written to stderr).
1249 */
1250 int read_loose_object(const char *path,
1251 - const unsigned char *expected_sha1,
1251 + const struct object_id *expected_oid,
1252 enum object_type *type,
1253 unsigned long *size,
1254 void **contents);
sha1_file.c
+5 -5
@@ -2176,7 +2176,7 @@ static int check_stream_sha1(git_zstream *stream,
2176 }
2177
2178 int read_loose_object(const char *path,
2179 - const unsigned char *expected_sha1,
2179 + const struct object_id *expected_oid,
2180 enum object_type *type,
2181 unsigned long *size,
2182 void **contents)
@@ -2208,19 +2208,19 @@ int read_loose_object(const char *path,
2208 }
2209
2210 if (*type == OBJ_BLOB) {
2211 - if (check_stream_sha1(&stream, hdr, *size, path, expected_sha1) < 0)
2211 + if (check_stream_sha1(&stream, hdr, *size, path, expected_oid->hash) < 0)
2212 goto out;
2213 } else {
2214 - *contents = unpack_sha1_rest(&stream, hdr, *size, expected_sha1);
2214 + *contents = unpack_sha1_rest(&stream, hdr, *size, expected_oid->hash);
2215 if (!*contents) {
2216 error("unable to unpack contents of %s", path);
2217 git_inflate_end(&stream);
2218 goto out;
2219 }
2220 - if (check_sha1_signature(expected_sha1, *contents,
2220 + if (check_sha1_signature(expected_oid->hash, *contents,
2221 *size, type_name(*type))) {
2222 error("sha1 mismatch for %s (expected %s)", path,
2223 - sha1_to_hex(expected_sha1));
2223 + oid_to_hex(expected_oid));
2224 free(*contents);
2225 goto out;
2226 }