object-file: get rid of `the_repository` when freshening objects
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>
Patrick Steinhardt committed
Jul 17, 2025 at 06:56 UTC
1031f57695ed02da06d1af5ac945bb243262fa09
1 file changed
+11
-11
object-file.c
+11
-11
@@ -893,23 +893,21 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
893
FOF_SKIP_COLLISION_CHECK);
894
}
895
896
-static int freshen_loose_object(const struct object_id *oid)
896
+static int freshen_loose_object(struct object_database *odb,
897
+ const struct object_id *oid)
898
{
898
- struct odb_source *source;
899
-
900
- odb_prepare_alternates(the_repository->objects);
901
- for (source = the_repository->objects->sources; source; source = source->next) {
899
+ odb_prepare_alternates(odb);
900
+ for (struct odb_source *source = odb->sources; source; source = source->next)
901
if (check_and_freshen_source(source, oid, 1))
902
return 1;
904
- }
905
-
903
return 0;
904
}
905
909
-static int freshen_packed_object(const struct object_id *oid)
906
+static int freshen_packed_object(struct object_database *odb,
907
+ const struct object_id *oid)
908
{
909
struct pack_entry e;
912
- if (!find_pack_entry(the_repository, oid, &e))
910
+ if (!find_pack_entry(odb->repo, oid, &e))
911
return 0;
912
if (e.p->is_cruft)
913
return 0;
@@ -999,7 +997,8 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
997
die(_("deflateEnd on stream object failed (%d)"), ret);
998
close_loose_object(fd, tmp_file.buf);
999
1002
- if (freshen_packed_object(oid) || freshen_loose_object(oid)) {
1000
+ if (freshen_packed_object(the_repository->objects, oid) ||
1001
+ freshen_loose_object(the_repository->objects, oid)) {
1002
unlink_or_warn(tmp_file.buf);
1003
goto cleanup;
1004
}
@@ -1062,7 +1061,8 @@ int write_object_file_flags(const void *buf, unsigned long len,
1061
* it out into .git/objects/??/?{38} file.
1062
*/
1063
write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
1065
- if (freshen_packed_object(oid) || freshen_loose_object(oid))
1064
+ if (freshen_packed_object(repo->objects, oid) ||
1065
+ freshen_loose_object(repo->objects, oid))
1066
return 0;
1067
if (write_loose_object(oid, hdr, hdrlen, buf, len, 0, flags))
1068
return -1;