sha1-file: convert pass-through functions to object_id

These two static functions, read_object() and quick_has_loose(), both have to hashcpy() their bare-sha1 arguments into object_id structs to pass them along. Since all of their callers actually have object_id structs in the first place, we can eliminate the copying by adjusting their input parameters. 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:37 UTC d7a245730b4397e50592e1f4ebce765f7fbf5f93
1 file changed +7 -13
sha1-file.c
+7 -13
@@ -922,16 +922,13 @@ static int open_loose_object(struct repository *r,
922 }
923
924 static int quick_has_loose(struct repository *r,
925 - const unsigned char *sha1)
925 + const struct object_id *oid)
926 {
927 - struct object_id oid;
927 struct object_directory *odb;
928
930 - hashcpy(oid.hash, sha1);
931 -
929 prepare_alt_odb(r);
930 for (odb = r->objects->odb; odb; odb = odb->next) {
934 - if (oid_array_lookup(odb_loose_cache(odb, &oid), &oid) >= 0)
931 + if (oid_array_lookup(odb_loose_cache(odb, oid), oid) >= 0)
932 return 1;
933 }
934 return 0;
@@ -1191,7 +1188,7 @@ static int loose_object_info(struct repository *r,
1188 const char *path;
1189 struct stat st;
1190 if (!oi->disk_sizep && (flags & OBJECT_INFO_QUICK))
1194 - return quick_has_loose(r, oid->hash) ? 0 : -1;
1191 + return quick_has_loose(r, oid) ? 0 : -1;
1192 if (stat_loose_object(r, oid, &st, &path) < 0)
1193 return -1;
1194 if (oi->disk_sizep)
@@ -1355,19 +1352,16 @@ int oid_object_info(struct repository *r,
1352 return type;
1353 }
1354
1358 -static void *read_object(const unsigned char *sha1, enum object_type *type,
1355 +static void *read_object(const struct object_id *oid, enum object_type *type,
1356 unsigned long *size)
1357 {
1361 - struct object_id oid;
1358 struct object_info oi = OBJECT_INFO_INIT;
1359 void *content;
1360 oi.typep = type;
1361 oi.sizep = size;
1362 oi.contentp = &content;
1363
1368 - hashcpy(oid.hash, sha1);
1369 -
1370 - if (oid_object_info_extended(the_repository, &oid, &oi, 0) < 0)
1364 + if (oid_object_info_extended(the_repository, oid, &oi, 0) < 0)
1365 return NULL;
1366 return content;
1367 }
@@ -1408,7 +1402,7 @@ void *read_object_file_extended(const struct object_id *oid,
1402 lookup_replace_object(the_repository, oid) : oid;
1403
1404 errno = 0;
1411 - data = read_object(repl->hash, type, size);
1405 + data = read_object(repl, type, size);
1406 if (data)
1407 return data;
1408
@@ -1748,7 +1742,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
1742
1743 if (has_loose_object(oid))
1744 return 0;
1751 - buf = read_object(oid->hash, &type, &len);
1745 + buf = read_object(oid, &type, &len);
1746 if (!buf)
1747 return error(_("cannot read sha1_file for %s"), oid_to_hex(oid));
1748 hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(type), (uintmax_t)len) + 1;