]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb: rename `repo_read_object_file()`
authorPatrick Steinhardt <ps@pks.im>
Thu, 5 Jun 2025 06:47:04 +0000 (08:47 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Jun 2025 15:52:01 +0000 (08:52 -0700)
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>
47 files changed:
apply.c
archive.c
attr.c
bisect.c
blame.c
builtin/cat-file.c
builtin/difftool.c
builtin/fast-export.c
builtin/fast-import.c
builtin/grep.c
builtin/index-pack.c
builtin/log.c
builtin/merge-tree.c
builtin/mktag.c
builtin/notes.c
builtin/pack-objects.c
builtin/tag.c
builtin/unpack-file.c
builtin/unpack-objects.c
bundle.c
combine-diff.c
commit.c
config.c
dir.c
entry.c
fmt-merge-msg.c
fsck.c
grep.c
http-push.c
mailmap.c
match-trees.c
merge-blobs.c
merge-ort.c
notes-cache.c
notes-merge.c
notes.c
object.c
odb.c
odb.h
read-cache.c
reflog.c
rerere.c
submodule-config.c
tag.c
tree-walk.c
tree.c
xdiff-interface.c

diff --git a/apply.c b/apply.c
index e778b4e911de98298804d7c076887a06ec015f79..a34ced04625e1827e7b44f457349cca04785eecb 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -3210,8 +3210,8 @@ static int apply_binary(struct apply_state *state,
                unsigned long size;
                char *result;
 
-               result = repo_read_object_file(the_repository, &oid, &type,
-                                              &size);
+               result = odb_read_object(the_repository->objects, &oid,
+                                        &type, &size);
                if (!result)
                        return error(_("the necessary postimage %s for "
                                       "'%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;
                char *result;
 
-               result = repo_read_object_file(the_repository, oid, &type,
-                                              &sz);
+               result = odb_read_object(the_repository->objects, oid,
+                                        &type, &sz);
                if (!result)
                        return -1;
                /* 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);
 
-       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)
                die("unable to read blob object %s", oid_to_hex(result_id));
        strbuf_attach(&image->buf, data, size, size + 1);
index f2511d530d585b66d3b8fe4ecec074306d2fd88c..f5a9d45c8d3e244c28fd72d5774fb987e396615f 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -98,7 +98,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
                               (args->tree ? &args->tree->object.oid : NULL), oid);
 
        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)) {
                struct strbuf buf = STRBUF_INIT;
                size_t size = 0;
diff --git a/attr.c b/attr.c
index e5680db7f650808cf0b8ee0c4f8ddecb6e2b5200..d1daeb0b4d90a6a289e3582f455212cbf20123ac 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -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))
                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) {
                free(buf);
                return NULL;
index a7939216d00eaf9853715aff07740a1108bb0c3b..f24474542ec3b16a4bc3379f7eb4eb1e3e83057e 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -155,9 +155,9 @@ static void show_list(const char *debug, int counted, int nr,
                unsigned commit_flags = commit->object.flags;
                enum object_type type;
                unsigned long size;
-               char *buf = repo_read_object_file(the_repository,
-                                                 &commit->object.oid, &type,
-                                                 &size);
+               char *buf = odb_read_object(the_repository->objects,
+                                           &commit->object.oid, &type,
+                                           &size);
                const char *subject_start;
                int subject_len;
 
diff --git a/blame.c b/blame.c
index 97db3355af45941a8dfaa2add7d00b0ccda5aad6..858d2d74df98fb0d6f983ffdd62275e16e54335a 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -1041,9 +1041,9 @@ static void fill_origin_blob(struct diff_options *opt,
                                    &o->blob_oid, 1, &file->ptr, &file_size))
                        ;
                else
-                       file->ptr = repo_read_object_file(the_repository,
-                                                         &o->blob_oid, &type,
-                                                         &file_size);
+                       file->ptr = odb_read_object(the_repository->objects,
+                                                   &o->blob_oid, &type,
+                                                   &file_size);
                file->size = file_size;
 
                if (!file->ptr)
@@ -2869,10 +2869,9 @@ void setup_scoreboard(struct blame_scoreboard *sb,
                                    &sb->final_buf_size))
                        ;
                else
-                       sb->final_buf = repo_read_object_file(the_repository,
-                                                             &o->blob_oid,
-                                                             &type,
-                                                             &sb->final_buf_size);
+                       sb->final_buf = odb_read_object(the_repository->objects,
+                                                       &o->blob_oid, &type,
+                                                       &sb->final_buf_size);
 
                if (!sb->final_buf)
                        die(_("cannot read blob %s for path %s"),
index f7595fdb04e90183a8d536570a7d2e1e9aff3984..90a3e159d119cd5dccca8d3dfee9d401f0476814 100644 (file)
@@ -74,7 +74,7 @@ static int filter_object(const char *path, unsigned mode,
 {
        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)
                return error(_("cannot read object %s '%s'"),
                             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);
                        goto cleanup;
                }
-               buf = repo_read_object_file(the_repository, &oid, &type,
-                                           &size);
+               buf = odb_read_object(the_repository->objects, &oid,
+                                     &type, &size);
                if (!buf)
                        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;
                        if (odb_read_object_info(the_repository->objects,
                                                 &oid, NULL) == OBJ_TAG) {
-                               char *buffer = repo_read_object_file(the_repository,
-                                                                    &oid,
-                                                                    &type,
-                                                                    &size);
+                               char *buffer = odb_read_object(the_repository->objects,
+                                                              &oid, &type, &size);
                                const char *target;
 
                                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,
                                                     data->rest, 0100644, oid,
                                                     1, &contents, &size))
-                                       contents = repo_read_object_file(the_repository,
-                                                                        oid,
-                                                                        &type,
-                                                                        &size);
+                                       contents = odb_read_object(the_repository->objects,
+                                                                  oid, &type, &size);
                                if (!contents)
                                        die("could not convert '%s' %s",
                                            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;
                void *contents;
 
-               contents = repo_read_object_file(the_repository, oid, &type,
-                                                &size);
+               contents = odb_read_object(the_repository->objects, oid,
+                                          &type, &size);
                if (!contents)
                        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;
                        char *buf = NULL;
 
-                       buf = repo_read_object_file(the_repository, &data->oid, &data->type,
-                                                   &data->size);
+                       buf = odb_read_object(the_repository->objects, &data->oid,
+                                             &data->type, &data->size);
                        if (!buf)
                                die(_("unable to read %s"), oid_to_hex(&data->oid));
                        buf = replace_idents_using_mailmap(buf, &s);
index fac613e3bc385ac0d51fa85f819dc190343c4013..e4bc1f831696a8eace3931567d815fb4fd794b88 100644 (file)
@@ -320,7 +320,7 @@ static char *get_symlink(struct repository *repo,
        } else {
                enum object_type type;
                unsigned long size;
-               data = repo_read_object_file(repo, oid, &type, &size);
+               data = odb_read_object(repo->objects, oid, &type, &size);
                if (!data)
                        die(_("could not read object %s for symlink %s"),
                                oid_to_hex(oid), path);
index 6c93cf0a8aa1f56786baa0ddeb0644980475f9a5..33f304dd0ad2431fe85fdc96dd39af248d70abac 100644 (file)
@@ -323,7 +323,7 @@ static void export_blob(const struct object_id *oid)
                object = (struct object *)lookup_blob(the_repository, oid);
                eaten = 0;
        } else {
-               buf = repo_read_object_file(the_repository, oid, &type, &size);
+               buf = odb_read_object(the_repository->objects, oid, &type, &size);
                if (!buf)
                        die("could not read blob %s", oid_to_hex(oid));
                if (check_object_signature(the_repository, oid, buf, size,
@@ -869,8 +869,8 @@ static void handle_tag(const char *name, struct tag *tag)
                return;
        }
 
-       buf = repo_read_object_file(the_repository, &tag->object.oid, &type,
-                                   &size);
+       buf = odb_read_object(the_repository->objects, &tag->object.oid,
+                             &type, &size);
        if (!buf)
                die("could not read tag %s", oid_to_hex(&tag->object.oid));
        message = memmem(buf, size, "\n\n", 2);
index 2718376f2c96def4fdc87d357271e36a2232205f..1973c504e257547565a3dedbe8c4fb1ac7322e1e 100644 (file)
@@ -1265,7 +1265,7 @@ static void load_tree(struct tree_entry *root)
                        die("Can't load tree %s", oid_to_hex(oid));
        } else {
                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)
                        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;
 
        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 {
                type = oe->type;
                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);
        } else {
                enum object_type unused;
-               buf = repo_read_object_file(the_repository, oid, &unused,
-                                           &size);
+               buf = odb_read_object(the_repository->objects, oid,
+                                     &unused, &size);
        }
        if (!buf)
                die("Can't load object %s", oid_to_hex(oid));
index 1435d462cd1883b1af5bfaca0b5fbd0554b5ce82..5de61dfffe893ba0dd190d6f8304ac0d22bf84fc 100644 (file)
@@ -573,8 +573,8 @@ static int grep_cache(struct grep_opt *opt,
                        void *data;
                        unsigned long size;
 
-                       data = repo_read_object_file(the_repository, &ce->oid,
-                                                    &type, &size);
+                       data = odb_read_object(the_repository->objects, &ce->oid,
+                                              &type, &size);
                        if (!data)
                                die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
                        init_tree_desc(&tree, &ce->oid, data, size);
@@ -666,8 +666,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
                        void *data;
                        unsigned long size;
 
-                       data = repo_read_object_file(the_repository,
-                                                    &entry.oid, &type, &size);
+                       data = odb_read_object(the_repository->objects,
+                                              &entry.oid, &type, &size);
                        if (!data)
                                die(_("unable to read tree (%s)"),
                                    oid_to_hex(&entry.oid));
index d0b16908122bf05968bf98a08555acdc874969fa..180d261f6ce288c67c75d43649d7a81f4d0073a3 100644 (file)
@@ -914,8 +914,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
                        die(_("cannot read existing object info %s"), oid_to_hex(oid));
                if (has_type != type || has_size != size)
                        die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
-               has_data = repo_read_object_file(the_repository, oid,
-                                                &has_type, &has_size);
+               has_data = odb_read_object(the_repository->objects, oid,
+                                          &has_type, &has_size);
                read_unlock();
                if (!data)
                        data = new_data = get_data_from_pack(obj_entry);
@@ -1521,8 +1521,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
 
                if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
                        continue;
-               data = repo_read_object_file(the_repository, &d->oid, &type,
-                                            &size);
+               data = odb_read_object(the_repository->objects, &d->oid,
+                                      &type, &size);
                if (!data)
                        continue;
 
index fe9cc5ebecb231e24e9068c1795647f85e775993..f2040b1815970b71213b6c35af6898348ebfb2be 100644 (file)
@@ -714,7 +714,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
 {
        unsigned long size;
        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;
 
        if (!buf)
index b1a17787bcf913c32b138212c9efcd364da819c9..cf8b06cadc7d5095979c6926ba493aef599326fb 100644 (file)
@@ -75,9 +75,9 @@ static void *result(struct merge_list *entry, unsigned long *size)
        const char *path = entry->path;
 
        if (!entry->stage)
-               return repo_read_object_file(the_repository,
-                                            &entry->blob->object.oid, &type,
-                                            size);
+               return odb_read_object(the_repository->objects,
+                                      &entry->blob->object.oid, &type,
+                                      size);
        base = NULL;
        if (entry->stage == 1) {
                base = entry->blob;
@@ -100,9 +100,9 @@ static void *origin(struct merge_list *entry, unsigned long *size)
        enum object_type type;
        while (entry) {
                if (entry->stage == 2)
-                       return repo_read_object_file(the_repository,
-                                                    &entry->blob->object.oid,
-                                                    &type, size);
+                       return odb_read_object(the_repository->objects,
+                                              &entry->blob->object.oid,
+                                              &type, size);
                entry = entry->link;
        }
        return NULL;
index 1809b38f937f3b6d36d3b774a157a546df8901ea..1b391119de85e5cc4457628a0f6c541666fc3a8b 100644 (file)
@@ -54,8 +54,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
        void *buffer;
        const struct object_id *repl;
 
-       buffer = repo_read_object_file(the_repository, tagged_oid, &type,
-                                      &size);
+       buffer = odb_read_object(the_repository->objects, tagged_oid,
+                                &type, &size);
        if (!buffer)
                die(_("could not read tagged object '%s'"),
                    oid_to_hex(tagged_oid));
index 783d4932ca6efe8172c701e390598e85fcc291cd..a9529b1696ae14174580795fbd71e5285b028eb5 100644 (file)
@@ -152,7 +152,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
 {
        unsigned long size;
        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 (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);
        if (repo_get_oid(the_repository, arg, &object))
                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);
        if (type != OBJ_BLOB) {
                strbuf_release(&msg->buf);
@@ -722,7 +722,7 @@ static int append_edit(int argc, const char **argv, const char *prefix,
                unsigned long size;
                enum object_type type;
                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)
                        die(_("unable to read %s"), oid_to_hex(note));
index da35d684081aea0edde465eefc6e64b11ae98fd6..580a5c1996b4063719c28205bbe9672abdb8f8c7 100644 (file)
@@ -337,13 +337,13 @@ static void *get_delta(struct object_entry *entry)
        void *buf, *base_buf, *delta_buf;
        enum object_type type;
 
-       buf = repo_read_object_file(the_repository, &entry->idx.oid, &type,
-                                   &size);
+       buf = odb_read_object(the_repository->objects, &entry->idx.oid,
+                             &type, &size);
        if (!buf)
                die(_("unable to read %s"), oid_to_hex(&entry->idx.oid));
-       base_buf = repo_read_object_file(the_repository,
-                                        &DELTA(entry)->idx.oid, &type,
-                                        &base_size);
+       base_buf = odb_read_object(the_repository->objects,
+                                  &DELTA(entry)->idx.oid, &type,
+                                  &base_size);
        if (!base_buf)
                die("unable to read %s",
                    oid_to_hex(&DELTA(entry)->idx.oid));
@@ -506,9 +506,9 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
                                       &size, NULL)) != NULL)
                        buf = NULL;
                else {
-                       buf = repo_read_object_file(the_repository,
-                                                   &entry->idx.oid, &type,
-                                                   &size);
+                       buf = odb_read_object(the_repository->objects,
+                                             &entry->idx.oid, &type,
+                                             &size);
                        if (!buf)
                                die(_("unable to read %s"),
                                    oid_to_hex(&entry->idx.oid));
@@ -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
         * 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)
                return NULL;
        if (type != OBJ_TREE) {
@@ -2762,9 +2762,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
        /* Load data if not already done */
        if (!trg->data) {
                packing_data_lock(&to_pack);
-               trg->data = repo_read_object_file(the_repository,
-                                                 &trg_entry->idx.oid, &type,
-                                                 &sz);
+               trg->data = odb_read_object(the_repository->objects,
+                                           &trg_entry->idx.oid, &type,
+                                           &sz);
                packing_data_unlock(&to_pack);
                if (!trg->data)
                        die(_("object %s cannot be read"),
@@ -2777,9 +2777,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
        }
        if (!src->data) {
                packing_data_lock(&to_pack);
-               src->data = repo_read_object_file(the_repository,
-                                                 &src_entry->idx.oid, &type,
-                                                 &sz);
+               src->data = odb_read_object(the_repository->objects,
+                                           &src_entry->idx.oid, &type,
+                                           &sz);
                packing_data_unlock(&to_pack);
                if (!src->data) {
                        if (src_entry->preferred_base) {
index e0b27396c6b90524ec174b872ea1b91c8aa1b973..46cbf892e34224ad2e8557ee2c20d55bb1e14a5a 100644 (file)
@@ -244,7 +244,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
        struct strbuf payload = 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)
                return;
        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");
                break;
        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);
                        strbuf_insert(sb, sb->len, subject_start, subject_len);
                } else {
index b92fd4710a99db3b077ef9ed88e1e8814ca73191..4360872ae070267bdf00dff06c8f86718f8a6c22 100644 (file)
@@ -14,7 +14,7 @@ static char *create_temp_file(struct object_id *oid)
        unsigned long size;
        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)
                die("unable to read blob object %s", oid_to_hex(oid));
 
index 405e78bc592387959e8fe9e890f5abf9d12189be..4bc6575a5743e15f4651c8455b72ae175198db44 100644 (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))
                return;
 
-       base = repo_read_object_file(the_repository, &base_oid, &type,
-                                    &base_size);
+       base = odb_read_object(the_repository->objects, &base_oid,
+                              &type, &base_size);
        if (!base) {
                error("failed to read delta-pack base object %s",
                      oid_to_hex(&base_oid));
index e09e3c2f58c3e969a34572662777311eaac2c5fb..717f056a45435f594605c3d3a110cd28055d10aa 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -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)
                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)
                goto out;
        line = memmem(buf, size, "\ntagger ", 8);
index cf23a753407561e9100cda7c3fead822b39214de..4ea2dc93c4f8075042641eeb8b57c131a4313571 100644 (file)
@@ -325,7 +325,7 @@ static char *grab_blob(struct repository *r,
                *size = fill_textconv(r, textconv, df, &blob);
                free_filespec(df);
        } else {
-               blob = repo_read_object_file(r, oid, &type, size);
+               blob = odb_read_object(r->objects, oid, &type, size);
                if (!blob)
                        die(_("unable to read %s"), oid_to_hex(oid));
                if (type != OBJ_BLOB)
index d4aa9c7a5f81a8c398c2a1970efe4084c63f3120..28ee6b73ae6be01a1c066fabb8e334e2952bfe39 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -374,7 +374,7 @@ const void *repo_get_commit_buffer(struct repository *r,
        if (!ret) {
                enum object_type type;
                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)
                        die("cannot read commit object %s",
                            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);
        if (!desc || !desc->obj)
                return;
-       buf = repo_read_object_file(the_repository, &desc->obj->oid, &type,
-                                   &size);
+       buf = odb_read_object(the_repository->objects, &desc->obj->oid,
+                             &type, &size);
        if (!buf || type != OBJ_TAG)
                goto free_return;
        if (!parse_signature(buf, size, &payload, &signature))
index 883dd0668271c698a2c90e002d8662eb16273a9d..142c37215a8c915336d70dd777da48ce8c34937b 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1942,7 +1942,7 @@ int git_config_from_blob_oid(config_fn_t fn,
        unsigned long size;
        int ret;
 
-       buf = repo_read_object_file(repo, oid, &type, &size);
+       buf = odb_read_object(repo->objects, oid, &type, &size);
        if (!buf)
                return error(_("unable to load config blob object '%s'"), name);
        if (type != OBJ_BLOB) {
diff --git a/dir.c b/dir.c
index a374972b6243b62da4db8e7d974d55549cdd98a7..cb7bd873b171a1f47cf78570810aa412e8d30154 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -302,7 +302,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
        *size_out = 0;
        *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) {
                free(data);
                return -1;
diff --git a/entry.c b/entry.c
index 75d55038d7ceb8e35fed443f2809943ce06faa99..cae02eb50398d7cfcdac8b4c4382e067e9de02d9 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -93,8 +93,8 @@ void *read_blob_entry(const struct cache_entry *ce, size_t *size)
 {
        enum object_type type;
        unsigned long ul;
-       void *blob_data = repo_read_object_file(the_repository, &ce->oid,
-                                               &type, &ul);
+       void *blob_data = odb_read_object(the_repository->objects, &ce->oid,
+                                         &type, &ul);
 
        *size = ul;
        if (blob_data) {
index 1a8c972adf3ad7698bb921a379fa050c527f0182..40174efa3de2b92285f49cf3c3d25fbeb63548f5 100644 (file)
@@ -526,8 +526,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
                struct object_id *oid = origins.items[i].util;
                enum object_type type;
                unsigned long size;
-               char *buf = repo_read_object_file(the_repository, oid, &type,
-                                                 &size);
+               char *buf = odb_read_object(the_repository->objects, oid,
+                                           &type, &size);
                char *origbuf = buf;
                unsigned long len = size;
                struct signature_check sigc = { NULL };
diff --git a/fsck.c b/fsck.c
index e69baab3af7ede71237d4e768dfeb85c9c773137..23965e1880fedead833a14e2b1db3197be494f85 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -1293,7 +1293,7 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,
                if (oidset_contains(blobs_done, oid))
                        continue;
 
-               buf = repo_read_object_file(the_repository, oid, &type, &size);
+               buf = odb_read_object(the_repository->objects, oid, &type, &size);
                if (!buf) {
                        if (is_promisor_object(the_repository, oid))
                                continue;
diff --git a/grep.c b/grep.c
index dc77e6c46319156815e198ee060e8c8f0b515c60..932647e4a6580b52973c90b8d94494e3bb31bbdc 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -1931,8 +1931,8 @@ static int grep_source_load_oid(struct grep_source *gs)
 {
        enum object_type type;
 
-       gs->buf = repo_read_object_file(gs->repo, gs->identifier, &type,
-                                       &gs->size);
+       gs->buf = odb_read_object(gs->repo->objects, gs->identifier,
+                                 &type, &gs->size);
        if (!gs->buf)
                return error(_("'%s': unable to read %s"),
                             gs->name,
index d1b1bb237116534b62309bd48f76a7dc731df68f..9481825abfb8ad74a0a9619d610a7f9b203a6dd6 100644 (file)
@@ -369,8 +369,8 @@ static void start_put(struct transfer_request *request)
        ssize_t size;
        git_zstream stream;
 
-       unpacked = repo_read_object_file(the_repository, &request->obj->oid,
-                                        &type, &len);
+       unpacked = odb_read_object(the_repository->objects, &request->obj->oid,
+                                  &type, &len);
        hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
 
        /* Set it up */
index b18e74c2110e7818c481dabfc6351ddf1eca8eb9..56c72102d9e39461adc3f2795f10da70b535c03b 100644 (file)
--- a/mailmap.c
+++ b/mailmap.c
@@ -196,7 +196,7 @@ int read_mailmap_blob(struct string_list *map, const char *name)
        if (repo_get_oid(the_repository, name, &oid) < 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)
                return error("unable to read mailmap object at %s", name);
        if (type != OBJ_BLOB) {
index 4704f95c3402e67dc8a641d4b094988bf2d488e4..5a8a5c39b04ab9f0397ec36282d35ffb79b66dca 100644 (file)
@@ -63,7 +63,7 @@ static void *fill_tree_desc_strict(struct repository *r,
        enum object_type type;
        unsigned long size;
 
-       buffer = repo_read_object_file(r, hash, &type, &size);
+       buffer = odb_read_object(r->objects, hash, &type, &size);
        if (!buffer)
                die("unable to read tree (%s)", oid_to_hex(hash));
        if (type != OBJ_TREE)
@@ -199,7 +199,7 @@ static int splice_tree(struct repository *r,
        if (*subpath)
                subpath++;
 
-       buf = repo_read_object_file(r, oid1, &type, &sz);
+       buf = odb_read_object(r->objects, oid1, &type, &sz);
        if (!buf)
                die("cannot read tree %s", oid_to_hex(oid1));
        init_tree_desc(&desc, oid1, buf, sz);
index ba8a3fdfd82b74bd9d4b5753e97ae7d129f3ef40..6fc279941714f63f4d2260ace310a12cc78af051 100644 (file)
@@ -12,8 +12,8 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
        unsigned long size;
        enum object_type type;
 
-       buf = repo_read_object_file(the_repository, &obj->object.oid, &type,
-                                   &size);
+       buf = odb_read_object(the_repository->objects, &obj->object.oid,
+                             &type, &size);
        if (!buf)
                return -1;
        if (type != OBJ_BLOB) {
@@ -79,8 +79,8 @@ void *merge_blobs(struct index_state *istate, const char *path,
                        return NULL;
                if (!our)
                        our = their;
-               return repo_read_object_file(the_repository, &our->object.oid,
-                                            &type, size);
+               return odb_read_object(the_repository->objects, &our->object.oid,
+                                      &type, size);
        }
 
        if (fill_mmfile_blob(&f1, our) < 0)
index f29417040c1cd9824ebdcc48cdc2bedde57d577c..473ff61e36e9f7bad64d24c91880a4829f1ee391 100644 (file)
@@ -3629,7 +3629,7 @@ static int read_oid_strbuf(struct merge_options *opt,
        void *buf;
        enum object_type type;
        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) {
                path_msg(opt, ERROR_OBJECT_READ_FAILED, 0,
                         path, NULL, NULL, NULL,
index 344f67762b8c183feee795dac2626aa9e4a83349..dd56feed6e8cfe339f9869723c56c0f9b396fcdd 100644 (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);
        if (!value_oid)
                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;
        return value;
index de6a52e2e7ff3fe064e1fcbb2392a83c1a2b8956..586939939f24516e5ca5226323118904e46c63e4 100644 (file)
@@ -340,7 +340,7 @@ static void write_note_to_worktree(const struct object_id *obj,
 {
        enum object_type type;
        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)
                die("cannot read note %s for object %s",
diff --git a/notes.c b/notes.c
index fc000e501d2a63e371d0af2ca7c258bf6a1a94a5..73eb5f00cf51742732dd16ce42eb19002239ceaf 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -816,15 +816,15 @@ int combine_notes_concatenate(struct object_id *cur_oid,
 
        /* read in both note blob objects */
        if (!is_null_oid(new_oid))
-               new_msg = repo_read_object_file(the_repository, new_oid,
-                                               &new_type, &new_len);
+               new_msg = odb_read_object(the_repository->objects, new_oid,
+                                         &new_type, &new_len);
        if (!new_msg || !new_len || new_type != OBJ_BLOB) {
                free(new_msg);
                return 0;
        }
        if (!is_null_oid(cur_oid))
-               cur_msg = repo_read_object_file(the_repository, cur_oid,
-                                               &cur_type, &cur_len);
+               cur_msg = odb_read_object(the_repository->objects, cur_oid,
+                                         &cur_type, &cur_len);
        if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
                free(cur_msg);
                free(new_msg);
@@ -880,7 +880,7 @@ static int string_list_add_note_lines(struct string_list *list,
                return 0;
 
        /* 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) {
                free(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)
                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);
                return;
        }
index 868d89eed42da1a856d2c65e700f98f915403afc..c1553ee4330c89533f4e09f842f40264777e1372 100644 (file)
--- a/object.c
+++ b/object.c
@@ -335,7 +335,7 @@ struct object *parse_object_with_flags(struct repository *r,
                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 (!skip_hash &&
                    check_object_signature(r, repl, buffer, size, type) < 0) {
diff --git a/odb.c b/odb.c
index c3fe79171619dc13d29441c397a00123b617bea5..fc39fbe12d89750840d1051fc2f136ab3469c6f3 100644 (file)
--- a/odb.c
+++ b/odb.c
@@ -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
- * 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
  * application).
  */
@@ -887,15 +887,10 @@ int pretend_object_file(struct repository *repo,
        return 0;
 }
 
-/*
- * 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,
-                           enum object_type *type,
-                           unsigned long *size)
+void *odb_read_object(struct object_database *odb,
+                     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;
@@ -904,7 +899,7 @@ void *repo_read_object_file(struct repository *r,
        oi.typep = type;
        oi.sizep = size;
        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 data;
@@ -926,7 +921,7 @@ void *read_object_with_reference(struct repository *r,
                int ref_length = -1;
                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)
                        return NULL;
                if (type == required_type) {
diff --git a/odb.h b/odb.h
index b37a9c5d20ffa3835c1fd2bfe9f74ea9314611aa..a4a5154fd0ff1d6654dbb9745dc43273697c6410 100644 (file)
--- a/odb.h
+++ b/odb.h
@@ -140,7 +140,7 @@ struct object_database {
 
        /*
         * 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
         * application).
         */
@@ -260,10 +260,19 @@ void odb_add_to_alternates_file(struct object_database *odb,
 void odb_add_to_alternates_memory(struct object_database *odb,
                                  const char *dir);
 
-void *repo_read_object_file(struct repository *r,
-                           const struct object_id *oid,
-                           enum object_type *type,
-                           unsigned long *size);
+/*
+ * 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,
+                     enum object_type *type,
+                     unsigned long *size);
 
 /*
  * 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,
 
 /*
  * 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().
  *
  * 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);
 }
 
+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 */
index 7d5bccf95dcfc39a6abbc749815524e828faa97a..531d87e790529fef78e3ed2bf633d3c0421d659a 100644 (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))
                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 (size == sb.len)
                        match = memcmp(buffer, sb.buf, size);
@@ -3485,8 +3485,8 @@ void *read_blob_data_from_index(struct index_state *istate,
        }
        if (pos < 0)
                return NULL;
-       data = repo_read_object_file(the_repository, &istate->cache[pos]->oid,
-                                    &type, &sz);
+       data = odb_read_object(the_repository->objects, &istate->cache[pos]->oid,
+                              &type, &sz);
        if (!data || type != OBJ_BLOB) {
                free(data);
                return NULL;
index 4f8a3b717cdb7404b7f128445e40db95bf396651..747b82eada83f4081591059f5b727aa678b9ee16 100644 (file)
--- a/reflog.c
+++ b/reflog.c
@@ -140,8 +140,8 @@ static int tree_is_complete(const struct object_id *oid)
        if (!tree->buffer) {
                enum object_type type;
                unsigned long size;
-               void *data = repo_read_object_file(the_repository, oid, &type,
-                                                  &size);
+               void *data = odb_read_object(the_repository->objects, oid,
+                                            &type, &size);
                if (!data) {
                        tree->object.flags |= INCOMPLETE;
                        return 0;
index 951e4bf8b41c95f3febb86c5a651097a4eeae6f3..8bb97c98229bdd5694f0a43523f1b5786dd5f676 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -1000,9 +1000,8 @@ static int handle_cache(struct index_state *istate,
                        break;
                i = ce_stage(ce) - 1;
                if (!mmfile[i].ptr) {
-                       mmfile[i].ptr = repo_read_object_file(the_repository,
-                                                             &ce->oid, &type,
-                                                             &size);
+                       mmfile[i].ptr = odb_read_object(the_repository->objects,
+                                                       &ce->oid, &type, &size);
                        if (!mmfile[i].ptr)
                                die(_("unable to read %s"),
                                    oid_to_hex(&ce->oid));
index a9f721078889ebe2a950ab6605028fa3ada9f0c6..ea3a087a8bb91fba08e47cc59554ee7aa0791625 100644 (file)
@@ -743,8 +743,8 @@ static const struct submodule *config_from(struct submodule_cache *cache,
        if (submodule)
                goto out;
 
-       config = repo_read_object_file(the_repository, &oid, &type,
-                                      &config_size);
+       config = odb_read_object(the_repository->objects, &oid,
+                                &type, &config_size);
        if (!config || type != OBJ_BLOB)
                goto out;
 
diff --git a/tag.c b/tag.c
index 144048fd5e0c252c530ee0d4cbd3f829cf5efdba..1d52686ee105f2ac168e9728716bc3f70c30cd57 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -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),
                                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)
                return error("%s: unable to read file.",
                                name_to_report ?
@@ -222,8 +222,8 @@ int parse_tag(struct tag *item)
 
        if (item->object.parsed)
                return 0;
-       data = repo_read_object_file(the_repository, &item->object.oid, &type,
-                                    &size);
+       data = odb_read_object(the_repository->objects, &item->object.oid,
+                              &type, &size);
        if (!data)
                return error("Could not read %s",
                             oid_to_hex(&item->object.oid));
index 34b0fff4873dbd57a9a073fe780bb056178e463c..766af99f4668e4efa6c58b54f60d8d673c5da006 100644 (file)
@@ -795,9 +795,9 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
                         */
                        retval = DANGLING_SYMLINK;
 
-                       contents = repo_read_object_file(r,
-                                                   &current_tree_oid, &type,
-                                                   &link_len);
+                       contents = odb_read_object(r->objects,
+                                                  &current_tree_oid, &type,
+                                                  &link_len);
 
                        if (!contents)
                                goto done;
diff --git a/tree.c b/tree.c
index 341b7c2ff3fb9f3ad2d351162d2ac758e18f8112..1ef743d90f4badf9e62fd6981bb920f35492e71f 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -193,8 +193,8 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
 
        if (item->object.parsed)
                return 0;
-       buffer = repo_read_object_file(the_repository, &item->object.oid,
-                                      &type, &size);
+       buffer = odb_read_object(the_repository->objects, &item->object.oid,
+                                &type, &size);
        if (!buffer)
                return quiet_on_missing ? -1 :
                        error("Could not read %s",
index 01e6e378ea6071075c48bbf85b08ac6a97ad119d..0e5d38c96003d3272706869502160c663a205d84 100644 (file)
@@ -187,7 +187,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
                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)
                die("unable to read blob object %s", oid_to_hex(oid));
        ptr->size = size;