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>

Patrick Steinhardt committed Jul 1, 2025 at 14:22 UTC d4ff88aee3967e5d1ef1237cd9b8792b7cdb304c
47 files changed +157 -150
apply.c
+5 -5
@@ -3210,8 +3210,8 @@ static int apply_binary(struct apply_state *state,
3210 unsigned long size;
3211 char *result;
3212
3213 - result = repo_read_object_file(the_repository, &oid, &type,
3214 - &size);
3213 + result = odb_read_object(the_repository->objects, &oid,
3214 + &type, &size);
3215 if (!result)
3216 return error(_("the necessary postimage %s for "
3217 "'%s' cannot be read"),
@@ -3273,8 +3273,8 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
3273 unsigned long sz;
3274 char *result;
3275
3276 - result = repo_read_object_file(the_repository, oid, &type,
3277 - &sz);
3276 + result = odb_read_object(the_repository->objects, oid,
3277 + &type, &sz);
3278 if (!result)
3279 return -1;
3280 /* XXX read_sha1_file NUL-terminates */
@@ -3503,7 +3503,7 @@ static int resolve_to(struct image *image, const struct object_id *result_id)
3503
3504 image_clear(image);
3505
3506 - data = repo_read_object_file(the_repository, result_id, &type, &size);
3506 + data = odb_read_object(the_repository->objects, result_id, &type, &size);
3507 if (!data || type != OBJ_BLOB)
3508 die("unable to read blob object %s", oid_to_hex(result_id));
3509 strbuf_attach(&image->buf, data, size, size + 1);
archive.c
+1 -1
@@ -98,7 +98,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
98 (args->tree ? &args->tree->object.oid : NULL), oid);
99
100 path += args->baselen;
101 - buffer = repo_read_object_file(the_repository, oid, type, sizep);
101 + buffer = odb_read_object(the_repository->objects, oid, type, sizep);
102 if (buffer && S_ISREG(mode)) {
103 struct strbuf buf = STRBUF_INIT;
104 size_t size = 0;
attr.c
+1 -1
@@ -779,7 +779,7 @@ static struct attr_stack *read_attr_from_blob(struct index_state *istate,
779 if (get_tree_entry(istate->repo, tree_oid, path, &oid, &mode))
780 return NULL;
781
782 - buf = repo_read_object_file(istate->repo, &oid, &type, &sz);
782 + buf = odb_read_object(istate->repo->objects, &oid, &type, &sz);
783 if (!buf || type != OBJ_BLOB) {
784 free(buf);
785 return NULL;
bisect.c
+3 -3
@@ -155,9 +155,9 @@ static void show_list(const char *debug, int counted, int nr,
155 unsigned commit_flags = commit->object.flags;
156 enum object_type type;
157 unsigned long size;
158 - char *buf = repo_read_object_file(the_repository,
159 - &commit->object.oid, &type,
160 - &size);
158 + char *buf = odb_read_object(the_repository->objects,
159 + &commit->object.oid, &type,
160 + &size);
161 const char *subject_start;
162 int subject_len;
163
blame.c
+6 -7
@@ -1041,9 +1041,9 @@ static void fill_origin_blob(struct diff_options *opt,
1041 &o->blob_oid, 1, &file->ptr, &file_size))
1042 ;
1043 else
1044 - file->ptr = repo_read_object_file(the_repository,
1045 - &o->blob_oid, &type,
1046 - &file_size);
1044 + file->ptr = odb_read_object(the_repository->objects,
1045 + &o->blob_oid, &type,
1046 + &file_size);
1047 file->size = file_size;
1048
1049 if (!file->ptr)
@@ -2869,10 +2869,9 @@ void setup_scoreboard(struct blame_scoreboard *sb,
2869 &sb->final_buf_size))
2870 ;
2871 else
2872 - sb->final_buf = repo_read_object_file(the_repository,
2873 - &o->blob_oid,
2874 - &type,
2875 - &sb->final_buf_size);
2872 + sb->final_buf = odb_read_object(the_repository->objects,
2873 + &o->blob_oid, &type,
2874 + &sb->final_buf_size);
2875
2876 if (!sb->final_buf)
2877 die(_("cannot read blob %s for path %s"),
builtin/cat-file.c
+11 -15
@@ -74,7 +74,7 @@ static int filter_object(const char *path, unsigned mode,
74 {
75 enum object_type type;
76
77 - *buf = repo_read_object_file(the_repository, oid, &type, size);
77 + *buf = odb_read_object(the_repository->objects, oid, &type, size);
78 if (!*buf)
79 return error(_("cannot read object %s '%s'"),
80 oid_to_hex(oid), path);
@@ -197,8 +197,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
197 ret = stream_blob(&oid);
198 goto cleanup;
199 }
200 - buf = repo_read_object_file(the_repository, &oid, &type,
201 - &size);
200 + buf = odb_read_object(the_repository->objects, &oid,
201 + &type, &size);
202 if (!buf)
203 die("Cannot read object %s", obj_name);
204
@@ -219,10 +219,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
219 struct object_id blob_oid;
220 if (odb_read_object_info(the_repository->objects,
221 &oid, NULL) == OBJ_TAG) {
222 - char *buffer = repo_read_object_file(the_repository,
223 - &oid,
224 - &type,
225 - &size);
222 + char *buffer = odb_read_object(the_repository->objects,
223 + &oid, &type, &size);
224 const char *target;
225
226 if (!buffer)
@@ -403,10 +401,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
401 if (!textconv_object(the_repository,
402 data->rest, 0100644, oid,
403 1, &contents, &size))
406 - contents = repo_read_object_file(the_repository,
407 - oid,
408 - &type,
409 - &size);
404 + contents = odb_read_object(the_repository->objects,
405 + oid, &type, &size);
406 if (!contents)
407 die("could not convert '%s' %s",
408 oid_to_hex(oid), data->rest);
@@ -423,8 +419,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
419 unsigned long size;
420 void *contents;
421
426 - contents = repo_read_object_file(the_repository, oid, &type,
427 - &size);
422 + contents = odb_read_object(the_repository->objects, oid,
423 + &type, &size);
424 if (!contents)
425 die("object %s disappeared", oid_to_hex(oid));
426
@@ -533,8 +529,8 @@ static void batch_object_write(const char *obj_name,
529 size_t s = data->size;
530 char *buf = NULL;
531
536 - buf = repo_read_object_file(the_repository, &data->oid, &data->type,
537 - &data->size);
532 + buf = odb_read_object(the_repository->objects, &data->oid,
533 + &data->type, &data->size);
534 if (!buf)
535 die(_("unable to read %s"), oid_to_hex(&data->oid));
536 buf = replace_idents_using_mailmap(buf, &s);
builtin/difftool.c
+1 -1
@@ -320,7 +320,7 @@ static char *get_symlink(struct repository *repo,
320 } else {
321 enum object_type type;
322 unsigned long size;
323 - data = repo_read_object_file(repo, oid, &type, &size);
323 + data = odb_read_object(repo->objects, oid, &type, &size);
324 if (!data)
325 die(_("could not read object %s for symlink %s"),
326 oid_to_hex(oid), path);
builtin/fast-export.c
+3 -3
@@ -323,7 +323,7 @@ static void export_blob(const struct object_id *oid)
323 object = (struct object *)lookup_blob(the_repository, oid);
324 eaten = 0;
325 } else {
326 - buf = repo_read_object_file(the_repository, oid, &type, &size);
326 + buf = odb_read_object(the_repository->objects, oid, &type, &size);
327 if (!buf)
328 die("could not read blob %s", oid_to_hex(oid));
329 if (check_object_signature(the_repository, oid, buf, size,
@@ -869,8 +869,8 @@ static void handle_tag(const char *name, struct tag *tag)
869 return;
870 }
871
872 - buf = repo_read_object_file(the_repository, &tag->object.oid, &type,
873 - &size);
872 + buf = odb_read_object(the_repository->objects, &tag->object.oid,
873 + &type, &size);
874 if (!buf)
875 die("could not read tag %s", oid_to_hex(&tag->object.oid));
876 message = memmem(buf, size, "\n\n", 2);
builtin/fast-import.c
+4 -4
@@ -1265,7 +1265,7 @@ static void load_tree(struct tree_entry *root)
1265 die("Can't load tree %s", oid_to_hex(oid));
1266 } else {
1267 enum object_type type;
1268 - buf = repo_read_object_file(the_repository, oid, &type, &size);
1268 + buf = odb_read_object(the_repository->objects, oid, &type, &size);
1269 if (!buf || type != OBJ_TREE)
1270 die("Can't load tree %s", oid_to_hex(oid));
1271 }
@@ -3002,7 +3002,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
3002 char *buf;
3003
3004 if (!oe || oe->pack_id == MAX_PACK_ID) {
3005 - buf = repo_read_object_file(the_repository, oid, &type, &size);
3005 + buf = odb_read_object(the_repository->objects, oid, &type, &size);
3006 } else {
3007 type = oe->type;
3008 buf = gfi_unpack_entry(oe, &size);
@@ -3110,8 +3110,8 @@ static struct object_entry *dereference(struct object_entry *oe,
3110 buf = gfi_unpack_entry(oe, &size);
3111 } else {
3112 enum object_type unused;
3113 - buf = repo_read_object_file(the_repository, oid, &unused,
3114 - &size);
3113 + buf = odb_read_object(the_repository->objects, oid,
3114 + &unused, &size);
3115 }
3116 if (!buf)
3117 die("Can't load object %s", oid_to_hex(oid));
builtin/grep.c
+4 -4
@@ -573,8 +573,8 @@ static int grep_cache(struct grep_opt *opt,
573 void *data;
574 unsigned long size;
575
576 - data = repo_read_object_file(the_repository, &ce->oid,
577 - &type, &size);
576 + data = odb_read_object(the_repository->objects, &ce->oid,
577 + &type, &size);
578 if (!data)
579 die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
580 init_tree_desc(&tree, &ce->oid, data, size);
@@ -666,8 +666,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
666 void *data;
667 unsigned long size;
668
669 - data = repo_read_object_file(the_repository,
670 - &entry.oid, &type, &size);
669 + data = odb_read_object(the_repository->objects,
670 + &entry.oid, &type, &size);
671 if (!data)
672 die(_("unable to read tree (%s)"),
673 oid_to_hex(&entry.oid));
builtin/index-pack.c
+4 -4
@@ -914,8 +914,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
914 die(_("cannot read existing object info %s"), oid_to_hex(oid));
915 if (has_type != type || has_size != size)
916 die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
917 - has_data = repo_read_object_file(the_repository, oid,
918 - &has_type, &has_size);
917 + has_data = odb_read_object(the_repository->objects, oid,
918 + &has_type, &has_size);
919 read_unlock();
920 if (!data)
921 data = new_data = get_data_from_pack(obj_entry);
@@ -1521,8 +1521,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
1521
1522 if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
1523 continue;
1524 - data = repo_read_object_file(the_repository, &d->oid, &type,
1525 - &size);
1524 + data = odb_read_object(the_repository->objects, &d->oid,
1525 + &type, &size);
1526 if (!data)
1527 continue;
1528
builtin/log.c
+1 -1
@@ -714,7 +714,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
714 {
715 unsigned long size;
716 enum object_type type;
717 - char *buf = repo_read_object_file(the_repository, oid, &type, &size);
717 + char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
718 unsigned long offset = 0;
719
720 if (!buf)
builtin/merge-tree.c
+6 -6
@@ -75,9 +75,9 @@ static void *result(struct merge_list *entry, unsigned long *size)
75 const char *path = entry->path;
76
77 if (!entry->stage)
78 - return repo_read_object_file(the_repository,
79 - &entry->blob->object.oid, &type,
80 - size);
78 + return odb_read_object(the_repository->objects,
79 + &entry->blob->object.oid, &type,
80 + size);
81 base = NULL;
82 if (entry->stage == 1) {
83 base = entry->blob;
@@ -100,9 +100,9 @@ static void *origin(struct merge_list *entry, unsigned long *size)
100 enum object_type type;
101 while (entry) {
102 if (entry->stage == 2)
103 - return repo_read_object_file(the_repository,
104 - &entry->blob->object.oid,
105 - &type, size);
103 + return odb_read_object(the_repository->objects,
104 + &entry->blob->object.oid,
105 + &type, size);
106 entry = entry->link;
107 }
108 return NULL;
builtin/mktag.c
+2 -2
@@ -54,8 +54,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
54 void *buffer;
55 const struct object_id *repl;
56
57 - buffer = repo_read_object_file(the_repository, tagged_oid, &type,
58 - &size);
57 + buffer = odb_read_object(the_repository->objects, tagged_oid,
58 + &type, &size);
59 if (!buffer)
60 die(_("could not read tagged object '%s'"),
61 oid_to_hex(tagged_oid));
builtin/notes.c
+3 -3
@@ -152,7 +152,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
152 {
153 unsigned long size;
154 enum object_type type;
155 - char *buf = repo_read_object_file(the_repository, oid, &type, &size);
155 + char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
156 if (buf) {
157 if (size)
158 write_or_die(fd, buf, size);
@@ -319,7 +319,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
319 strbuf_init(&msg->buf, 0);
320 if (repo_get_oid(the_repository, arg, &object))
321 die(_("failed to resolve '%s' as a valid ref."), arg);
322 - if (!(value = repo_read_object_file(the_repository, &object, &type, &len)))
322 + if (!(value = odb_read_object(the_repository->objects, &object, &type, &len)))
323 die(_("failed to read object '%s'."), arg);
324 if (type != OBJ_BLOB) {
325 strbuf_release(&msg->buf);
@@ -722,7 +722,7 @@ static int append_edit(int argc, const char **argv, const char *prefix,
722 unsigned long size;
723 enum object_type type;
724 struct strbuf buf = STRBUF_INIT;
725 - char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
725 + char *prev_buf = odb_read_object(the_repository->objects, note, &type, &size);
726
727 if (!prev_buf)
728 die(_("unable to read %s"), oid_to_hex(note));
builtin/pack-objects.c
+15 -15
@@ -337,13 +337,13 @@ static void *get_delta(struct object_entry *entry)
337 void *buf, *base_buf, *delta_buf;
338 enum object_type type;
339
340 - buf = repo_read_object_file(the_repository, &entry->idx.oid, &type,
341 - &size);
340 + buf = odb_read_object(the_repository->objects, &entry->idx.oid,
341 + &type, &size);
342 if (!buf)
343 die(_("unable to read %s"), oid_to_hex(&entry->idx.oid));
344 - base_buf = repo_read_object_file(the_repository,
345 - &DELTA(entry)->idx.oid, &type,
346 - &base_size);
344 + base_buf = odb_read_object(the_repository->objects,
345 + &DELTA(entry)->idx.oid, &type,
346 + &base_size);
347 if (!base_buf)
348 die("unable to read %s",
349 oid_to_hex(&DELTA(entry)->idx.oid));
@@ -506,9 +506,9 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
506 &size, NULL)) != NULL)
507 buf = NULL;
508 else {
509 - buf = repo_read_object_file(the_repository,
510 - &entry->idx.oid, &type,
511 - &size);
509 + buf = odb_read_object(the_repository->objects,
510 + &entry->idx.oid, &type,
511 + &size);
512 if (!buf)
513 die(_("unable to read %s"),
514 oid_to_hex(&entry->idx.oid));
@@ -1895,7 +1895,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
1895 /* Did not find one. Either we got a bogus request or
1896 * we need to read and perhaps cache.
1897 */
1898 - data = repo_read_object_file(the_repository, oid, &type, &size);
1898 + data = odb_read_object(the_repository->objects, oid, &type, &size);
1899 if (!data)
1900 return NULL;
1901 if (type != OBJ_TREE) {
@@ -2762,9 +2762,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
2762 /* Load data if not already done */
2763 if (!trg->data) {
2764 packing_data_lock(&to_pack);
2765 - trg->data = repo_read_object_file(the_repository,
2766 - &trg_entry->idx.oid, &type,
2767 - &sz);
2765 + trg->data = odb_read_object(the_repository->objects,
2766 + &trg_entry->idx.oid, &type,
2767 + &sz);
2768 packing_data_unlock(&to_pack);
2769 if (!trg->data)
2770 die(_("object %s cannot be read"),
@@ -2777,9 +2777,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
2777 }
2778 if (!src->data) {
2779 packing_data_lock(&to_pack);
2780 - src->data = repo_read_object_file(the_repository,
2781 - &src_entry->idx.oid, &type,
2782 - &sz);
2780 + src->data = odb_read_object(the_repository->objects,
2781 + &src_entry->idx.oid, &type,
2782 + &sz);
2783 packing_data_unlock(&to_pack);
2784 if (!src->data) {
2785 if (src_entry->preferred_base) {
builtin/tag.c
+2 -2
@@ -244,7 +244,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
244 struct strbuf payload = STRBUF_INIT;
245 struct strbuf signature = STRBUF_INIT;
246
247 - orig = buf = repo_read_object_file(the_repository, oid, &type, &size);
247 + orig = buf = odb_read_object(the_repository->objects, oid, &type, &size);
248 if (!buf)
249 return;
250 if (parse_signature(buf, size, &payload, &signature)) {
@@ -407,7 +407,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
407 strbuf_addstr(sb, "object of unknown type");
408 break;
409 case OBJ_COMMIT:
410 - if ((buf = repo_read_object_file(the_repository, oid, &type, &size))) {
410 + if ((buf = odb_read_object(the_repository->objects, oid, &type, &size))) {
411 subject_len = find_commit_subject(buf, &subject_start);
412 strbuf_insert(sb, sb->len, subject_start, subject_len);
413 } else {
builtin/unpack-file.c
+1 -1
@@ -14,7 +14,7 @@ static char *create_temp_file(struct object_id *oid)
14 unsigned long size;
15 int fd;
16
17 - buf = repo_read_object_file(the_repository, oid, &type, &size);
17 + buf = odb_read_object(the_repository->objects, oid, &type, &size);
18 if (!buf || type != OBJ_BLOB)
19 die("unable to read blob object %s", oid_to_hex(oid));
20
builtin/unpack-objects.c
+2 -2
@@ -516,8 +516,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
516 if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
517 return;
518
519 - base = repo_read_object_file(the_repository, &base_oid, &type,
520 - &base_size);
519 + base = odb_read_object(the_repository->objects, &base_oid,
520 + &type, &base_size);
521 if (!base) {
522 error("failed to read delta-pack base object %s",
523 oid_to_hex(&base_oid));
bundle.c
+1 -1
@@ -305,7 +305,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
305 if (revs->max_age == -1 && revs->min_age == -1)
306 goto out;
307
308 - buf = repo_read_object_file(the_repository, &tag->oid, &type, &size);
308 + buf = odb_read_object(the_repository->objects, &tag->oid, &type, &size);
309 if (!buf)
310 goto out;
311 line = memmem(buf, size, "\ntagger ", 8);
combine-diff.c
+1 -1
@@ -325,7 +325,7 @@ static char *grab_blob(struct repository *r,
325 *size = fill_textconv(r, textconv, df, &blob);
326 free_filespec(df);
327 } else {
328 - blob = repo_read_object_file(r, oid, &type, size);
328 + blob = odb_read_object(r->objects, oid, &type, size);
329 if (!blob)
330 die(_("unable to read %s"), oid_to_hex(oid));
331 if (type != OBJ_BLOB)
commit.c
+3 -3
@@ -374,7 +374,7 @@ const void *repo_get_commit_buffer(struct repository *r,
374 if (!ret) {
375 enum object_type type;
376 unsigned long size;
377 - ret = repo_read_object_file(r, &commit->object.oid, &type, &size);
377 + ret = odb_read_object(r->objects, &commit->object.oid, &type, &size);
378 if (!ret)
379 die("cannot read commit object %s",
380 oid_to_hex(&commit->object.oid));
@@ -1275,8 +1275,8 @@ static void handle_signed_tag(const struct commit *parent, struct commit_extra_h
1275 desc = merge_remote_util(parent);
1276 if (!desc || !desc->obj)
1277 return;
1278 - buf = repo_read_object_file(the_repository, &desc->obj->oid, &type,
1279 - &size);
1278 + buf = odb_read_object(the_repository->objects, &desc->obj->oid,
1279 + &type, &size);
1280 if (!buf || type != OBJ_TAG)
1281 goto free_return;
1282 if (!parse_signature(buf, size, &payload, &signature))
config.c
+1 -1
@@ -1942,7 +1942,7 @@ int git_config_from_blob_oid(config_fn_t fn,
1942 unsigned long size;
1943 int ret;
1944
1945 - buf = repo_read_object_file(repo, oid, &type, &size);
1945 + buf = odb_read_object(repo->objects, oid, &type, &size);
1946 if (!buf)
1947 return error(_("unable to load config blob object '%s'"), name);
1948 if (type != OBJ_BLOB) {
dir.c
+1 -1
@@ -302,7 +302,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
302 *size_out = 0;
303 *data_out = NULL;
304
305 - data = repo_read_object_file(the_repository, oid, &type, &sz);
305 + data = odb_read_object(the_repository->objects, oid, &type, &sz);
306 if (!data || type != OBJ_BLOB) {
307 free(data);
308 return -1;
entry.c
+2 -2
@@ -93,8 +93,8 @@ void *read_blob_entry(const struct cache_entry *ce, size_t *size)
93 {
94 enum object_type type;
95 unsigned long ul;
96 - void *blob_data = repo_read_object_file(the_repository, &ce->oid,
97 - &type, &ul);
96 + void *blob_data = odb_read_object(the_repository->objects, &ce->oid,
97 + &type, &ul);
98
99 *size = ul;
100 if (blob_data) {
fmt-merge-msg.c
+2 -2
@@ -526,8 +526,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
526 struct object_id *oid = origins.items[i].util;
527 enum object_type type;
528 unsigned long size;
529 - char *buf = repo_read_object_file(the_repository, oid, &type,
530 - &size);
529 + char *buf = odb_read_object(the_repository->objects, oid,
530 + &type, &size);
531 char *origbuf = buf;
532 unsigned long len = size;
533 struct signature_check sigc = { NULL };
fsck.c
+1 -1
@@ -1293,7 +1293,7 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,
1293 if (oidset_contains(blobs_done, oid))
1294 continue;
1295
1296 - buf = repo_read_object_file(the_repository, oid, &type, &size);
1296 + buf = odb_read_object(the_repository->objects, oid, &type, &size);
1297 if (!buf) {
1298 if (is_promisor_object(the_repository, oid))
1299 continue;
grep.c
+2 -2
@@ -1931,8 +1931,8 @@ static int grep_source_load_oid(struct grep_source *gs)
1931 {
1932 enum object_type type;
1933
1934 - gs->buf = repo_read_object_file(gs->repo, gs->identifier, &type,
1935 - &gs->size);
1934 + gs->buf = odb_read_object(gs->repo->objects, gs->identifier,
1935 + &type, &gs->size);
1936 if (!gs->buf)
1937 return error(_("'%s': unable to read %s"),
1938 gs->name,
http-push.c
+2 -2
@@ -369,8 +369,8 @@ static void start_put(struct transfer_request *request)
369 ssize_t size;
370 git_zstream stream;
371
372 - unpacked = repo_read_object_file(the_repository, &request->obj->oid,
373 - &type, &len);
372 + unpacked = odb_read_object(the_repository->objects, &request->obj->oid,
373 + &type, &len);
374 hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
375
376 /* Set it up */
mailmap.c
+1 -1
@@ -196,7 +196,7 @@ int read_mailmap_blob(struct string_list *map, const char *name)
196 if (repo_get_oid(the_repository, name, &oid) < 0)
197 return 0;
198
199 - buf = repo_read_object_file(the_repository, &oid, &type, &size);
199 + buf = odb_read_object(the_repository->objects, &oid, &type, &size);
200 if (!buf)
201 return error("unable to read mailmap object at %s", name);
202 if (type != OBJ_BLOB) {
match-trees.c
+2 -2
@@ -63,7 +63,7 @@ static void *fill_tree_desc_strict(struct repository *r,
63 enum object_type type;
64 unsigned long size;
65
66 - buffer = repo_read_object_file(r, hash, &type, &size);
66 + buffer = odb_read_object(r->objects, hash, &type, &size);
67 if (!buffer)
68 die("unable to read tree (%s)", oid_to_hex(hash));
69 if (type != OBJ_TREE)
@@ -199,7 +199,7 @@ static int splice_tree(struct repository *r,
199 if (*subpath)
200 subpath++;
201
202 - buf = repo_read_object_file(r, oid1, &type, &sz);
202 + buf = odb_read_object(r->objects, oid1, &type, &sz);
203 if (!buf)
204 die("cannot read tree %s", oid_to_hex(oid1));
205 init_tree_desc(&desc, oid1, buf, sz);
merge-blobs.c
+4 -4
@@ -12,8 +12,8 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
12 unsigned long size;
13 enum object_type type;
14
15 - buf = repo_read_object_file(the_repository, &obj->object.oid, &type,
16 - &size);
15 + buf = odb_read_object(the_repository->objects, &obj->object.oid,
16 + &type, &size);
17 if (!buf)
18 return -1;
19 if (type != OBJ_BLOB) {
@@ -79,8 +79,8 @@ void *merge_blobs(struct index_state *istate, const char *path,
79 return NULL;
80 if (!our)
81 our = their;
82 - return repo_read_object_file(the_repository, &our->object.oid,
83 - &type, size);
82 + return odb_read_object(the_repository->objects, &our->object.oid,
83 + &type, size);
84 }
85
86 if (fill_mmfile_blob(&f1, our) < 0)
merge-ort.c
+1 -1
@@ -3629,7 +3629,7 @@ static int read_oid_strbuf(struct merge_options *opt,
3629 void *buf;
3630 enum object_type type;
3631 unsigned long size;
3632 - buf = repo_read_object_file(the_repository, oid, &type, &size);
3632 + buf = odb_read_object(the_repository->objects, oid, &type, &size);
3633 if (!buf) {
3634 path_msg(opt, ERROR_OBJECT_READ_FAILED, 0,
3635 path, NULL, NULL, NULL,
notes-cache.c
+1 -1
@@ -87,7 +87,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
87 value_oid = get_note(&c->tree, key_oid);
88 if (!value_oid)
89 return NULL;
90 - value = repo_read_object_file(the_repository, value_oid, &type, &size);
90 + value = odb_read_object(the_repository->objects, value_oid, &type, &size);
91
92 *outsize = size;
93 return value;
notes-merge.c
+1 -1
@@ -340,7 +340,7 @@ static void write_note_to_worktree(const struct object_id *obj,
340 {
341 enum object_type type;
342 unsigned long size;
343 - void *buf = repo_read_object_file(the_repository, note, &type, &size);
343 + void *buf = odb_read_object(the_repository->objects, note, &type, &size);
344
345 if (!buf)
346 die("cannot read note %s for object %s",
notes.c
+7 -6
@@ -816,15 +816,15 @@ int combine_notes_concatenate(struct object_id *cur_oid,
816
817 /* read in both note blob objects */
818 if (!is_null_oid(new_oid))
819 - new_msg = repo_read_object_file(the_repository, new_oid,
820 - &new_type, &new_len);
819 + new_msg = odb_read_object(the_repository->objects, new_oid,
820 + &new_type, &new_len);
821 if (!new_msg || !new_len || new_type != OBJ_BLOB) {
822 free(new_msg);
823 return 0;
824 }
825 if (!is_null_oid(cur_oid))
826 - cur_msg = repo_read_object_file(the_repository, cur_oid,
827 - &cur_type, &cur_len);
826 + cur_msg = odb_read_object(the_repository->objects, cur_oid,
827 + &cur_type, &cur_len);
828 if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
829 free(cur_msg);
830 free(new_msg);
@@ -880,7 +880,7 @@ static int string_list_add_note_lines(struct string_list *list,
880 return 0;
881
882 /* read_sha1_file NUL-terminates */
883 - data = repo_read_object_file(the_repository, oid, &t, &len);
883 + data = odb_read_object(the_repository->objects, oid, &t, &len);
884 if (t != OBJ_BLOB || !data || !len) {
885 free(data);
886 return t != OBJ_BLOB || !data;
@@ -1290,7 +1290,8 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
1290 if (!oid)
1291 return;
1292
1293 - if (!(msg = repo_read_object_file(the_repository, oid, &type, &msglen)) || type != OBJ_BLOB) {
1293 + if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
1294 + type != OBJ_BLOB) {
1295 free(msg);
1296 return;
1297 }
object.c
+1 -1
@@ -335,7 +335,7 @@ struct object *parse_object_with_flags(struct repository *r,
335 return &lookup_tree(r, oid)->object;
336 }
337
338 - buffer = repo_read_object_file(r, oid, &type, &size);
338 + buffer = odb_read_object(r->objects, oid, &type, &size);
339 if (buffer) {
340 if (!skip_hash &&
341 check_object_signature(r, repl, buffer, size, type) < 0) {
odb.c
+7 -12
@@ -30,7 +30,7 @@ KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
30
31 /*
32 * This is meant to hold a *small* number of objects that you would
33 - * want repo_read_object_file() to be able to return, but yet you do not want
33 + * want odb_read_object() to be able to return, but yet you do not want
34 * to write them into the object store (e.g. a browse-only
35 * application).
36 */
@@ -887,15 +887,10 @@ int pretend_object_file(struct repository *repo,
887 return 0;
888 }
889
890 -/*
891 - * This function dies on corrupt objects; the callers who want to
892 - * deal with them should arrange to call odb_read_object_info_extended() and give
893 - * error messages themselves.
894 - */
895 -void *repo_read_object_file(struct repository *r,
896 - const struct object_id *oid,
897 - enum object_type *type,
898 - unsigned long *size)
890 +void *odb_read_object(struct object_database *odb,
891 + const struct object_id *oid,
892 + enum object_type *type,
893 + unsigned long *size)
894 {
895 struct object_info oi = OBJECT_INFO_INIT;
896 unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT | OBJECT_INFO_LOOKUP_REPLACE;
@@ -904,7 +899,7 @@ void *repo_read_object_file(struct repository *r,
899 oi.typep = type;
900 oi.sizep = size;
901 oi.contentp = &data;
907 - if (odb_read_object_info_extended(r->objects, oid, &oi, flags))
902 + if (odb_read_object_info_extended(odb, oid, &oi, flags))
903 return NULL;
904
905 return data;
@@ -926,7 +921,7 @@ void *read_object_with_reference(struct repository *r,
921 int ref_length = -1;
922 const char *ref_type = NULL;
923
929 - buffer = repo_read_object_file(r, &actual_oid, &type, &isize);
924 + buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
925 if (!buffer)
926 return NULL;
927 if (type == required_type) {
odb.h
+23 -6
@@ -140,7 +140,7 @@ struct object_database {
140
141 /*
142 * This is meant to hold a *small* number of objects that you would
143 - * want repo_read_object_file() to be able to return, but yet you do not want
143 + * want odb_read_object() to be able to return, but yet you do not want
144 * to write them into the object store (e.g. a browse-only
145 * application).
146 */
@@ -260,10 +260,19 @@ void odb_add_to_alternates_file(struct object_database *odb,
260 void odb_add_to_alternates_memory(struct object_database *odb,
261 const char *dir);
262
263 -void *repo_read_object_file(struct repository *r,
264 - const struct object_id *oid,
265 - enum object_type *type,
266 - unsigned long *size);
263 +/*
264 + * Read an object from the database. Returns the object data and assigns object
265 + * type and size to the `type` and `size` pointers, if these pointers are
266 + * non-NULL. Returns a `NULL` pointer in case the object does not exist.
267 + *
268 + * This function dies on corrupt objects; the callers who want to deal with
269 + * them should arrange to call odb_read_object_info_extended() and give error
270 + * messages themselves.
271 + */
272 +void *odb_read_object(struct object_database *odb,
273 + const struct object_id *oid,
274 + enum object_type *type,
275 + unsigned long *size);
276
277 /*
278 * Add an object file to the in-memory object store, without writing it
@@ -371,7 +380,7 @@ void odb_assert_oid_type(struct object_database *odb,
380
381 /*
382 * Enabling the object read lock allows multiple threads to safely call the
374 - * following functions in parallel: repo_read_object_file(),
383 + * following functions in parallel: odb_read_object(),
384 * read_object_with_reference(), odb_read_object_info() and odb().
385 *
386 * 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,
455 return odb_read_object_info(r->objects, oid, sizep);
456 }
457
458 +static inline void *repo_read_object_file(struct repository *r,
459 + const struct object_id *oid,
460 + enum object_type *type,
461 + unsigned long *size)
462 +{
463 + return odb_read_object(r->objects, oid, type, size);
464 +}
465 +
466 #endif /* ODB_H */
read-cache.c
+3 -3
@@ -254,7 +254,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
254 if (strbuf_readlink(&sb, ce->name, expected_size))
255 return -1;
256
257 - buffer = repo_read_object_file(the_repository, &ce->oid, &type, &size);
257 + buffer = odb_read_object(the_repository->objects, &ce->oid, &type, &size);
258 if (buffer) {
259 if (size == sb.len)
260 match = memcmp(buffer, sb.buf, size);
@@ -3485,8 +3485,8 @@ void *read_blob_data_from_index(struct index_state *istate,
3485 }
3486 if (pos < 0)
3487 return NULL;
3488 - data = repo_read_object_file(the_repository, &istate->cache[pos]->oid,
3489 - &type, &sz);
3488 + data = odb_read_object(the_repository->objects, &istate->cache[pos]->oid,
3489 + &type, &sz);
3490 if (!data || type != OBJ_BLOB) {
3491 free(data);
3492 return NULL;
reflog.c
+2 -2
@@ -140,8 +140,8 @@ static int tree_is_complete(const struct object_id *oid)
140 if (!tree->buffer) {
141 enum object_type type;
142 unsigned long size;
143 - void *data = repo_read_object_file(the_repository, oid, &type,
144 - &size);
143 + void *data = odb_read_object(the_repository->objects, oid,
144 + &type, &size);
145 if (!data) {
146 tree->object.flags |= INCOMPLETE;
147 return 0;
rerere.c
+2 -3
@@ -1000,9 +1000,8 @@ static int handle_cache(struct index_state *istate,
1000 break;
1001 i = ce_stage(ce) - 1;
1002 if (!mmfile[i].ptr) {
1003 - mmfile[i].ptr = repo_read_object_file(the_repository,
1004 - &ce->oid, &type,
1005 - &size);
1003 + mmfile[i].ptr = odb_read_object(the_repository->objects,
1004 + &ce->oid, &type, &size);
1005 if (!mmfile[i].ptr)
1006 die(_("unable to read %s"),
1007 oid_to_hex(&ce->oid));
submodule-config.c
+2 -2
@@ -743,8 +743,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
743 if (submodule)
744 goto out;
745
746 - config = repo_read_object_file(the_repository, &oid, &type,
747 - &config_size);
746 + config = odb_read_object(the_repository->objects, &oid,
747 + &type, &config_size);
748 if (!config || type != OBJ_BLOB)
749 goto out;
750
tag.c
+3 -3
@@ -60,7 +60,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
60 repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV),
61 type_name(type));
62
63 - buf = repo_read_object_file(the_repository, oid, &type, &size);
63 + buf = odb_read_object(the_repository->objects, oid, &type, &size);
64 if (!buf)
65 return error("%s: unable to read file.",
66 name_to_report ?
@@ -222,8 +222,8 @@ int parse_tag(struct tag *item)
222
223 if (item->object.parsed)
224 return 0;
225 - data = repo_read_object_file(the_repository, &item->object.oid, &type,
226 - &size);
225 + data = odb_read_object(the_repository->objects, &item->object.oid,
226 + &type, &size);
227 if (!data)
228 return error("Could not read %s",
229 oid_to_hex(&item->object.oid));
tree-walk.c
+3 -3
@@ -795,9 +795,9 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
795 */
796 retval = DANGLING_SYMLINK;
797
798 - contents = repo_read_object_file(r,
799 - &current_tree_oid, &type,
800 - &link_len);
798 + contents = odb_read_object(r->objects,
799 + &current_tree_oid, &type,
800 + &link_len);
801
802 if (!contents)
803 goto done;
tree.c
+2 -2
@@ -193,8 +193,8 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
193
194 if (item->object.parsed)
195 return 0;
196 - buffer = repo_read_object_file(the_repository, &item->object.oid,
197 - &type, &size);
196 + buffer = odb_read_object(the_repository->objects, &item->object.oid,
197 + &type, &size);
198 if (!buffer)
199 return quiet_on_missing ? -1 :
200 error("Could not read %s",
xdiff-interface.c
+1 -1
@@ -187,7 +187,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
187 return;
188 }
189
190 - ptr->ptr = repo_read_object_file(the_repository, oid, &type, &size);
190 + ptr->ptr = odb_read_object(the_repository->objects, oid, &type, &size);
191 if (!ptr->ptr || type != OBJ_BLOB)
192 die("unable to read blob object %s", oid_to_hex(oid));
193 ptr->size = size;