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()
This commit is contained in:
Junio C Hamano
2023-01-20 15:36:21 -08:00
4 changed files with 41 additions and 66 deletions

View File

@ -1671,23 +1671,6 @@ int oid_object_info(struct repository *r,
return type;
}
static void *read_object(struct repository *r,
const struct object_id *oid, enum object_type *type,
unsigned long *size,
int die_if_corrupt)
{
struct object_info oi = OBJECT_INFO_INIT;
void *content;
oi.typep = type;
oi.sizep = size;
oi.contentp = &content;
if (oid_object_info_extended(r, oid, &oi, die_if_corrupt
? OBJECT_INFO_DIE_IF_CORRUPT : 0) < 0)
return NULL;
return content;
}
int pretend_object_file(void *buf, unsigned long len, enum object_type type,
struct object_id *oid)
{
@ -1709,25 +1692,25 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
/*
* This function dies on corrupt objects; the callers who want to
* deal with them should arrange to call read_object() and give error
* messages themselves.
* deal with them should arrange to call oid_object_info_extended() and give
* error messages themselves.
*/
void *read_object_file_extended(struct repository *r,
const struct object_id *oid,
enum object_type *type,
unsigned long *size,
int lookup_replace)
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
enum object_type *type,
unsigned long *size)
{
struct object_info oi = OBJECT_INFO_INIT;
unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT | OBJECT_INFO_LOOKUP_REPLACE;
void *data;
const struct object_id *repl = lookup_replace ?
lookup_replace_object(r, oid) : oid;
errno = 0;
data = read_object(r, repl, type, size, 1);
if (data)
return data;
oi.typep = type;
oi.sizep = size;
oi.contentp = &data;
if (oid_object_info_extended(r, oid, &oi, flags))
return NULL;
return NULL;
return data;
}
void *read_object_with_reference(struct repository *r,
@ -2255,6 +2238,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
{
void *buf;
unsigned long len;
struct object_info oi = OBJECT_INFO_INIT;
enum object_type type;
char hdr[MAX_HEADER_LEN];
int hdrlen;
@ -2262,8 +2246,10 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
if (has_loose_object(oid))
return 0;
buf = read_object(the_repository, oid, &type, &len, 0);
if (!buf)
oi.typep = &type;
oi.sizep = &len;
oi.contentp = &buf;
if (oid_object_info_extended(the_repository, oid, &oi, 0))
return error(_("cannot read object for %s"), oid_to_hex(oid));
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime, 0);

View File

@ -241,17 +241,10 @@ const char *loose_object_path(struct repository *r, struct strbuf *buf,
void *map_loose_object(struct repository *r, const struct object_id *oid,
unsigned long *size);
void *read_object_file_extended(struct repository *r,
const struct object_id *oid,
enum object_type *type,
unsigned long *size, int lookup_replace);
static inline void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
enum object_type *type,
unsigned long *size)
{
return read_object_file_extended(r, oid, type, size, 1);
}
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
enum object_type *type,
unsigned long *size);
#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
#define read_object_file(oid, type, size) repo_read_object_file(the_repository, oid, type, size)
#endif
@ -358,8 +351,7 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect);
/*
* Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: repo_read_object_file(), read_object_file(),
* read_object_file_extended(), read_object_with_reference(), read_object(),
* oid_object_info() and oid_object_info_extended().
* read_object_with_reference(), oid_object_info() and oid_object_info_extended().
*
* obj_read_lock() and obj_read_unlock() may also be used to protect other
* section which cannot execute in parallel with object reading. Since the used

View File

@ -1650,22 +1650,6 @@ struct unpack_entry_stack_ent {
unsigned long size;
};
static void *read_object(struct repository *r,
const struct object_id *oid,
enum object_type *type,
unsigned long *size)
{
struct object_info oi = OBJECT_INFO_INIT;
void *content;
oi.typep = type;
oi.sizep = size;
oi.contentp = &content;
if (oid_object_info_extended(r, oid, &oi, 0) < 0)
return NULL;
return content;
}
void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
enum object_type *final_type, unsigned long *final_size)
{
@ -1798,6 +1782,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
uint32_t pos;
struct object_id base_oid;
if (!(offset_to_pack_pos(p, obj_offset, &pos))) {
struct object_info oi = OBJECT_INFO_INIT;
nth_packed_object_id(&base_oid, p,
pack_pos_to_index(p, pos));
error("failed to read delta base object %s"
@ -1805,7 +1791,13 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
oid_to_hex(&base_oid), (uintmax_t)obj_offset,
p->pack_name);
mark_bad_packed_object(p, &base_oid);
base = read_object(r, &base_oid, &type, &base_size);
oi.typep = &type;
oi.sizep = &base_size;
oi.contentp = &base;
if (oid_object_info_extended(r, &base_oid, &oi, 0) < 0)
base = NULL;
external_base = base;
}
}

View File

@ -38,7 +38,7 @@ struct git_istream {
union {
struct {
char *buf; /* from read_object() */
char *buf; /* from oid_object_info_extended() */
unsigned long read_ptr;
} incore;
@ -388,12 +388,17 @@ static ssize_t read_istream_incore(struct git_istream *st, char *buf, size_t sz)
static int open_istream_incore(struct git_istream *st, struct repository *r,
const struct object_id *oid, enum object_type *type)
{
st->u.incore.buf = read_object_file_extended(r, oid, type, &st->size, 0);
struct object_info oi = OBJECT_INFO_INIT;
st->u.incore.read_ptr = 0;
st->close = close_istream_incore;
st->read = read_istream_incore;
return st->u.incore.buf ? 0 : -1;
oi.typep = type;
oi.sizep = &st->size;
oi.contentp = (void **)&st->u.incore.buf;
return oid_object_info_extended(r, oid, &oi,
OBJECT_INFO_DIE_IF_CORRUPT);
}
/*****************************************************************************