From: Patrick Steinhardt Date: Mon, 1 Jun 2026 08:20:29 +0000 (+0200) Subject: odb/source-loose: wire up `read_object_info()` callback X-Git-Tag: v2.55.0-rc0~5^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=584338ed92735f3be768c16b53266d5bad439a7a;p=thirdparty%2Fgit.git odb/source-loose: wire up `read_object_info()` callback Move `odb_source_loose_read_object_info()` from "object-file.c" into "odb/source-loose.c" and wire it up as the `read_object_info()` callback of the loose source. Callers that previously invoked it directly now go through the generic `odb_source_read_object_info()` interface instead. The function `read_object_info_from_path()` cannot be moved along with it because it is still called by `for_each_object_wrapper_cb()`. It is therefore kept in place, but adjusted to take a loose source to clarify that it's always operating on this structure. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- diff --git a/object-file.c b/object-file.c index 0f4f1e7bdc..fa174512a4 100644 --- a/object-file.c +++ b/object-file.c @@ -396,13 +396,12 @@ static int parse_loose_header(const char *hdr, struct object_info *oi) return 0; } -static int read_object_info_from_path(struct odb_source *source, - const char *path, - const struct object_id *oid, - struct object_info *oi, - enum object_info_flags flags) +int read_object_info_from_path(struct odb_source_loose *loose, + const char *path, + const struct object_id *oid, + struct object_info *oi, + enum object_info_flags flags) { - struct odb_source_files *files = odb_source_files_downcast(source); int ret; int fd; unsigned long mapsize; @@ -425,7 +424,7 @@ static int read_object_info_from_path(struct odb_source *source, struct stat st; if ((!oi || (!oi->disk_sizep && !oi->mtimep)) && (flags & OBJECT_INFO_QUICK)) { - ret = quick_has_loose(files->loose, oid) ? 0 : -1; + ret = quick_has_loose(loose, oid) ? 0 : -1; goto out; } @@ -532,7 +531,7 @@ out: if (oi->typep == &type_scratch) oi->typep = NULL; if (oi->delta_base_oid) - oidclr(oi->delta_base_oid, source->odb->repo->hash_algo); + oidclr(oi->delta_base_oid, loose->base.odb->repo->hash_algo); if (!ret) oi->whence = OI_LOOSE; } @@ -540,26 +539,6 @@ out: return ret; } -int odb_source_loose_read_object_info(struct odb_source *source, - const struct object_id *oid, - struct object_info *oi, - enum object_info_flags flags) -{ - static struct strbuf buf = STRBUF_INIT; - - /* - * The second read shouldn't cause new loose objects to show up, unless - * there was a race condition with a secondary process. We don't care - * about this case though, so we simply skip reading loose objects a - * second time. - */ - if (flags & OBJECT_INFO_SECOND_READ) - return -1; - - odb_loose_path(source, &buf, oid); - return read_object_info_from_path(source, buf.buf, oid, oi, flags); -} - static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c, const void *buf, unsigned long len, struct object_id *oid, @@ -1833,7 +1812,7 @@ int for_each_loose_file_in_source(struct odb_source *source, } struct for_each_object_wrapper_data { - struct odb_source *source; + struct odb_source_loose *loose; const struct object_info *request; odb_for_each_object_cb cb; void *cb_data; @@ -1848,7 +1827,7 @@ static int for_each_object_wrapper_cb(const struct object_id *oid, if (data->request) { struct object_info oi = *data->request; - if (read_object_info_from_path(data->source, path, oid, &oi, 0) < 0) + if (read_object_info_from_path(data->loose, path, oid, &oi, 0) < 0) return -1; return data->cb(oid, &oi, data->cb_data); @@ -1865,8 +1844,8 @@ static int for_each_prefixed_object_wrapper_cb(const struct object_id *oid, if (data->request) { struct object_info oi = *data->request; - if (odb_source_loose_read_object_info(data->source, - oid, &oi, 0) < 0) + if (odb_source_read_object_info(&data->loose->base, + oid, &oi, 0) < 0) return -1; return data->cb(oid, &oi, data->cb_data); @@ -1881,8 +1860,9 @@ int odb_source_loose_for_each_object(struct odb_source *source, void *cb_data, const struct odb_for_each_object_options *opts) { + struct odb_source_files *files = odb_source_files_downcast(source); struct for_each_object_wrapper_data data = { - .source = source, + .loose = files->loose, .request = request, .cb = cb, .cb_data = cb_data, diff --git a/object-file.h b/object-file.h index 420a0fff2e..8ac2832dac 100644 --- a/object-file.h +++ b/object-file.h @@ -21,11 +21,6 @@ struct object_info; struct odb_read_stream; struct odb_source; -int odb_source_loose_read_object_info(struct odb_source *source, - const struct object_id *oid, - struct object_info *oi, - enum object_info_flags flags); - int odb_source_loose_read_object_stream(struct odb_read_stream **out, struct odb_source *source, const struct object_id *oid); @@ -198,6 +193,12 @@ int read_loose_object(struct repository *repo, void **contents, struct object_info *oi); +int read_object_info_from_path(struct odb_source_loose *loose, + const char *path, + const struct object_id *oid, + struct object_info *oi, + enum object_info_flags flags); + struct odb_transaction; /* diff --git a/odb/source-files.c b/odb/source-files.c index 59e3a70d80..8d6924755f 100644 --- a/odb/source-files.c +++ b/odb/source-files.c @@ -55,7 +55,7 @@ static int odb_source_files_read_object_info(struct odb_source *source, struct odb_source_files *files = odb_source_files_downcast(source); if (!packfile_store_read_object_info(files->packed, oid, oi, flags) || - !odb_source_loose_read_object_info(source, oid, oi, flags)) + !odb_source_read_object_info(&files->loose->base, oid, oi, flags)) return 0; return -1; diff --git a/odb/source-loose.c b/odb/source-loose.c index 65c1076659..50f387ecf3 100644 --- a/odb/source-loose.c +++ b/odb/source-loose.c @@ -2,10 +2,33 @@ #include "abspath.h" #include "chdir-notify.h" #include "loose.h" +#include "object-file.h" #include "odb.h" #include "odb/source-files.h" #include "odb/source-loose.h" #include "oidtree.h" +#include "strbuf.h" + +static int odb_source_loose_read_object_info(struct odb_source *source, + const struct object_id *oid, + struct object_info *oi, + enum object_info_flags flags) +{ + struct odb_source_loose *loose = odb_source_loose_downcast(source); + static struct strbuf buf = STRBUF_INIT; + + /* + * The second read shouldn't cause new loose objects to show up, unless + * there was a race condition with a secondary process. We don't care + * about this case though, so we simply skip reading loose objects a + * second time. + */ + if (flags & OBJECT_INFO_SECOND_READ) + return -1; + + odb_loose_path(source, &buf, oid); + return read_object_info_from_path(loose, buf.buf, oid, oi, flags); +} static void odb_source_loose_clear_cache(struct odb_source_loose *loose) { @@ -60,6 +83,7 @@ struct odb_source_loose *odb_source_loose_new(struct odb_source_files *files) loose->base.free = odb_source_loose_free; loose->base.close = odb_source_loose_close; loose->base.reprepare = odb_source_loose_reprepare; + loose->base.read_object_info = odb_source_loose_read_object_info; if (!is_absolute_path(loose->base.path)) chdir_notify_register(NULL, odb_source_loose_reparent, loose);