odb: rename `repo_read_object_file()`

Rename `repo_read_object_file()` to `odb_read_object()` to match other
functions related to the object database and our modern coding
guidelines.

Introduce a compatibility wrapper so that any in-flight topics will
continue to compile.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Patrick Steinhardt 2025-07-01 14:22:26 +02:00 committed by Junio C Hamano
parent e989dd96b8
commit d4ff88aee3
47 changed files with 157 additions and 150 deletions

10
apply.c
View File

@ -3210,8 +3210,8 @@ static int apply_binary(struct apply_state *state,
unsigned long size; unsigned long size;
char *result; char *result;


result = repo_read_object_file(the_repository, &oid, &type, result = odb_read_object(the_repository->objects, &oid,
&size); &type, &size);
if (!result) if (!result)
return error(_("the necessary postimage %s for " return error(_("the necessary postimage %s for "
"'%s' cannot be read"), "'%s' cannot be read"),
@ -3273,8 +3273,8 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
unsigned long sz; unsigned long sz;
char *result; char *result;


result = repo_read_object_file(the_repository, oid, &type, result = odb_read_object(the_repository->objects, oid,
&sz); &type, &sz);
if (!result) if (!result)
return -1; return -1;
/* XXX read_sha1_file NUL-terminates */ /* XXX read_sha1_file NUL-terminates */
@ -3503,7 +3503,7 @@ static int resolve_to(struct image *image, const struct object_id *result_id)


image_clear(image); image_clear(image);


data = repo_read_object_file(the_repository, result_id, &type, &size); data = odb_read_object(the_repository->objects, result_id, &type, &size);
if (!data || type != OBJ_BLOB) if (!data || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(result_id)); die("unable to read blob object %s", oid_to_hex(result_id));
strbuf_attach(&image->buf, data, size, size + 1); strbuf_attach(&image->buf, data, size, size + 1);

View File

@ -98,7 +98,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
(args->tree ? &args->tree->object.oid : NULL), oid); (args->tree ? &args->tree->object.oid : NULL), oid);


path += args->baselen; path += args->baselen;
buffer = repo_read_object_file(the_repository, oid, type, sizep); buffer = odb_read_object(the_repository->objects, oid, type, sizep);
if (buffer && S_ISREG(mode)) { if (buffer && S_ISREG(mode)) {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
size_t size = 0; size_t size = 0;

2
attr.c
View File

@ -779,7 +779,7 @@ static struct attr_stack *read_attr_from_blob(struct index_state *istate,
if (get_tree_entry(istate->repo, tree_oid, path, &oid, &mode)) if (get_tree_entry(istate->repo, tree_oid, path, &oid, &mode))
return NULL; return NULL;


buf = repo_read_object_file(istate->repo, &oid, &type, &sz); buf = odb_read_object(istate->repo->objects, &oid, &type, &sz);
if (!buf || type != OBJ_BLOB) { if (!buf || type != OBJ_BLOB) {
free(buf); free(buf);
return NULL; return NULL;

View File

@ -155,7 +155,7 @@ static void show_list(const char *debug, int counted, int nr,
unsigned commit_flags = commit->object.flags; unsigned commit_flags = commit->object.flags;
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
char *buf = repo_read_object_file(the_repository, char *buf = odb_read_object(the_repository->objects,
&commit->object.oid, &type, &commit->object.oid, &type,
&size); &size);
const char *subject_start; const char *subject_start;

View File

@ -1041,7 +1041,7 @@ static void fill_origin_blob(struct diff_options *opt,
&o->blob_oid, 1, &file->ptr, &file_size)) &o->blob_oid, 1, &file->ptr, &file_size))
; ;
else else
file->ptr = repo_read_object_file(the_repository, file->ptr = odb_read_object(the_repository->objects,
&o->blob_oid, &type, &o->blob_oid, &type,
&file_size); &file_size);
file->size = file_size; file->size = file_size;
@ -2869,9 +2869,8 @@ void setup_scoreboard(struct blame_scoreboard *sb,
&sb->final_buf_size)) &sb->final_buf_size))
; ;
else else
sb->final_buf = repo_read_object_file(the_repository, sb->final_buf = odb_read_object(the_repository->objects,
&o->blob_oid, &o->blob_oid, &type,
&type,
&sb->final_buf_size); &sb->final_buf_size);


if (!sb->final_buf) if (!sb->final_buf)

View File

@ -74,7 +74,7 @@ static int filter_object(const char *path, unsigned mode,
{ {
enum object_type type; enum object_type type;


*buf = repo_read_object_file(the_repository, oid, &type, size); *buf = odb_read_object(the_repository->objects, oid, &type, size);
if (!*buf) if (!*buf)
return error(_("cannot read object %s '%s'"), return error(_("cannot read object %s '%s'"),
oid_to_hex(oid), path); oid_to_hex(oid), path);
@ -197,8 +197,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
ret = stream_blob(&oid); ret = stream_blob(&oid);
goto cleanup; goto cleanup;
} }
buf = repo_read_object_file(the_repository, &oid, &type, buf = odb_read_object(the_repository->objects, &oid,
&size); &type, &size);
if (!buf) if (!buf)
die("Cannot read object %s", obj_name); die("Cannot read object %s", obj_name);


@ -219,10 +219,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
struct object_id blob_oid; struct object_id blob_oid;
if (odb_read_object_info(the_repository->objects, if (odb_read_object_info(the_repository->objects,
&oid, NULL) == OBJ_TAG) { &oid, NULL) == OBJ_TAG) {
char *buffer = repo_read_object_file(the_repository, char *buffer = odb_read_object(the_repository->objects,
&oid, &oid, &type, &size);
&type,
&size);
const char *target; const char *target;


if (!buffer) if (!buffer)
@ -403,10 +401,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
if (!textconv_object(the_repository, if (!textconv_object(the_repository,
data->rest, 0100644, oid, data->rest, 0100644, oid,
1, &contents, &size)) 1, &contents, &size))
contents = repo_read_object_file(the_repository, contents = odb_read_object(the_repository->objects,
oid, oid, &type, &size);
&type,
&size);
if (!contents) if (!contents)
die("could not convert '%s' %s", die("could not convert '%s' %s",
oid_to_hex(oid), data->rest); oid_to_hex(oid), data->rest);
@ -423,8 +419,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
unsigned long size; unsigned long size;
void *contents; void *contents;


contents = repo_read_object_file(the_repository, oid, &type, contents = odb_read_object(the_repository->objects, oid,
&size); &type, &size);
if (!contents) if (!contents)
die("object %s disappeared", oid_to_hex(oid)); die("object %s disappeared", oid_to_hex(oid));


@ -533,8 +529,8 @@ static void batch_object_write(const char *obj_name,
size_t s = data->size; size_t s = data->size;
char *buf = NULL; char *buf = NULL;


buf = repo_read_object_file(the_repository, &data->oid, &data->type, buf = odb_read_object(the_repository->objects, &data->oid,
&data->size); &data->type, &data->size);
if (!buf) if (!buf)
die(_("unable to read %s"), oid_to_hex(&data->oid)); die(_("unable to read %s"), oid_to_hex(&data->oid));
buf = replace_idents_using_mailmap(buf, &s); buf = replace_idents_using_mailmap(buf, &s);

View File

@ -320,7 +320,7 @@ static char *get_symlink(struct repository *repo,
} else { } else {
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
data = repo_read_object_file(repo, oid, &type, &size); data = odb_read_object(repo->objects, oid, &type, &size);
if (!data) if (!data)
die(_("could not read object %s for symlink %s"), die(_("could not read object %s for symlink %s"),
oid_to_hex(oid), path); oid_to_hex(oid), path);

View File

@ -323,7 +323,7 @@ static void export_blob(const struct object_id *oid)
object = (struct object *)lookup_blob(the_repository, oid); object = (struct object *)lookup_blob(the_repository, oid);
eaten = 0; eaten = 0;
} else { } else {
buf = repo_read_object_file(the_repository, oid, &type, &size); buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) if (!buf)
die("could not read blob %s", oid_to_hex(oid)); die("could not read blob %s", oid_to_hex(oid));
if (check_object_signature(the_repository, oid, buf, size, if (check_object_signature(the_repository, oid, buf, size,
@ -869,8 +869,8 @@ static void handle_tag(const char *name, struct tag *tag)
return; return;
} }


buf = repo_read_object_file(the_repository, &tag->object.oid, &type, buf = odb_read_object(the_repository->objects, &tag->object.oid,
&size); &type, &size);
if (!buf) if (!buf)
die("could not read tag %s", oid_to_hex(&tag->object.oid)); die("could not read tag %s", oid_to_hex(&tag->object.oid));
message = memmem(buf, size, "\n\n", 2); message = memmem(buf, size, "\n\n", 2);

View File

@ -1265,7 +1265,7 @@ static void load_tree(struct tree_entry *root)
die("Can't load tree %s", oid_to_hex(oid)); die("Can't load tree %s", oid_to_hex(oid));
} else { } else {
enum object_type type; enum object_type type;
buf = repo_read_object_file(the_repository, oid, &type, &size); buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_TREE) if (!buf || type != OBJ_TREE)
die("Can't load tree %s", oid_to_hex(oid)); die("Can't load tree %s", oid_to_hex(oid));
} }
@ -3002,7 +3002,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
char *buf; char *buf;


if (!oe || oe->pack_id == MAX_PACK_ID) { if (!oe || oe->pack_id == MAX_PACK_ID) {
buf = repo_read_object_file(the_repository, oid, &type, &size); buf = odb_read_object(the_repository->objects, oid, &type, &size);
} else { } else {
type = oe->type; type = oe->type;
buf = gfi_unpack_entry(oe, &size); buf = gfi_unpack_entry(oe, &size);
@ -3110,8 +3110,8 @@ static struct object_entry *dereference(struct object_entry *oe,
buf = gfi_unpack_entry(oe, &size); buf = gfi_unpack_entry(oe, &size);
} else { } else {
enum object_type unused; enum object_type unused;
buf = repo_read_object_file(the_repository, oid, &unused, buf = odb_read_object(the_repository->objects, oid,
&size); &unused, &size);
} }
if (!buf) if (!buf)
die("Can't load object %s", oid_to_hex(oid)); die("Can't load object %s", oid_to_hex(oid));

View File

@ -573,7 +573,7 @@ static int grep_cache(struct grep_opt *opt,
void *data; void *data;
unsigned long size; unsigned long size;


data = repo_read_object_file(the_repository, &ce->oid, data = odb_read_object(the_repository->objects, &ce->oid,
&type, &size); &type, &size);
if (!data) if (!data)
die(_("unable to read tree %s"), oid_to_hex(&ce->oid)); die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
@ -666,7 +666,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
void *data; void *data;
unsigned long size; unsigned long size;


data = repo_read_object_file(the_repository, data = odb_read_object(the_repository->objects,
&entry.oid, &type, &size); &entry.oid, &type, &size);
if (!data) if (!data)
die(_("unable to read tree (%s)"), die(_("unable to read tree (%s)"),

View File

@ -914,7 +914,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
die(_("cannot read existing object info %s"), oid_to_hex(oid)); die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size) if (has_type != type || has_size != size)
die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid)); die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
has_data = repo_read_object_file(the_repository, oid, has_data = odb_read_object(the_repository->objects, oid,
&has_type, &has_size); &has_type, &has_size);
read_unlock(); read_unlock();
if (!data) if (!data)
@ -1521,8 +1521,8 @@ static void fix_unresolved_deltas(struct hashfile *f)


if (objects[d->obj_no].real_type != OBJ_REF_DELTA) if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
continue; continue;
data = repo_read_object_file(the_repository, &d->oid, &type, data = odb_read_object(the_repository->objects, &d->oid,
&size); &type, &size);
if (!data) if (!data)
continue; continue;



View File

@ -714,7 +714,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
{ {
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
char *buf = repo_read_object_file(the_repository, oid, &type, &size); char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
unsigned long offset = 0; unsigned long offset = 0;


if (!buf) if (!buf)

View File

@ -75,7 +75,7 @@ static void *result(struct merge_list *entry, unsigned long *size)
const char *path = entry->path; const char *path = entry->path;


if (!entry->stage) if (!entry->stage)
return repo_read_object_file(the_repository, return odb_read_object(the_repository->objects,
&entry->blob->object.oid, &type, &entry->blob->object.oid, &type,
size); size);
base = NULL; base = NULL;
@ -100,7 +100,7 @@ static void *origin(struct merge_list *entry, unsigned long *size)
enum object_type type; enum object_type type;
while (entry) { while (entry) {
if (entry->stage == 2) if (entry->stage == 2)
return repo_read_object_file(the_repository, return odb_read_object(the_repository->objects,
&entry->blob->object.oid, &entry->blob->object.oid,
&type, size); &type, size);
entry = entry->link; entry = entry->link;

View File

@ -54,8 +54,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
void *buffer; void *buffer;
const struct object_id *repl; const struct object_id *repl;


buffer = repo_read_object_file(the_repository, tagged_oid, &type, buffer = odb_read_object(the_repository->objects, tagged_oid,
&size); &type, &size);
if (!buffer) if (!buffer)
die(_("could not read tagged object '%s'"), die(_("could not read tagged object '%s'"),
oid_to_hex(tagged_oid)); oid_to_hex(tagged_oid));

View File

@ -152,7 +152,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
{ {
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
char *buf = repo_read_object_file(the_repository, oid, &type, &size); char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (buf) { if (buf) {
if (size) if (size)
write_or_die(fd, buf, size); write_or_die(fd, buf, size);
@ -319,7 +319,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
strbuf_init(&msg->buf, 0); strbuf_init(&msg->buf, 0);
if (repo_get_oid(the_repository, arg, &object)) if (repo_get_oid(the_repository, arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg); die(_("failed to resolve '%s' as a valid ref."), arg);
if (!(value = repo_read_object_file(the_repository, &object, &type, &len))) if (!(value = odb_read_object(the_repository->objects, &object, &type, &len)))
die(_("failed to read object '%s'."), arg); die(_("failed to read object '%s'."), arg);
if (type != OBJ_BLOB) { if (type != OBJ_BLOB) {
strbuf_release(&msg->buf); strbuf_release(&msg->buf);
@ -722,7 +722,7 @@ static int append_edit(int argc, const char **argv, const char *prefix,
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
char *prev_buf = repo_read_object_file(the_repository, note, &type, &size); char *prev_buf = odb_read_object(the_repository->objects, note, &type, &size);


if (!prev_buf) if (!prev_buf)
die(_("unable to read %s"), oid_to_hex(note)); die(_("unable to read %s"), oid_to_hex(note));

View File

@ -337,11 +337,11 @@ static void *get_delta(struct object_entry *entry)
void *buf, *base_buf, *delta_buf; void *buf, *base_buf, *delta_buf;
enum object_type type; enum object_type type;


buf = repo_read_object_file(the_repository, &entry->idx.oid, &type, buf = odb_read_object(the_repository->objects, &entry->idx.oid,
&size); &type, &size);
if (!buf) if (!buf)
die(_("unable to read %s"), oid_to_hex(&entry->idx.oid)); die(_("unable to read %s"), oid_to_hex(&entry->idx.oid));
base_buf = repo_read_object_file(the_repository, base_buf = odb_read_object(the_repository->objects,
&DELTA(entry)->idx.oid, &type, &DELTA(entry)->idx.oid, &type,
&base_size); &base_size);
if (!base_buf) if (!base_buf)
@ -506,7 +506,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
&size, NULL)) != NULL) &size, NULL)) != NULL)
buf = NULL; buf = NULL;
else { else {
buf = repo_read_object_file(the_repository, buf = odb_read_object(the_repository->objects,
&entry->idx.oid, &type, &entry->idx.oid, &type,
&size); &size);
if (!buf) if (!buf)
@ -1895,7 +1895,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
/* Did not find one. Either we got a bogus request or /* Did not find one. Either we got a bogus request or
* we need to read and perhaps cache. * we need to read and perhaps cache.
*/ */
data = repo_read_object_file(the_repository, oid, &type, &size); data = odb_read_object(the_repository->objects, oid, &type, &size);
if (!data) if (!data)
return NULL; return NULL;
if (type != OBJ_TREE) { if (type != OBJ_TREE) {
@ -2762,7 +2762,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
/* Load data if not already done */ /* Load data if not already done */
if (!trg->data) { if (!trg->data) {
packing_data_lock(&to_pack); packing_data_lock(&to_pack);
trg->data = repo_read_object_file(the_repository, trg->data = odb_read_object(the_repository->objects,
&trg_entry->idx.oid, &type, &trg_entry->idx.oid, &type,
&sz); &sz);
packing_data_unlock(&to_pack); packing_data_unlock(&to_pack);
@ -2777,7 +2777,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
} }
if (!src->data) { if (!src->data) {
packing_data_lock(&to_pack); packing_data_lock(&to_pack);
src->data = repo_read_object_file(the_repository, src->data = odb_read_object(the_repository->objects,
&src_entry->idx.oid, &type, &src_entry->idx.oid, &type,
&sz); &sz);
packing_data_unlock(&to_pack); packing_data_unlock(&to_pack);

View File

@ -244,7 +244,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
struct strbuf payload = STRBUF_INIT; struct strbuf payload = STRBUF_INIT;
struct strbuf signature = STRBUF_INIT; struct strbuf signature = STRBUF_INIT;


orig = buf = repo_read_object_file(the_repository, oid, &type, &size); orig = buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) if (!buf)
return; return;
if (parse_signature(buf, size, &payload, &signature)) { if (parse_signature(buf, size, &payload, &signature)) {
@ -407,7 +407,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
strbuf_addstr(sb, "object of unknown type"); strbuf_addstr(sb, "object of unknown type");
break; break;
case OBJ_COMMIT: case OBJ_COMMIT:
if ((buf = repo_read_object_file(the_repository, oid, &type, &size))) { if ((buf = odb_read_object(the_repository->objects, oid, &type, &size))) {
subject_len = find_commit_subject(buf, &subject_start); subject_len = find_commit_subject(buf, &subject_start);
strbuf_insert(sb, sb->len, subject_start, subject_len); strbuf_insert(sb, sb->len, subject_start, subject_len);
} else { } else {

View File

@ -14,7 +14,7 @@ static char *create_temp_file(struct object_id *oid)
unsigned long size; unsigned long size;
int fd; int fd;


buf = repo_read_object_file(the_repository, oid, &type, &size); buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf || type != OBJ_BLOB) if (!buf || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid)); die("unable to read blob object %s", oid_to_hex(oid));



View File

@ -516,8 +516,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
if (resolve_against_held(nr, &base_oid, delta_data, delta_size)) if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
return; return;


base = repo_read_object_file(the_repository, &base_oid, &type, base = odb_read_object(the_repository->objects, &base_oid,
&base_size); &type, &base_size);
if (!base) { if (!base) {
error("failed to read delta-pack base object %s", error("failed to read delta-pack base object %s",
oid_to_hex(&base_oid)); oid_to_hex(&base_oid));

View File

@ -305,7 +305,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
if (revs->max_age == -1 && revs->min_age == -1) if (revs->max_age == -1 && revs->min_age == -1)
goto out; goto out;


buf = repo_read_object_file(the_repository, &tag->oid, &type, &size); buf = odb_read_object(the_repository->objects, &tag->oid, &type, &size);
if (!buf) if (!buf)
goto out; goto out;
line = memmem(buf, size, "\ntagger ", 8); line = memmem(buf, size, "\ntagger ", 8);

View File

@ -325,7 +325,7 @@ static char *grab_blob(struct repository *r,
*size = fill_textconv(r, textconv, df, &blob); *size = fill_textconv(r, textconv, df, &blob);
free_filespec(df); free_filespec(df);
} else { } else {
blob = repo_read_object_file(r, oid, &type, size); blob = odb_read_object(r->objects, oid, &type, size);
if (!blob) if (!blob)
die(_("unable to read %s"), oid_to_hex(oid)); die(_("unable to read %s"), oid_to_hex(oid));
if (type != OBJ_BLOB) if (type != OBJ_BLOB)

View File

@ -374,7 +374,7 @@ const void *repo_get_commit_buffer(struct repository *r,
if (!ret) { if (!ret) {
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
ret = repo_read_object_file(r, &commit->object.oid, &type, &size); ret = odb_read_object(r->objects, &commit->object.oid, &type, &size);
if (!ret) if (!ret)
die("cannot read commit object %s", die("cannot read commit object %s",
oid_to_hex(&commit->object.oid)); oid_to_hex(&commit->object.oid));
@ -1275,8 +1275,8 @@ static void handle_signed_tag(const struct commit *parent, struct commit_extra_h
desc = merge_remote_util(parent); desc = merge_remote_util(parent);
if (!desc || !desc->obj) if (!desc || !desc->obj)
return; return;
buf = repo_read_object_file(the_repository, &desc->obj->oid, &type, buf = odb_read_object(the_repository->objects, &desc->obj->oid,
&size); &type, &size);
if (!buf || type != OBJ_TAG) if (!buf || type != OBJ_TAG)
goto free_return; goto free_return;
if (!parse_signature(buf, size, &payload, &signature)) if (!parse_signature(buf, size, &payload, &signature))

View File

@ -1942,7 +1942,7 @@ int git_config_from_blob_oid(config_fn_t fn,
unsigned long size; unsigned long size;
int ret; int ret;


buf = repo_read_object_file(repo, oid, &type, &size); buf = odb_read_object(repo->objects, oid, &type, &size);
if (!buf) if (!buf)
return error(_("unable to load config blob object '%s'"), name); return error(_("unable to load config blob object '%s'"), name);
if (type != OBJ_BLOB) { if (type != OBJ_BLOB) {

2
dir.c
View File

@ -302,7 +302,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
*size_out = 0; *size_out = 0;
*data_out = NULL; *data_out = NULL;


data = repo_read_object_file(the_repository, oid, &type, &sz); data = odb_read_object(the_repository->objects, oid, &type, &sz);
if (!data || type != OBJ_BLOB) { if (!data || type != OBJ_BLOB) {
free(data); free(data);
return -1; return -1;

View File

@ -93,7 +93,7 @@ void *read_blob_entry(const struct cache_entry *ce, size_t *size)
{ {
enum object_type type; enum object_type type;
unsigned long ul; unsigned long ul;
void *blob_data = repo_read_object_file(the_repository, &ce->oid, void *blob_data = odb_read_object(the_repository->objects, &ce->oid,
&type, &ul); &type, &ul);


*size = ul; *size = ul;

View File

@ -526,8 +526,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
struct object_id *oid = origins.items[i].util; struct object_id *oid = origins.items[i].util;
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
char *buf = repo_read_object_file(the_repository, oid, &type, char *buf = odb_read_object(the_repository->objects, oid,
&size); &type, &size);
char *origbuf = buf; char *origbuf = buf;
unsigned long len = size; unsigned long len = size;
struct signature_check sigc = { NULL }; struct signature_check sigc = { NULL };

2
fsck.c
View File

@ -1293,7 +1293,7 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,
if (oidset_contains(blobs_done, oid)) if (oidset_contains(blobs_done, oid))
continue; continue;


buf = repo_read_object_file(the_repository, oid, &type, &size); buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) { if (!buf) {
if (is_promisor_object(the_repository, oid)) if (is_promisor_object(the_repository, oid))
continue; continue;

4
grep.c
View File

@ -1931,8 +1931,8 @@ static int grep_source_load_oid(struct grep_source *gs)
{ {
enum object_type type; enum object_type type;


gs->buf = repo_read_object_file(gs->repo, gs->identifier, &type, gs->buf = odb_read_object(gs->repo->objects, gs->identifier,
&gs->size); &type, &gs->size);
if (!gs->buf) if (!gs->buf)
return error(_("'%s': unable to read %s"), return error(_("'%s': unable to read %s"),
gs->name, gs->name,

View File

@ -369,7 +369,7 @@ static void start_put(struct transfer_request *request)
ssize_t size; ssize_t size;
git_zstream stream; git_zstream stream;


unpacked = repo_read_object_file(the_repository, &request->obj->oid, unpacked = odb_read_object(the_repository->objects, &request->obj->oid,
&type, &len); &type, &len);
hdrlen = format_object_header(hdr, sizeof(hdr), type, len); hdrlen = format_object_header(hdr, sizeof(hdr), type, len);



View File

@ -196,7 +196,7 @@ int read_mailmap_blob(struct string_list *map, const char *name)
if (repo_get_oid(the_repository, name, &oid) < 0) if (repo_get_oid(the_repository, name, &oid) < 0)
return 0; return 0;


buf = repo_read_object_file(the_repository, &oid, &type, &size); buf = odb_read_object(the_repository->objects, &oid, &type, &size);
if (!buf) if (!buf)
return error("unable to read mailmap object at %s", name); return error("unable to read mailmap object at %s", name);
if (type != OBJ_BLOB) { if (type != OBJ_BLOB) {

View File

@ -63,7 +63,7 @@ static void *fill_tree_desc_strict(struct repository *r,
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;


buffer = repo_read_object_file(r, hash, &type, &size); buffer = odb_read_object(r->objects, hash, &type, &size);
if (!buffer) if (!buffer)
die("unable to read tree (%s)", oid_to_hex(hash)); die("unable to read tree (%s)", oid_to_hex(hash));
if (type != OBJ_TREE) if (type != OBJ_TREE)
@ -199,7 +199,7 @@ static int splice_tree(struct repository *r,
if (*subpath) if (*subpath)
subpath++; subpath++;


buf = repo_read_object_file(r, oid1, &type, &sz); buf = odb_read_object(r->objects, oid1, &type, &sz);
if (!buf) if (!buf)
die("cannot read tree %s", oid_to_hex(oid1)); die("cannot read tree %s", oid_to_hex(oid1));
init_tree_desc(&desc, oid1, buf, sz); init_tree_desc(&desc, oid1, buf, sz);

View File

@ -12,8 +12,8 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;


buf = repo_read_object_file(the_repository, &obj->object.oid, &type, buf = odb_read_object(the_repository->objects, &obj->object.oid,
&size); &type, &size);
if (!buf) if (!buf)
return -1; return -1;
if (type != OBJ_BLOB) { if (type != OBJ_BLOB) {
@ -79,7 +79,7 @@ void *merge_blobs(struct index_state *istate, const char *path,
return NULL; return NULL;
if (!our) if (!our)
our = their; our = their;
return repo_read_object_file(the_repository, &our->object.oid, return odb_read_object(the_repository->objects, &our->object.oid,
&type, size); &type, size);
} }



View File

@ -3629,7 +3629,7 @@ static int read_oid_strbuf(struct merge_options *opt,
void *buf; void *buf;
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
buf = repo_read_object_file(the_repository, oid, &type, &size); buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) { if (!buf) {
path_msg(opt, ERROR_OBJECT_READ_FAILED, 0, path_msg(opt, ERROR_OBJECT_READ_FAILED, 0,
path, NULL, NULL, NULL, path, NULL, NULL, NULL,

View File

@ -87,7 +87,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
value_oid = get_note(&c->tree, key_oid); value_oid = get_note(&c->tree, key_oid);
if (!value_oid) if (!value_oid)
return NULL; return NULL;
value = repo_read_object_file(the_repository, value_oid, &type, &size); value = odb_read_object(the_repository->objects, value_oid, &type, &size);


*outsize = size; *outsize = size;
return value; return value;

View File

@ -340,7 +340,7 @@ static void write_note_to_worktree(const struct object_id *obj,
{ {
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
void *buf = repo_read_object_file(the_repository, note, &type, &size); void *buf = odb_read_object(the_repository->objects, note, &type, &size);


if (!buf) if (!buf)
die("cannot read note %s for object %s", die("cannot read note %s for object %s",

View File

@ -816,14 +816,14 @@ int combine_notes_concatenate(struct object_id *cur_oid,


/* read in both note blob objects */ /* read in both note blob objects */
if (!is_null_oid(new_oid)) if (!is_null_oid(new_oid))
new_msg = repo_read_object_file(the_repository, new_oid, new_msg = odb_read_object(the_repository->objects, new_oid,
&new_type, &new_len); &new_type, &new_len);
if (!new_msg || !new_len || new_type != OBJ_BLOB) { if (!new_msg || !new_len || new_type != OBJ_BLOB) {
free(new_msg); free(new_msg);
return 0; return 0;
} }
if (!is_null_oid(cur_oid)) if (!is_null_oid(cur_oid))
cur_msg = repo_read_object_file(the_repository, cur_oid, cur_msg = odb_read_object(the_repository->objects, cur_oid,
&cur_type, &cur_len); &cur_type, &cur_len);
if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) { if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
free(cur_msg); free(cur_msg);
@ -880,7 +880,7 @@ static int string_list_add_note_lines(struct string_list *list,
return 0; return 0;


/* read_sha1_file NUL-terminates */ /* read_sha1_file NUL-terminates */
data = repo_read_object_file(the_repository, oid, &t, &len); data = odb_read_object(the_repository->objects, oid, &t, &len);
if (t != OBJ_BLOB || !data || !len) { if (t != OBJ_BLOB || !data || !len) {
free(data); free(data);
return t != OBJ_BLOB || !data; return t != OBJ_BLOB || !data;
@ -1290,7 +1290,8 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
if (!oid) if (!oid)
return; return;


if (!(msg = repo_read_object_file(the_repository, oid, &type, &msglen)) || type != OBJ_BLOB) { if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
type != OBJ_BLOB) {
free(msg); free(msg);
return; return;
} }

View File

@ -335,7 +335,7 @@ struct object *parse_object_with_flags(struct repository *r,
return &lookup_tree(r, oid)->object; return &lookup_tree(r, oid)->object;
} }


buffer = repo_read_object_file(r, oid, &type, &size); buffer = odb_read_object(r->objects, oid, &type, &size);
if (buffer) { if (buffer) {
if (!skip_hash && if (!skip_hash &&
check_object_signature(r, repl, buffer, size, type) < 0) { check_object_signature(r, repl, buffer, size, type) < 0) {

13
odb.c
View File

@ -30,7 +30,7 @@ KHASH_INIT(odb_path_map, const char * /* key: odb_path */,


/* /*
* This is meant to hold a *small* number of objects that you would * This is meant to hold a *small* number of objects that you would
* want repo_read_object_file() to be able to return, but yet you do not want * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only * to write them into the object store (e.g. a browse-only
* application). * application).
*/ */
@ -887,12 +887,7 @@ int pretend_object_file(struct repository *repo,
return 0; return 0;
} }


/* void *odb_read_object(struct object_database *odb,
* This function dies on corrupt objects; the callers who want to
* deal with them should arrange to call odb_read_object_info_extended() and give
* error messages themselves.
*/
void *repo_read_object_file(struct repository *r,
const struct object_id *oid, const struct object_id *oid,
enum object_type *type, enum object_type *type,
unsigned long *size) unsigned long *size)
@ -904,7 +899,7 @@ void *repo_read_object_file(struct repository *r,
oi.typep = type; oi.typep = type;
oi.sizep = size; oi.sizep = size;
oi.contentp = &data; oi.contentp = &data;
if (odb_read_object_info_extended(r->objects, oid, &oi, flags)) if (odb_read_object_info_extended(odb, oid, &oi, flags))
return NULL; return NULL;


return data; return data;
@ -926,7 +921,7 @@ void *read_object_with_reference(struct repository *r,
int ref_length = -1; int ref_length = -1;
const char *ref_type = NULL; const char *ref_type = NULL;


buffer = repo_read_object_file(r, &actual_oid, &type, &isize); buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
if (!buffer) if (!buffer)
return NULL; return NULL;
if (type == required_type) { if (type == required_type) {

23
odb.h
View File

@ -140,7 +140,7 @@ struct object_database {


/* /*
* This is meant to hold a *small* number of objects that you would * This is meant to hold a *small* number of objects that you would
* want repo_read_object_file() to be able to return, but yet you do not want * want odb_read_object() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only * to write them into the object store (e.g. a browse-only
* application). * application).
*/ */
@ -260,7 +260,16 @@ void odb_add_to_alternates_file(struct object_database *odb,
void odb_add_to_alternates_memory(struct object_database *odb, void odb_add_to_alternates_memory(struct object_database *odb,
const char *dir); const char *dir);


void *repo_read_object_file(struct repository *r, /*
* Read an object from the database. Returns the object data and assigns object
* type and size to the `type` and `size` pointers, if these pointers are
* non-NULL. Returns a `NULL` pointer in case the object does not exist.
*
* This function dies on corrupt objects; the callers who want to deal with
* them should arrange to call odb_read_object_info_extended() and give error
* messages themselves.
*/
void *odb_read_object(struct object_database *odb,
const struct object_id *oid, const struct object_id *oid,
enum object_type *type, enum object_type *type,
unsigned long *size); unsigned long *size);
@ -371,7 +380,7 @@ void odb_assert_oid_type(struct object_database *odb,


/* /*
* Enabling the object read lock allows multiple threads to safely call the * Enabling the object read lock allows multiple threads to safely call the
* following functions in parallel: repo_read_object_file(), * following functions in parallel: odb_read_object(),
* read_object_with_reference(), odb_read_object_info() and odb(). * read_object_with_reference(), odb_read_object_info() and odb().
* *
* obj_read_lock() and obj_read_unlock() may also be used to protect other * obj_read_lock() and obj_read_unlock() may also be used to protect other
@ -446,4 +455,12 @@ static inline int oid_object_info(struct repository *r,
return odb_read_object_info(r->objects, oid, sizep); return odb_read_object_info(r->objects, oid, sizep);
} }


static inline void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
enum object_type *type,
unsigned long *size)
{
return odb_read_object(r->objects, oid, type, size);
}

#endif /* ODB_H */ #endif /* ODB_H */

View File

@ -254,7 +254,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
if (strbuf_readlink(&sb, ce->name, expected_size)) if (strbuf_readlink(&sb, ce->name, expected_size))
return -1; return -1;


buffer = repo_read_object_file(the_repository, &ce->oid, &type, &size); buffer = odb_read_object(the_repository->objects, &ce->oid, &type, &size);
if (buffer) { if (buffer) {
if (size == sb.len) if (size == sb.len)
match = memcmp(buffer, sb.buf, size); match = memcmp(buffer, sb.buf, size);
@ -3485,7 +3485,7 @@ void *read_blob_data_from_index(struct index_state *istate,
} }
if (pos < 0) if (pos < 0)
return NULL; return NULL;
data = repo_read_object_file(the_repository, &istate->cache[pos]->oid, data = odb_read_object(the_repository->objects, &istate->cache[pos]->oid,
&type, &sz); &type, &sz);
if (!data || type != OBJ_BLOB) { if (!data || type != OBJ_BLOB) {
free(data); free(data);

View File

@ -140,8 +140,8 @@ static int tree_is_complete(const struct object_id *oid)
if (!tree->buffer) { if (!tree->buffer) {
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
void *data = repo_read_object_file(the_repository, oid, &type, void *data = odb_read_object(the_repository->objects, oid,
&size); &type, &size);
if (!data) { if (!data) {
tree->object.flags |= INCOMPLETE; tree->object.flags |= INCOMPLETE;
return 0; return 0;

View File

@ -1000,9 +1000,8 @@ static int handle_cache(struct index_state *istate,
break; break;
i = ce_stage(ce) - 1; i = ce_stage(ce) - 1;
if (!mmfile[i].ptr) { if (!mmfile[i].ptr) {
mmfile[i].ptr = repo_read_object_file(the_repository, mmfile[i].ptr = odb_read_object(the_repository->objects,
&ce->oid, &type, &ce->oid, &type, &size);
&size);
if (!mmfile[i].ptr) if (!mmfile[i].ptr)
die(_("unable to read %s"), die(_("unable to read %s"),
oid_to_hex(&ce->oid)); oid_to_hex(&ce->oid));

View File

@ -743,8 +743,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
if (submodule) if (submodule)
goto out; goto out;


config = repo_read_object_file(the_repository, &oid, &type, config = odb_read_object(the_repository->objects, &oid,
&config_size); &type, &config_size);
if (!config || type != OBJ_BLOB) if (!config || type != OBJ_BLOB)
goto out; goto out;



6
tag.c
View File

@ -60,7 +60,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV), repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV),
type_name(type)); type_name(type));


buf = repo_read_object_file(the_repository, oid, &type, &size); buf = odb_read_object(the_repository->objects, oid, &type, &size);
if (!buf) if (!buf)
return error("%s: unable to read file.", return error("%s: unable to read file.",
name_to_report ? name_to_report ?
@ -222,8 +222,8 @@ int parse_tag(struct tag *item)


if (item->object.parsed) if (item->object.parsed)
return 0; return 0;
data = repo_read_object_file(the_repository, &item->object.oid, &type, data = odb_read_object(the_repository->objects, &item->object.oid,
&size); &type, &size);
if (!data) if (!data)
return error("Could not read %s", return error("Could not read %s",
oid_to_hex(&item->object.oid)); oid_to_hex(&item->object.oid));

View File

@ -795,7 +795,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
*/ */
retval = DANGLING_SYMLINK; retval = DANGLING_SYMLINK;


contents = repo_read_object_file(r, contents = odb_read_object(r->objects,
&current_tree_oid, &type, &current_tree_oid, &type,
&link_len); &link_len);



2
tree.c
View File

@ -193,7 +193,7 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)


if (item->object.parsed) if (item->object.parsed)
return 0; return 0;
buffer = repo_read_object_file(the_repository, &item->object.oid, buffer = odb_read_object(the_repository->objects, &item->object.oid,
&type, &size); &type, &size);
if (!buffer) if (!buffer)
return quiet_on_missing ? -1 : return quiet_on_missing ? -1 :

View File

@ -187,7 +187,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
return; return;
} }


ptr->ptr = repo_read_object_file(the_repository, oid, &type, &size); ptr->ptr = odb_read_object(the_repository->objects, oid, &type, &size);
if (!ptr->ptr || type != OBJ_BLOB) if (!ptr->ptr || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid)); die("unable to read blob object %s", oid_to_hex(oid));
ptr->size = size; ptr->size = size;