Skip to content

Commit 1031f57

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f6638bf commit 1031f57

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

object-file.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -893,23 +893,21 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
893893
FOF_SKIP_COLLISION_CHECK);
894894
}
895895

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)
897898
{
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)
902901
if (check_and_freshen_source(source, oid, 1))
903902
return 1;
904-
}
905-
906903
return 0;
907904
}
908905

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)
910908
{
911909
struct pack_entry e;
912-
if (!find_pack_entry(the_repository, oid, &e))
910+
if (!find_pack_entry(odb->repo, oid, &e))
913911
return 0;
914912
if (e.p->is_cruft)
915913
return 0;
@@ -999,7 +997,8 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
999997
die(_("deflateEnd on stream object failed (%d)"), ret);
1000998
close_loose_object(fd, tmp_file.buf);
1001999

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)) {
10031002
unlink_or_warn(tmp_file.buf);
10041003
goto cleanup;
10051004
}
@@ -1062,7 +1061,8 @@ int write_object_file_flags(const void *buf, unsigned long len,
10621061
* it out into .git/objects/??/?{38} file.
10631062
*/
10641063
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))
10661066
return 0;
10671067
if (write_loose_object(oid, hdr, hdrlen, buf, len, 0, flags))
10681068
return -1;

0 commit comments

Comments
 (0)