sha1_file: allow read_object to read objects in arbitrary repositories

Allow read_object (a file local functon in sha1_file) to handle arbitrary repositories by passing the repository down to oid_object_info_extended. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Oct 16, 2018 at 16:35 UTC 1b9b5c695e34051c80c9240fdb22e7c89ff0fd5f
1 file changed +6 -4
sha1-file.c
+6 -4
@@ -1361,7 +1361,9 @@ int oid_object_info(struct repository *r,
1361 return type;
1362 }
1363
1364 -static void *read_object(const unsigned char *sha1, enum object_type *type,
1364 +static void *read_object(struct repository *r,
1365 + const unsigned char *sha1,
1366 + enum object_type *type,
1367 unsigned long *size)
1368 {
1369 struct object_id oid;
@@ -1373,7 +1375,7 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
1375
1376 hashcpy(oid.hash, sha1);
1377
1376 - if (oid_object_info_extended(the_repository, &oid, &oi, 0) < 0)
1378 + if (oid_object_info_extended(r, &oid, &oi, 0) < 0)
1379 return NULL;
1380 return content;
1381 }
@@ -1414,7 +1416,7 @@ void *read_object_file_extended(const struct object_id *oid,
1416 lookup_replace_object(the_repository, oid) : oid;
1417
1418 errno = 0;
1417 - data = read_object(repl->hash, type, size);
1419 + data = read_object(the_repository, repl->hash, type, size);
1420 if (data)
1421 return data;
1422
@@ -1755,7 +1757,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
1757
1758 if (has_loose_object(oid))
1759 return 0;
1758 - buf = read_object(oid->hash, &type, &len);
1760 + buf = read_object(the_repository, oid->hash, &type, &len);
1761 if (!buf)
1762 return error(_("cannot read sha1_file for %s"), oid_to_hex(oid));
1763 hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;