Skip to content

Commit c2b5d14

Browse files
pks-tgitster
authored andcommitted
object-file: get rid of the_repository in force_object_loose()
The function `force_object_loose()` forces an object to become a loose object in case it only exists in its packed form. To do so it implicitly relies on `the_repository`. Refactor the function by passing a `struct odb_source` as parameter. While the check whether any such loose object exists already acts on the whole object database, writing the loose object happens in one specific source. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0df0053 commit c2b5d14

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

builtin/pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4411,7 +4411,8 @@ static void loosen_unused_packed_objects(void)
44114411
if (!packlist_find(&to_pack, &oid) &&
44124412
!has_sha1_pack_kept_or_nonlocal(&oid) &&
44134413
!loosened_object_can_be_discarded(&oid, p->mtime)) {
4414-
if (force_object_loose(&oid, p->mtime))
4414+
if (force_object_loose(the_repository->objects->sources,
4415+
&oid, p->mtime))
44154416
die(_("unable to force loose object"));
44164417
loosened_objects_nr++;
44174418
}

object-file.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,10 +1077,10 @@ int write_object_file(struct odb_source *source,
10771077
return 0;
10781078
}
10791079

1080-
int force_object_loose(const struct object_id *oid, time_t mtime)
1080+
int force_object_loose(struct odb_source *source,
1081+
const struct object_id *oid, time_t mtime)
10811082
{
1082-
struct repository *repo = the_repository;
1083-
const struct git_hash_algo *compat = repo->compat_hash_algo;
1083+
const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo;
10841084
void *buf;
10851085
unsigned long len;
10861086
struct object_info oi = OBJECT_INFO_INIT;
@@ -1090,24 +1090,24 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
10901090
int hdrlen;
10911091
int ret;
10921092

1093-
for (struct odb_source *source = repo->objects->sources; source; source = source->next)
1094-
if (has_loose_object(source, oid))
1093+
for (struct odb_source *s = source->odb->sources; s; s = s->next)
1094+
if (has_loose_object(s, oid))
10951095
return 0;
10961096

10971097
oi.typep = &type;
10981098
oi.sizep = &len;
10991099
oi.contentp = &buf;
1100-
if (odb_read_object_info_extended(the_repository->objects, oid, &oi, 0))
1100+
if (odb_read_object_info_extended(source->odb, oid, &oi, 0))
11011101
return error(_("cannot read object for %s"), oid_to_hex(oid));
11021102
if (compat) {
1103-
if (repo_oid_to_algop(repo, oid, compat, &compat_oid))
1103+
if (repo_oid_to_algop(source->odb->repo, oid, compat, &compat_oid))
11041104
return error(_("cannot map object %s to %s"),
11051105
oid_to_hex(oid), compat->name);
11061106
}
11071107
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
1108-
ret = write_loose_object(repo->objects->sources, oid, hdr, hdrlen, buf, len, mtime, 0);
1108+
ret = write_loose_object(source, oid, hdr, hdrlen, buf, len, mtime, 0);
11091109
if (!ret && compat)
1110-
ret = repo_add_loose_object_map(the_repository->objects->sources, oid, &compat_oid);
1110+
ret = repo_add_loose_object_map(source, oid, &compat_oid);
11111111
free(buf);
11121112

11131113
return ret;

object-file.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ int stream_loose_object(struct odb_source *source,
161161
struct input_stream *in_stream, size_t len,
162162
struct object_id *oid);
163163

164-
int force_object_loose(const struct object_id *oid, time_t mtime);
164+
int force_object_loose(struct odb_source *source,
165+
const struct object_id *oid, time_t mtime);
165166

166167
/**
167168
* With in-core object data in "buf", rehash it to make sure the

0 commit comments

Comments
 (0)