object-file: inline calls to read_object()

Since read_object() is these days just a thin wrapper around oid_object_info_extended(), and since it only has two callers, let's just inline those calls. This has a few positive outcomes: - it's a net reduction in source code lines - even though the callers end up with a few extra lines, they're now more flexible and can use object_info flags directly. So no more need to convert die_if_corrupt between parameter/flag, and we can ask for lookup replacement with a flag rather than doing it ourselves. - there's one fewer function in an already crowded namespace (e.g., the difference between read_object() and read_object_file() was not immediately obvious; now we only have one of them). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 7, 2023 at 08:48 UTC b25562e63fe8afaf0f103362a4e672e9ccdc2d68
2 files changed +18 -29
object-file.c
+17 -28
@@ -1671,23 +1671,6 @@ int oid_object_info(struct repository *r,
1671 return type;
1672 }
1673
1674 -static void *read_object(struct repository *r,
1675 - const struct object_id *oid, enum object_type *type,
1676 - unsigned long *size,
1677 - int die_if_corrupt)
1678 -{
1679 - struct object_info oi = OBJECT_INFO_INIT;
1680 - void *content;
1681 - oi.typep = type;
1682 - oi.sizep = size;
1683 - oi.contentp = &content;
1684 -
1685 - if (oid_object_info_extended(r, oid, &oi, die_if_corrupt
1686 - ? OBJECT_INFO_DIE_IF_CORRUPT : 0) < 0)
1687 - return NULL;
1688 - return content;
1689 -}
1690 -
1674 int pretend_object_file(void *buf, unsigned long len, enum object_type type,
1675 struct object_id *oid)
1676 {
@@ -1709,8 +1692,8 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
1692
1693 /*
1694 * This function dies on corrupt objects; the callers who want to
1712 - * deal with them should arrange to call read_object() and give error
1713 - * messages themselves.
1695 + * deal with them should arrange to call oid_object_info_extended() and give
1696 + * error messages themselves.
1697 */
1698 void *read_object_file_extended(struct repository *r,
1699 const struct object_id *oid,
@@ -1718,16 +1701,19 @@ void *read_object_file_extended(struct repository *r,
1701 unsigned long *size,
1702 int lookup_replace)
1703 {
1704 + struct object_info oi = OBJECT_INFO_INIT;
1705 + unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT;
1706 void *data;
1722 - const struct object_id *repl = lookup_replace ?
1723 - lookup_replace_object(r, oid) : oid;
1707
1725 - errno = 0;
1726 - data = read_object(r, repl, type, size, 1);
1727 - if (data)
1728 - return data;
1708 + oi.typep = type;
1709 + oi.sizep = size;
1710 + oi.contentp = &data;
1711 + if (lookup_replace)
1712 + flags |= OBJECT_INFO_LOOKUP_REPLACE;
1713 + if (oid_object_info_extended(r, oid, &oi, flags))
1714 + return NULL;
1715
1730 - return NULL;
1716 + return data;
1717 }
1718
1719 void *read_object_with_reference(struct repository *r,
@@ -2255,6 +2241,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
2241 {
2242 void *buf;
2243 unsigned long len;
2244 + struct object_info oi = OBJECT_INFO_INIT;
2245 enum object_type type;
2246 char hdr[MAX_HEADER_LEN];
2247 int hdrlen;
@@ -2262,8 +2249,10 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
2249
2250 if (has_loose_object(oid))
2251 return 0;
2265 - buf = read_object(the_repository, oid, &type, &len, 0);
2266 - if (!buf)
2252 + oi.typep = &type;
2253 + oi.sizep = &len;
2254 + oi.contentp = &buf;
2255 + if (oid_object_info_extended(the_repository, oid, &oi, 0))
2256 return error(_("cannot read object for %s"), oid_to_hex(oid));
2257 hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
2258 ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime, 0);
object-store.h
+1 -1
@@ -358,7 +358,7 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect);
358 /*
359 * Enabling the object read lock allows multiple threads to safely call the
360 * following functions in parallel: repo_read_object_file(), read_object_file(),
361 - * read_object_file_extended(), read_object_with_reference(), read_object(),
361 + * read_object_file_extended(), read_object_with_reference(),
362 * oid_object_info() and oid_object_info_extended().
363 *
364 * obj_read_lock() and obj_read_unlock() may also be used to protect other