Git fork

loose: write loose objects map via their source

When a repository is configured to have a compatibility hash algorithm
we keep track of object ID mappings for loose objects via the loose
object map. This map simply maps an object ID of the actual hash to the
object ID of the compatibility hash. This loose object map is an
inherent property of the loose files backend and thus of one specific
object source.

Refactor the interfaces to reflect this by requiring a `struct
odb_source` as input instead of a repository. This prepares for
subsequent commits where we will refactor writing of loose objects to
work on a `struct odb_source`, as well.

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
0f9b1893 cbb388f3

+15 -11
+9 -7
loose.c
··· 166 166 return -1; 167 167 } 168 168 169 - static int write_one_object(struct repository *repo, const struct object_id *oid, 169 + static int write_one_object(struct odb_source *source, 170 + const struct object_id *oid, 170 171 const struct object_id *compat_oid) 171 172 { 172 173 struct lock_file lock; ··· 174 175 struct stat st; 175 176 struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT; 176 177 177 - repo_common_path_replace(repo, &path, "objects/loose-object-idx"); 178 + strbuf_addf(&path, "%s/loose-object-idx", source->path); 178 179 hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1); 179 180 180 181 fd = open(path.buf, O_WRONLY | O_CREAT | O_APPEND, 0666); ··· 190 191 goto errout; 191 192 if (close(fd)) 192 193 goto errout; 193 - adjust_shared_perm(repo, path.buf); 194 + adjust_shared_perm(source->odb->repo, path.buf); 194 195 rollback_lock_file(&lock); 195 196 strbuf_release(&buf); 196 197 strbuf_release(&path); ··· 204 205 return -1; 205 206 } 206 207 207 - int repo_add_loose_object_map(struct repository *repo, const struct object_id *oid, 208 + int repo_add_loose_object_map(struct odb_source *source, 209 + const struct object_id *oid, 208 210 const struct object_id *compat_oid) 209 211 { 210 212 int inserted = 0; 211 213 212 - if (!should_use_loose_object_map(repo)) 214 + if (!should_use_loose_object_map(source->odb->repo)) 213 215 return 0; 214 216 215 - inserted = insert_loose_map(repo->objects->sources, oid, compat_oid); 217 + inserted = insert_loose_map(source, oid, compat_oid); 216 218 if (inserted) 217 - return write_one_object(repo, oid, compat_oid); 219 + return write_one_object(source, oid, compat_oid); 218 220 return 0; 219 221 } 220 222
+3 -1
loose.h
··· 4 4 #include "khash.h" 5 5 6 6 struct repository; 7 + struct odb_source; 7 8 8 9 struct loose_object_map { 9 10 kh_oid_map_t *to_compat; ··· 16 17 const struct object_id *src, 17 18 const struct git_hash_algo *dest_algo, 18 19 struct object_id *dest); 19 - int repo_add_loose_object_map(struct repository *repo, const struct object_id *oid, 20 + int repo_add_loose_object_map(struct odb_source *source, 21 + const struct object_id *oid, 20 22 const struct object_id *compat_oid); 21 23 int repo_read_loose_object_map(struct repository *repo); 22 24 int repo_write_loose_object_map(struct repository *repo);
+3 -3
object-file.c
··· 1025 1025 err = finalize_object_file_flags(the_repository, tmp_file.buf, filename.buf, 1026 1026 FOF_SKIP_COLLISION_CHECK); 1027 1027 if (!err && compat) 1028 - err = repo_add_loose_object_map(the_repository, oid, &compat_oid); 1028 + err = repo_add_loose_object_map(the_repository->objects->sources, oid, &compat_oid); 1029 1029 cleanup: 1030 1030 strbuf_release(&tmp_file); 1031 1031 strbuf_release(&filename); ··· 1069 1069 if (write_loose_object(oid, hdr, hdrlen, buf, len, 0, flags)) 1070 1070 return -1; 1071 1071 if (compat) 1072 - return repo_add_loose_object_map(repo, oid, &compat_oid); 1072 + return repo_add_loose_object_map(repo->objects->sources, oid, &compat_oid); 1073 1073 return 0; 1074 1074 } 1075 1075 ··· 1103 1103 hdrlen = format_object_header(hdr, sizeof(hdr), type, len); 1104 1104 ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime, 0); 1105 1105 if (!ret && compat) 1106 - ret = repo_add_loose_object_map(the_repository, oid, &compat_oid); 1106 + ret = repo_add_loose_object_map(the_repository->objects->sources, oid, &compat_oid); 1107 1107 free(buf); 1108 1108 1109 1109 return ret;