From: Patrick Steinhardt Date: Fri, 17 Jul 2026 09:32:15 +0000 (+0200) Subject: object-file: force objects loose via generic interface X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=627d3b7ab5dc76f0d4e4ef7a42184524df8f2ab1;p=thirdparty%2Fgit.git object-file: force objects loose via generic interface When repacking objects we may end up "loosening" objects via `force_objects_loose()`. The implementation of this logic still sits with "object-file.c" even though it is ultimately an implementation detail of the "files" backend. Moving this logic around is non-trivial though as we depend on `write_loose_object()`, which is an internal implementation detail of how we write loose objects. Until now it wasn't possible to use the generic function `odb_source_write_object()` though, because the "loose" implementation thereof would skip writing the object in case it already exists in any other source. This restriction was lifted over the preceding commits though, where this object existence check is now handled on the object database level and not on the individual source level anymore. Consequently, it is now possible to use generic interfaces. Refactor the code accordingly so that we can move the logic around in a subsequent commit. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- diff --git a/object-file.c b/object-file.c index 067a63a4f1..89825feed0 100644 --- a/object-file.c +++ b/object-file.c @@ -898,13 +898,11 @@ int force_object_loose(struct odb_source *source, { struct odb_source_files *files = odb_source_files_downcast(source); const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo; - void *buf = NULL; - size_t len; struct object_info oi = OBJECT_INFO_INIT; - struct object_id compat_oid; + struct object_id compat_oid, *compat_oid_p = NULL; enum object_type type; - char hdr[MAX_HEADER_LEN]; - int hdrlen; + void *buf = NULL; + size_t len; int ret; for (struct odb_source *s = source->odb->sources; s; s = s->next) { @@ -927,15 +925,12 @@ int force_object_loose(struct odb_source *source, oid_to_hex(oid), compat->name); goto out; } - } - hdrlen = format_object_header(hdr, sizeof(hdr), type, len); - ret = write_loose_object(files->loose, oid, hdr, hdrlen, buf, len, mtime, 0); - if (ret) - goto out; + compat_oid_p = &compat_oid; + } - if (compat) - ret = repo_add_loose_object_map(files->loose, oid, &compat_oid); + ret = odb_source_write_object(&files->loose->base, buf, len, type, oid, + compat_oid_p, mtime, 0); out: free(buf);