Skip to content

Commit cb506a8

Browse files
pks-tgitster
authored andcommitted
odb: introduce "files" source
Introduce a new "files" object database source. This source encapsulates access to both loose object files and the packfile store, similar to how the "files" backend for refs encapsulates access to loose refs and the packed-refs file. Note that for now the "files" source is still a direct member of a `struct odb_source`. This architecture will be reversed in the next commit so that the files source contains a `struct odb_source`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ba1c21d commit cb506a8

20 files changed

Lines changed: 114 additions & 68 deletions

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,7 @@ LIB_OBJS += object-name.o
12151215
LIB_OBJS += object.o
12161216
LIB_OBJS += odb.o
12171217
LIB_OBJS += odb/source.o
1218+
LIB_OBJS += odb/source-files.o
12181219
LIB_OBJS += odb/streaming.o
12191220
LIB_OBJS += oid-array.o
12201221
LIB_OBJS += oidmap.o

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ static void batch_each_object(struct batch_options *opt,
882882
struct object_info oi = { 0 };
883883

884884
for (source = the_repository->objects->sources; source; source = source->next) {
885-
int ret = packfile_store_for_each_object(source->packfiles, &oi,
885+
int ret = packfile_store_for_each_object(source->files->packed, &oi,
886886
batch_one_object_oi, &payload, flags);
887887
if (ret)
888888
break;

builtin/fast-import.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ static void end_packfile(void)
900900
idx_name = keep_pack(create_index());
901901

902902
/* Register the packfile with core git's machinery. */
903-
new_p = packfile_store_load_pack(pack_data->repo->objects->sources->packfiles,
903+
new_p = packfile_store_load_pack(pack_data->repo->objects->sources->files->packed,
904904
idx_name, 1);
905905
if (!new_p)
906906
die(_("core Git rejected index %s"), idx_name);
@@ -982,7 +982,7 @@ static int store_object(
982982
}
983983

984984
for (source = the_repository->objects->sources; source; source = source->next) {
985-
if (!packfile_list_find_oid(packfile_store_get_packs(source->packfiles), &oid))
985+
if (!packfile_list_find_oid(packfile_store_get_packs(source->files->packed), &oid))
986986
continue;
987987
e->type = type;
988988
e->pack_id = MAX_PACK_ID;
@@ -1187,7 +1187,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
11871187
}
11881188

11891189
for (source = the_repository->objects->sources; source; source = source->next) {
1190-
if (!packfile_list_find_oid(packfile_store_get_packs(source->packfiles), &oid))
1190+
if (!packfile_list_find_oid(packfile_store_get_packs(source->files->packed), &oid))
11911191
continue;
11921192
e->type = OBJ_BLOB;
11931193
e->pack_id = MAX_PACK_ID;

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ int cmd_grep(int argc,
12191219

12201220
odb_prepare_alternates(the_repository->objects);
12211221
for (source = the_repository->objects->sources; source; source = source->next)
1222-
packfile_store_prepare(source->packfiles);
1222+
packfile_store_prepare(source->files->packed);
12231223
}
12241224

12251225
start_threads(&opt);

builtin/index-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
16381638
hash, "idx", 1);
16391639

16401640
if (do_fsck_object && startup_info->have_repository)
1641-
packfile_store_load_pack(the_repository->objects->sources->packfiles,
1641+
packfile_store_load_pack(the_repository->objects->sources->files->packed,
16421642
final_index_name, 0);
16431643

16441644
if (!from_stdin) {

builtin/pack-objects.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ static int want_cruft_object_mtime(struct repository *r,
15311531
struct odb_source *source;
15321532

15331533
for (source = r->objects->sources; source; source = source->next) {
1534-
struct packed_git **cache = packfile_store_get_kept_pack_cache(source->packfiles, flags);
1534+
struct packed_git **cache = packfile_store_get_kept_pack_cache(source->files->packed, flags);
15351535

15361536
for (; *cache; cache++) {
15371537
struct packed_git *p = *cache;
@@ -1753,11 +1753,11 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17531753
}
17541754

17551755
for (source = the_repository->objects->sources; source; source = source->next) {
1756-
for (e = source->packfiles->packs.head; e; e = e->next) {
1756+
for (e = source->files->packed->packs.head; e; e = e->next) {
17571757
struct packed_git *p = e->pack;
17581758
want = want_object_in_pack_one(p, oid, exclude, found_pack, found_offset, found_mtime);
17591759
if (!exclude && want > 0)
1760-
packfile_list_prepend(&source->packfiles->packs, p);
1760+
packfile_list_prepend(&source->files->packed->packs, p);
17611761
if (want != -1)
17621762
return want;
17631763
}
@@ -4340,7 +4340,7 @@ static void add_objects_in_unpacked_packs(void)
43404340
if (!source->local)
43414341
continue;
43424342

4343-
if (packfile_store_for_each_object(source->packfiles, &oi,
4343+
if (packfile_store_for_each_object(source->files->packed, &oi,
43444344
add_object_in_unpacked_pack, NULL,
43454345
ODB_FOR_EACH_OBJECT_PACK_ORDER |
43464346
ODB_FOR_EACH_OBJECT_LOCAL_ONLY |

commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
19811981

19821982
odb_prepare_alternates(ctx->r->objects);
19831983
for (source = ctx->r->objects->sources; source; source = source->next)
1984-
packfile_store_for_each_object(source->packfiles, &oi, add_packed_commits_oi,
1984+
packfile_store_for_each_object(source->files->packed, &oi, add_packed_commits_oi,
19851985
ctx, ODB_FOR_EACH_OBJECT_PACK_ORDER);
19861986

19871987
if (ctx->progress_done < ctx->approx_nr_objects)

http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,7 @@ void http_install_packfile(struct packed_git *p,
25442544
struct packfile_list *list_to_remove_from)
25452545
{
25462546
packfile_list_remove(list_to_remove_from, p);
2547-
packfile_store_add_pack(the_repository->objects->sources->packfiles, p);
2547+
packfile_store_add_pack(the_repository->objects->sources->files->packed, p);
25482548
}
25492549

25502550
struct http_pack_request *new_http_pack_request(

loose.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ static int insert_loose_map(struct odb_source *source,
4949
const struct object_id *oid,
5050
const struct object_id *compat_oid)
5151
{
52-
struct loose_object_map *map = source->loose->map;
52+
struct loose_object_map *map = source->files->loose->map;
5353
int inserted = 0;
5454

5555
inserted |= insert_oid_pair(map->to_compat, oid, compat_oid);
5656
inserted |= insert_oid_pair(map->to_storage, compat_oid, oid);
5757
if (inserted)
58-
oidtree_insert(source->loose->cache, compat_oid);
58+
oidtree_insert(source->files->loose->cache, compat_oid);
5959

6060
return inserted;
6161
}
@@ -65,11 +65,11 @@ static int load_one_loose_object_map(struct repository *repo, struct odb_source
6565
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
6666
FILE *fp;
6767

68-
if (!source->loose->map)
69-
loose_object_map_init(&source->loose->map);
70-
if (!source->loose->cache) {
71-
ALLOC_ARRAY(source->loose->cache, 1);
72-
oidtree_init(source->loose->cache);
68+
if (!source->files->loose->map)
69+
loose_object_map_init(&source->files->loose->map);
70+
if (!source->files->loose->cache) {
71+
ALLOC_ARRAY(source->files->loose->cache, 1);
72+
oidtree_init(source->files->loose->cache);
7373
}
7474

7575
insert_loose_map(source, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
@@ -125,7 +125,7 @@ int repo_read_loose_object_map(struct repository *repo)
125125

126126
int repo_write_loose_object_map(struct repository *repo)
127127
{
128-
kh_oid_map_t *map = repo->objects->sources->loose->map->to_compat;
128+
kh_oid_map_t *map = repo->objects->sources->files->loose->map->to_compat;
129129
struct lock_file lock;
130130
int fd;
131131
khiter_t iter;
@@ -231,7 +231,7 @@ int repo_loose_object_map_oid(struct repository *repo,
231231
khiter_t pos;
232232

233233
for (source = repo->objects->sources; source; source = source->next) {
234-
struct loose_object_map *loose_map = source->loose->map;
234+
struct loose_object_map *loose_map = source->files->loose->map;
235235
if (!loose_map)
236236
continue;
237237
map = (to == repo->compat_hash_algo) ?

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ libgit_sources = [
398398
'object.c',
399399
'odb.c',
400400
'odb/source.c',
401+
'odb/source-files.c',
401402
'odb/streaming.c',
402403
'oid-array.c',
403404
'oidmap.c',

0 commit comments

Comments
 (0)