Skip to content

Commit b25562e

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4dbebc3 commit b25562e

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

object-file.c

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,23 +1671,6 @@ int oid_object_info(struct repository *r,
16711671
return type;
16721672
}
16731673

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-
16911674
int pretend_object_file(void *buf, unsigned long len, enum object_type type,
16921675
struct object_id *oid)
16931676
{
@@ -1709,25 +1692,28 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
17091692

17101693
/*
17111694
* 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.
17141697
*/
17151698
void *read_object_file_extended(struct repository *r,
17161699
const struct object_id *oid,
17171700
enum object_type *type,
17181701
unsigned long *size,
17191702
int lookup_replace)
17201703
{
1704+
struct object_info oi = OBJECT_INFO_INIT;
1705+
unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT;
17211706
void *data;
1722-
const struct object_id *repl = lookup_replace ?
1723-
lookup_replace_object(r, oid) : oid;
17241707

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;
17291715

1730-
return NULL;
1716+
return data;
17311717
}
17321718

17331719
void *read_object_with_reference(struct repository *r,
@@ -2255,15 +2241,18 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
22552241
{
22562242
void *buf;
22572243
unsigned long len;
2244+
struct object_info oi = OBJECT_INFO_INIT;
22582245
enum object_type type;
22592246
char hdr[MAX_HEADER_LEN];
22602247
int hdrlen;
22612248
int ret;
22622249

22632250
if (has_loose_object(oid))
22642251
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))
22672256
return error(_("cannot read object for %s"), oid_to_hex(oid));
22682257
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
22692258
ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime, 0);

object-store.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect);
358358
/*
359359
* Enabling the object read lock allows multiple threads to safely call the
360360
* 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(),
362362
* oid_object_info() and oid_object_info_extended().
363363
*
364364
* obj_read_lock() and obj_read_unlock() may also be used to protect other

0 commit comments

Comments
 (0)