]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-file: get rid of `the_repository` when freshening objects
authorPatrick Steinhardt <ps@pks.im>
Thu, 17 Jul 2025 04:56:31 +0000 (06:56 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Jul 2025 05:16:14 +0000 (22:16 -0700)
We implicitly depend on `the_repository` when freshening either loose or
packed objects. Refactor these functions to instead accept an object
database as input so that we can get rid of the global dependency.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-file.c

index 9e17e608f789603bec0171aeba80f4e7942b448e..3453989b7e321e32dd159b82c3dd92b67b187cda 100644 (file)
@@ -893,23 +893,21 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
                                          FOF_SKIP_COLLISION_CHECK);
 }
 
-static int freshen_loose_object(const struct object_id *oid)
+static int freshen_loose_object(struct object_database *odb,
+                               const struct object_id *oid)
 {
-       struct odb_source *source;
-
-       odb_prepare_alternates(the_repository->objects);
-       for (source = the_repository->objects->sources; source; source = source->next) {
+       odb_prepare_alternates(odb);
+       for (struct odb_source *source = odb->sources; source; source = source->next)
                if (check_and_freshen_source(source, oid, 1))
                        return 1;
-       }
-
        return 0;
 }
 
-static int freshen_packed_object(const struct object_id *oid)
+static int freshen_packed_object(struct object_database *odb,
+                                const struct object_id *oid)
 {
        struct pack_entry e;
-       if (!find_pack_entry(the_repository, oid, &e))
+       if (!find_pack_entry(odb->repo, oid, &e))
                return 0;
        if (e.p->is_cruft)
                return 0;
@@ -999,7 +997,8 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
                die(_("deflateEnd on stream object failed (%d)"), ret);
        close_loose_object(fd, tmp_file.buf);
 
-       if (freshen_packed_object(oid) || freshen_loose_object(oid)) {
+       if (freshen_packed_object(the_repository->objects, oid) ||
+           freshen_loose_object(the_repository->objects, oid)) {
                unlink_or_warn(tmp_file.buf);
                goto cleanup;
        }
@@ -1062,7 +1061,8 @@ int write_object_file_flags(const void *buf, unsigned long len,
         * it out into .git/objects/??/?{38} file.
         */
        write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
-       if (freshen_packed_object(oid) || freshen_loose_object(oid))
+       if (freshen_packed_object(repo->objects, oid) ||
+           freshen_loose_object(repo->objects, oid))
                return 0;
        if (write_loose_object(oid, hdr, hdrlen, buf, len, 0, flags))
                return -1;