Skip to content

Commit 5970a4b

Browse files
committed
Merge branch 'jk/read-object-cleanup'
Code clean-up. * jk/read-object-cleanup: object-file: fix indent-with-space packfile: inline custom read_object() repo_read_object_file(): stop wrapping read_object_file_extended() read_object_file_extended(): drop lookup_replace option streaming: inline call to read_object_file_extended() object-file: inline calls to read_object()
2 parents 10925f5 + 15b6368 commit 5970a4b

File tree

4 files changed

+41
-66
lines changed

4 files changed

+41
-66
lines changed

object-file.c

Lines changed: 19 additions & 33 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,25 @@ 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
*/
1715-
void *read_object_file_extended(struct repository *r,
1716-
const struct object_id *oid,
1717-
enum object_type *type,
1718-
unsigned long *size,
1719-
int lookup_replace)
1698+
void *repo_read_object_file(struct repository *r,
1699+
const struct object_id *oid,
1700+
enum object_type *type,
1701+
unsigned long *size)
17201702
{
1703+
struct object_info oi = OBJECT_INFO_INIT;
1704+
unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT | OBJECT_INFO_LOOKUP_REPLACE;
17211705
void *data;
1722-
const struct object_id *repl = lookup_replace ?
1723-
lookup_replace_object(r, oid) : oid;
17241706

1725-
errno = 0;
1726-
data = read_object(r, repl, type, size, 1);
1727-
if (data)
1728-
return data;
1707+
oi.typep = type;
1708+
oi.sizep = size;
1709+
oi.contentp = &data;
1710+
if (oid_object_info_extended(r, oid, &oi, flags))
1711+
return NULL;
17291712

1730-
return NULL;
1713+
return data;
17311714
}
17321715

17331716
void *read_object_with_reference(struct repository *r,
@@ -2255,15 +2238,18 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
22552238
{
22562239
void *buf;
22572240
unsigned long len;
2241+
struct object_info oi = OBJECT_INFO_INIT;
22582242
enum object_type type;
22592243
char hdr[MAX_HEADER_LEN];
22602244
int hdrlen;
22612245
int ret;
22622246

22632247
if (has_loose_object(oid))
22642248
return 0;
2265-
buf = read_object(the_repository, oid, &type, &len, 0);
2266-
if (!buf)
2249+
oi.typep = &type;
2250+
oi.sizep = &len;
2251+
oi.contentp = &buf;
2252+
if (oid_object_info_extended(the_repository, oid, &oi, 0))
22672253
return error(_("cannot read object for %s"), oid_to_hex(oid));
22682254
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
22692255
ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime, 0);

object-store.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -241,17 +241,10 @@ const char *loose_object_path(struct repository *r, struct strbuf *buf,
241241
void *map_loose_object(struct repository *r, const struct object_id *oid,
242242
unsigned long *size);
243243

244-
void *read_object_file_extended(struct repository *r,
245-
const struct object_id *oid,
246-
enum object_type *type,
247-
unsigned long *size, int lookup_replace);
248-
static inline void *repo_read_object_file(struct repository *r,
249-
const struct object_id *oid,
250-
enum object_type *type,
251-
unsigned long *size)
252-
{
253-
return read_object_file_extended(r, oid, type, size, 1);
254-
}
244+
void *repo_read_object_file(struct repository *r,
245+
const struct object_id *oid,
246+
enum object_type *type,
247+
unsigned long *size);
255248
#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
256249
#define read_object_file(oid, type, size) repo_read_object_file(the_repository, oid, type, size)
257250
#endif
@@ -358,8 +351,7 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect);
358351
/*
359352
* Enabling the object read lock allows multiple threads to safely call the
360353
* following functions in parallel: repo_read_object_file(), read_object_file(),
361-
* read_object_file_extended(), read_object_with_reference(), read_object(),
362-
* oid_object_info() and oid_object_info_extended().
354+
* read_object_with_reference(), oid_object_info() and oid_object_info_extended().
363355
*
364356
* obj_read_lock() and obj_read_unlock() may also be used to protect other
365357
* section which cannot execute in parallel with object reading. Since the used

packfile.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,22 +1650,6 @@ struct unpack_entry_stack_ent {
16501650
unsigned long size;
16511651
};
16521652

1653-
static void *read_object(struct repository *r,
1654-
const struct object_id *oid,
1655-
enum object_type *type,
1656-
unsigned long *size)
1657-
{
1658-
struct object_info oi = OBJECT_INFO_INIT;
1659-
void *content;
1660-
oi.typep = type;
1661-
oi.sizep = size;
1662-
oi.contentp = &content;
1663-
1664-
if (oid_object_info_extended(r, oid, &oi, 0) < 0)
1665-
return NULL;
1666-
return content;
1667-
}
1668-
16691653
void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
16701654
enum object_type *final_type, unsigned long *final_size)
16711655
{
@@ -1798,14 +1782,22 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
17981782
uint32_t pos;
17991783
struct object_id base_oid;
18001784
if (!(offset_to_pack_pos(p, obj_offset, &pos))) {
1785+
struct object_info oi = OBJECT_INFO_INIT;
1786+
18011787
nth_packed_object_id(&base_oid, p,
18021788
pack_pos_to_index(p, pos));
18031789
error("failed to read delta base object %s"
18041790
" at offset %"PRIuMAX" from %s",
18051791
oid_to_hex(&base_oid), (uintmax_t)obj_offset,
18061792
p->pack_name);
18071793
mark_bad_packed_object(p, &base_oid);
1808-
base = read_object(r, &base_oid, &type, &base_size);
1794+
1795+
oi.typep = &type;
1796+
oi.sizep = &base_size;
1797+
oi.contentp = &base;
1798+
if (oid_object_info_extended(r, &base_oid, &oi, 0) < 0)
1799+
base = NULL;
1800+
18091801
external_base = base;
18101802
}
18111803
}

streaming.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct git_istream {
3838

3939
union {
4040
struct {
41-
char *buf; /* from read_object() */
41+
char *buf; /* from oid_object_info_extended() */
4242
unsigned long read_ptr;
4343
} incore;
4444

@@ -388,12 +388,17 @@ static ssize_t read_istream_incore(struct git_istream *st, char *buf, size_t sz)
388388
static int open_istream_incore(struct git_istream *st, struct repository *r,
389389
const struct object_id *oid, enum object_type *type)
390390
{
391-
st->u.incore.buf = read_object_file_extended(r, oid, type, &st->size, 0);
391+
struct object_info oi = OBJECT_INFO_INIT;
392+
392393
st->u.incore.read_ptr = 0;
393394
st->close = close_istream_incore;
394395
st->read = read_istream_incore;
395396

396-
return st->u.incore.buf ? 0 : -1;
397+
oi.typep = type;
398+
oi.sizep = &st->size;
399+
oi.contentp = (void **)&st->u.incore.buf;
400+
return oid_object_info_extended(r, oid, &oi,
401+
OBJECT_INFO_DIE_IF_CORRUPT);
397402
}
398403

399404
/*****************************************************************************

0 commit comments

Comments
 (0)