From: Patrick Steinhardt Date: Mon, 02 Nov 2026 11:20:18 GMT Subject: [PATCH 2/6] object-file: move logic to derive loose object paths into backend Message-ID: <20261102-pks-odb-loose-cleanups-v1-2-fbbc86c29693@pks.im> In-Reply-To: <20261102-pks-odb-loose-cleanups-v1-0-fbbc86c29693@pks.im> The logic to derive the filesystem path of a loose object is contained in "object-file.c" even though it's an implementation detail of the "loose" backend. Move the logic into the "loose" backend accordingly. While at it, inline the call to `fill_loose_path()`. Ideally, we'd be able to remove the externally-visible declaration. But unfortunately, we still require access to that function for use in the dumb transport so that it can derive the target path for downloaded objects. This will need to get abstracted eventually, but for now we simply continue to expose the function. Signed-off-by: Patrick Steinhardt --- object-file.c | 25 ------------------------- object-file.h | 8 -------- odb/source-loose.c | 21 +++++++++++++++++++++ odb/source-loose.h | 8 ++++++++ 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/object-file.c b/object-file.c index c1b78a25c9f..ab919f03fef 100644 --- a/object-file.c +++ b/object-file.c @@ -43,31 +43,6 @@ static int get_conv_flags(unsigned flags) return 0; } -static void fill_loose_path(struct strbuf *buf, - const struct object_id *oid, - const struct git_hash_algo *algop) -{ - for (size_t i = 0; i < algop->rawsz; i++) { - static char hex[] = "0123456789abcdef"; - unsigned int val = oid->hash[i]; - strbuf_addch(buf, hex[val >> 4]); - strbuf_addch(buf, hex[val & 0xf]); - if (!i) - strbuf_addch(buf, '/'); - } -} - -const char *odb_loose_path(struct odb_source_loose *loose, - struct strbuf *buf, - const struct object_id *oid) -{ - strbuf_reset(buf); - strbuf_addstr(buf, loose->base.path); - strbuf_addch(buf, '/'); - fill_loose_path(buf, oid, loose->base.odb->repo->hash_algo); - return buf->buf; -} - /* Returns 1 if we have successfully freshened the file, 0 otherwise. */ static int freshen_file(const char *fn, const time_t *mtime) { diff --git a/object-file.h b/object-file.h index 65ab44542b0..3cfcaefa420 100644 --- a/object-file.h +++ b/object-file.h @@ -23,14 +23,6 @@ int index_path(struct index_state *istate, struct object_id *oid, const char *pa struct odb_source; -/* - * Put in `buf` the name of the file in the local object database that - * would be used to store a loose object with the specified oid. - */ -const char *odb_loose_path(struct odb_source_loose *source, - struct strbuf *buf, - const struct object_id *oid); - /* * Iterate over the files in the loose-object parts of the object * directory "path", triggering the following callbacks: diff --git a/odb/source-loose.c b/odb/source-loose.c index 96fc2ed213f..0f29162d752 100644 --- a/odb/source-loose.c +++ b/odb/source-loose.c @@ -18,6 +18,27 @@ #include "tempfile.h" #include "write-or-die.h" +const char *odb_loose_path(struct odb_source_loose *loose, + struct strbuf *buf, + const struct object_id *oid) +{ + static const char hex[] = "0123456789abcdef"; + + strbuf_reset(buf); + strbuf_addstr(buf, loose->base.path); + strbuf_addch(buf, '/'); + + for (size_t i = 0; i < loose->base.odb->repo->hash_algo->rawsz; i++) { + unsigned int val = oid->hash[i]; + strbuf_addch(buf, hex[val >> 4]); + strbuf_addch(buf, hex[val & 0xf]); + if (!i) + strbuf_addch(buf, '/'); + } + + return buf->buf; +} + static int append_loose_object(const struct object_id *oid, const char *path UNUSED, void *data) diff --git a/odb/source-loose.h b/odb/source-loose.h index a6ae808662b..8d4cdac0d50 100644 --- a/odb/source-loose.h +++ b/odb/source-loose.h @@ -49,4 +49,12 @@ static inline struct odb_source_loose *odb_source_loose_downcast(struct odb_sour return container_of(source, struct odb_source_loose, base); } +/* + * Put in `buf` the name of the file in the local object database that + * would be used to store a loose object with the specified oid. + */ +const char *odb_loose_path(struct odb_source_loose *source, + struct strbuf *buf, + const struct object_id *oid); + #endif -- 2.56.0.500.g5d06dc02cd.dirty