Skip to content

Commit 0f9b189

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

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

loose.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,16 @@ int repo_write_loose_object_map(struct repository *repo)
166166
return -1;
167167
}
168168

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,
170171
const struct object_id *compat_oid)
171172
{
172173
struct lock_file lock;
173174
int fd;
174175
struct stat st;
175176
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
176177

177-
repo_common_path_replace(repo, &path, "objects/loose-object-idx");
178+
strbuf_addf(&path, "%s/loose-object-idx", source->path);
178179
hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1);
179180

180181
fd = open(path.buf, O_WRONLY | O_CREAT | O_APPEND, 0666);
@@ -190,7 +191,7 @@ static int write_one_object(struct repository *repo, const struct object_id *oid
190191
goto errout;
191192
if (close(fd))
192193
goto errout;
193-
adjust_shared_perm(repo, path.buf);
194+
adjust_shared_perm(source->odb->repo, path.buf);
194195
rollback_lock_file(&lock);
195196
strbuf_release(&buf);
196197
strbuf_release(&path);
@@ -204,17 +205,18 @@ static int write_one_object(struct repository *repo, const struct object_id *oid
204205
return -1;
205206
}
206207

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,
208210
const struct object_id *compat_oid)
209211
{
210212
int inserted = 0;
211213

212-
if (!should_use_loose_object_map(repo))
214+
if (!should_use_loose_object_map(source->odb->repo))
213215
return 0;
214216

215-
inserted = insert_loose_map(repo->objects->sources, oid, compat_oid);
217+
inserted = insert_loose_map(source, oid, compat_oid);
216218
if (inserted)
217-
return write_one_object(repo, oid, compat_oid);
219+
return write_one_object(source, oid, compat_oid);
218220
return 0;
219221
}
220222

loose.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "khash.h"
55

66
struct repository;
7+
struct odb_source;
78

89
struct loose_object_map {
910
kh_oid_map_t *to_compat;
@@ -16,7 +17,8 @@ int repo_loose_object_map_oid(struct repository *repo,
1617
const struct object_id *src,
1718
const struct git_hash_algo *dest_algo,
1819
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,
2022
const struct object_id *compat_oid);
2123
int repo_read_loose_object_map(struct repository *repo);
2224
int repo_write_loose_object_map(struct repository *repo);

object-file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
10251025
err = finalize_object_file_flags(the_repository, tmp_file.buf, filename.buf,
10261026
FOF_SKIP_COLLISION_CHECK);
10271027
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);
10291029
cleanup:
10301030
strbuf_release(&tmp_file);
10311031
strbuf_release(&filename);
@@ -1069,7 +1069,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
10691069
if (write_loose_object(oid, hdr, hdrlen, buf, len, 0, flags))
10701070
return -1;
10711071
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);
10731073
return 0;
10741074
}
10751075

@@ -1103,7 +1103,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
11031103
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
11041104
ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime, 0);
11051105
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);
11071107
free(buf);
11081108

11091109
return ret;

0 commit comments

Comments
 (0)