]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-file: move `force_object_loose()`
authorPatrick Steinhardt <ps@pks.im>
Fri, 17 Jul 2026 09:32:16 +0000 (11:32 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 19 Jul 2026 02:03:49 +0000 (19:03 -0700)
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pack-objects.c
object-file.c
object-file.h

index e64a96f1a727ec45e97a56d888717050b672cc92..bb3bc486e8be909159f573d59bbfeb1e6b85bb63 100644 (file)
@@ -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;
index 89825feed0c1b1998066dfb3e604357e980372c8..b867d8d9de10af90ca8d6d2e2f88bd74629aea80 100644 (file)
@@ -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,
index 9fd540afb6c6e7f4745b0c0aa59b5f707674555b..31781a9c5308d8517e4cbee22c2bb20a8c559c80 100644 (file)
@@ -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.