From: Patrick Steinhardt Date: Fri, 17 Jul 2026 09:32:16 +0000 (+0200) Subject: object-file: move `force_object_loose()` X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a6c1e16b480a797a61a47616772e7254f7759053;p=thirdparty%2Fgit.git object-file: move `force_object_loose()` In the preceding commits we have refactored `force_object_loose()` to not call internal functions anymore for writing the object. Instead, it now only uses generic functions that are accessible to all callers. Consequently, we can now easily move the function to its only caller, which is git-pack-objects(1). Do so. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index e64a96f1a7..bb3bc486e8 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -32,6 +32,7 @@ #include "list.h" #include "packfile.h" #include "object-file.h" +#include "object-file-convert.h" #include "odb.h" #include "odb/streaming.h" #include "replace-object.h" @@ -4622,6 +4623,51 @@ static int loosened_object_can_be_discarded(const struct object_id *oid, return 1; } +static int force_object_loose(struct odb_source *source, + const struct object_id *oid, + const time_t *mtime) +{ + struct odb_source_files *files = odb_source_files_downcast(source); + const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo; + struct object_info oi = OBJECT_INFO_INIT; + struct object_id compat_oid, *compat_oid_p = NULL; + enum object_type type; + void *buf = NULL; + size_t len; + int ret; + + for (struct odb_source *s = source->odb->sources; s; s = s->next) { + struct odb_source_files *files = odb_source_files_downcast(s); + if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0)) + return 0; + } + + oi.typep = &type; + oi.sizep = &len; + oi.contentp = &buf; + if (odb_read_object_info_extended(source->odb, oid, &oi, 0)) { + ret = error(_("cannot read object for %s"), oid_to_hex(oid)); + goto out; + } + + if (compat) { + if (repo_oid_to_algop(source->odb->repo, oid, compat, &compat_oid)) { + ret = error(_("cannot map object %s to %s"), + oid_to_hex(oid), compat->name); + goto out; + } + + compat_oid_p = &compat_oid; + } + + ret = odb_source_write_object(&files->loose->base, buf, len, type, oid, + compat_oid_p, mtime, 0); + +out: + free(buf); + return ret; +} + static void loosen_unused_packed_objects(void) { struct packed_git *p; diff --git a/object-file.c b/object-file.c index 89825feed0..b867d8d9de 100644 --- a/object-file.c +++ b/object-file.c @@ -893,50 +893,6 @@ cleanup: return err; } -int force_object_loose(struct odb_source *source, - const struct object_id *oid, const time_t *mtime) -{ - struct odb_source_files *files = odb_source_files_downcast(source); - const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo; - struct object_info oi = OBJECT_INFO_INIT; - struct object_id compat_oid, *compat_oid_p = NULL; - enum object_type type; - void *buf = NULL; - size_t len; - int ret; - - for (struct odb_source *s = source->odb->sources; s; s = s->next) { - struct odb_source_files *files = odb_source_files_downcast(s); - if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0)) - return 0; - } - - oi.typep = &type; - oi.sizep = &len; - oi.contentp = &buf; - if (odb_read_object_info_extended(source->odb, oid, &oi, 0)) { - ret = error(_("cannot read object for %s"), oid_to_hex(oid)); - goto out; - } - - if (compat) { - if (repo_oid_to_algop(source->odb->repo, oid, compat, &compat_oid)) { - ret = error(_("cannot map object %s to %s"), - oid_to_hex(oid), compat->name); - goto out; - } - - compat_oid_p = &compat_oid; - } - - ret = odb_source_write_object(&files->loose->base, buf, len, type, oid, - compat_oid_p, mtime, 0); - -out: - free(buf); - return ret; -} - /* * We can't use the normal fsck_error_function() for index_mem(), * because we don't yet have a valid oid for it to report. Instead, diff --git a/object-file.h b/object-file.h index 9fd540afb6..31781a9c53 100644 --- a/object-file.h +++ b/object-file.h @@ -98,10 +98,6 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr, int format_object_header(char *str, size_t size, enum object_type type, size_t objsize); -int force_object_loose(struct odb_source *source, - const struct object_id *oid, - const time_t *mtime); - /** * With in-core object data in "buf", rehash it to make sure the * object name actually matches "oid" to detect object corruption.