Git fork

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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
c2b5d149 0df00535

+13 -11
+2 -1
builtin/pack-objects.c
··· 4411 4411 if (!packlist_find(&to_pack, &oid) && 4412 4412 !has_sha1_pack_kept_or_nonlocal(&oid) && 4413 4413 !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)) 4415 4416 die(_("unable to force loose object")); 4416 4417 loosened_objects_nr++; 4417 4418 }
+9 -9
object-file.c
··· 1077 1077 return 0; 1078 1078 } 1079 1079 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) 1081 1082 { 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; 1084 1084 void *buf; 1085 1085 unsigned long len; 1086 1086 struct object_info oi = OBJECT_INFO_INIT; ··· 1090 1090 int hdrlen; 1091 1091 int ret; 1092 1092 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)) 1095 1095 return 0; 1096 1096 1097 1097 oi.typep = &type; 1098 1098 oi.sizep = &len; 1099 1099 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)) 1101 1101 return error(_("cannot read object for %s"), oid_to_hex(oid)); 1102 1102 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)) 1104 1104 return error(_("cannot map object %s to %s"), 1105 1105 oid_to_hex(oid), compat->name); 1106 1106 } 1107 1107 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); 1109 1109 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); 1111 1111 free(buf); 1112 1112 1113 1113 return ret;
+2 -1
object-file.h
··· 161 161 struct input_stream *in_stream, size_t len, 162 162 struct object_id *oid); 163 163 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); 165 166 166 167 /** 167 168 * With in-core object data in "buf", rehash it to make sure the