Skip to content

Commit 6cdef94

Browse files
committed
Merge branch 'ps/odb-sources' into ps/object-counting
* ps/odb-sources: odb/source: make `begin_transaction()` function pluggable odb/source: make `write_alternate()` function pluggable odb/source: make `read_alternates()` function pluggable odb/source: make `write_object_stream()` function pluggable odb/source: make `write_object()` function pluggable odb/source: make `freshen_object()` function pluggable odb/source: make `for_each_object()` function pluggable odb/source: make `read_object_stream()` function pluggable odb/source: make `read_object_info()` function pluggable odb/source: make `close()` function pluggable odb/source: make `reprepare()` function pluggable odb/source: make `free()` function pluggable odb/source: introduce source type for robustness odb: move reparenting logic into respective subsystems odb: embed base source in the "files" backend odb: introduce "files" source odb: split `struct odb_source` into separate header
2 parents d181b93 + d6fc6fe commit 6cdef94

23 files changed

+953
-354
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,8 @@ LIB_OBJS += object-file.o
12141214
LIB_OBJS += object-name.o
12151215
LIB_OBJS += object.o
12161216
LIB_OBJS += odb.o
1217+
LIB_OBJS += odb/source.o
1218+
LIB_OBJS += odb/source-files.o
12171219
LIB_OBJS += odb/streaming.o
12181220
LIB_OBJS += oid-array.o
12191221
LIB_OBJS += oidmap.o

builtin/cat-file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,8 @@ 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+
struct odb_source_files *files = odb_source_files_downcast(source);
886+
int ret = packfile_store_for_each_object(files->packed, &oi,
886887
batch_one_object_oi, &payload, flags);
887888
if (ret)
888889
break;

builtin/fast-import.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ static void end_packfile(void)
875875
running = 1;
876876
clear_delta_base_cache();
877877
if (object_count) {
878+
struct odb_source_files *files = odb_source_files_downcast(pack_data->repo->objects->sources);
878879
struct packed_git *new_p;
879880
struct object_id cur_pack_oid;
880881
char *idx_name;
@@ -900,8 +901,7 @@ static void end_packfile(void)
900901
idx_name = keep_pack(create_index());
901902

902903
/* Register the packfile with core git's machinery. */
903-
new_p = packfile_store_load_pack(pack_data->repo->objects->sources->packfiles,
904-
idx_name, 1);
904+
new_p = packfile_store_load_pack(files->packed, idx_name, 1);
905905
if (!new_p)
906906
die(_("core Git rejected index %s"), idx_name);
907907
all_packs[pack_id] = new_p;
@@ -982,7 +982,9 @@ 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+
struct odb_source_files *files = odb_source_files_downcast(source);
986+
987+
if (!packfile_list_find_oid(packfile_store_get_packs(files->packed), &oid))
986988
continue;
987989
e->type = type;
988990
e->pack_id = MAX_PACK_ID;
@@ -1187,7 +1189,9 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
11871189
}
11881190

11891191
for (source = the_repository->objects->sources; source; source = source->next) {
1190-
if (!packfile_list_find_oid(packfile_store_get_packs(source->packfiles), &oid))
1192+
struct odb_source_files *files = odb_source_files_downcast(source);
1193+
1194+
if (!packfile_list_find_oid(packfile_store_get_packs(files->packed), &oid))
11911195
continue;
11921196
e->type = OBJ_BLOB;
11931197
e->pack_id = MAX_PACK_ID;

builtin/grep.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,10 @@ int cmd_grep(int argc,
12181218
struct odb_source *source;
12191219

12201220
odb_prepare_alternates(the_repository->objects);
1221-
for (source = the_repository->objects->sources; source; source = source->next)
1222-
packfile_store_prepare(source->packfiles);
1221+
for (source = the_repository->objects->sources; source; source = source->next) {
1222+
struct odb_source_files *files = odb_source_files_downcast(source);
1223+
packfile_store_prepare(files->packed);
1224+
}
12231225
}
12241226

12251227
start_threads(&opt);

builtin/index-pack.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,9 +1637,11 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
16371637
rename_tmp_packfile(&final_index_name, curr_index_name, &index_name,
16381638
hash, "idx", 1);
16391639

1640-
if (do_fsck_object && startup_info->have_repository)
1641-
packfile_store_load_pack(the_repository->objects->sources->packfiles,
1642-
final_index_name, 0);
1640+
if (do_fsck_object && startup_info->have_repository) {
1641+
struct odb_source_files *files =
1642+
odb_source_files_downcast(the_repository->objects->sources);
1643+
packfile_store_load_pack(files->packed, final_index_name, 0);
1644+
}
16431645

16441646
if (!from_stdin) {
16451647
printf("%s\n", hash_to_hex(hash));

builtin/pack-objects.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,8 @@ 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 odb_source_files *files = odb_source_files_downcast(source);
1535+
struct packed_git **cache = packfile_store_get_kept_pack_cache(files->packed, flags);
15351536

15361537
for (; *cache; cache++) {
15371538
struct packed_git *p = *cache;
@@ -1753,11 +1754,13 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17531754
}
17541755

17551756
for (source = the_repository->objects->sources; source; source = source->next) {
1756-
for (e = source->packfiles->packs.head; e; e = e->next) {
1757+
struct odb_source_files *files = odb_source_files_downcast(source);
1758+
1759+
for (e = files->packed->packs.head; e; e = e->next) {
17571760
struct packed_git *p = e->pack;
17581761
want = want_object_in_pack_one(p, oid, exclude, found_pack, found_offset, found_mtime);
17591762
if (!exclude && want > 0)
1760-
packfile_list_prepend(&source->packfiles->packs, p);
1763+
packfile_list_prepend(&files->packed->packs, p);
17611764
if (want != -1)
17621765
return want;
17631766
}
@@ -4347,10 +4350,12 @@ static void add_objects_in_unpacked_packs(void)
43474350

43484351
odb_prepare_alternates(to_pack.repo->objects);
43494352
for (source = to_pack.repo->objects->sources; source; source = source->next) {
4353+
struct odb_source_files *files = odb_source_files_downcast(source);
4354+
43504355
if (!source->local)
43514356
continue;
43524357

4353-
if (packfile_store_for_each_object(source->packfiles, &oi,
4358+
if (packfile_store_for_each_object(files->packed, &oi,
43544359
add_object_in_unpacked_pack, NULL,
43554360
ODB_FOR_EACH_OBJECT_PACK_ORDER |
43564361
ODB_FOR_EACH_OBJECT_LOCAL_ONLY |

commit-graph.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,9 +1980,11 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
19801980
ctx->approx_nr_objects);
19811981

19821982
odb_prepare_alternates(ctx->r->objects);
1983-
for (source = ctx->r->objects->sources; source; source = source->next)
1984-
packfile_store_for_each_object(source->packfiles, &oi, add_packed_commits_oi,
1983+
for (source = ctx->r->objects->sources; source; source = source->next) {
1984+
struct odb_source_files *files = odb_source_files_downcast(source);
1985+
packfile_store_for_each_object(files->packed, &oi, add_packed_commits_oi,
19851986
ctx, ODB_FOR_EACH_OBJECT_PACK_ORDER);
1987+
}
19861988

19871989
if (ctx->progress_done < ctx->approx_nr_objects)
19881990
display_progress(ctx->progress, ctx->approx_nr_objects);

http.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2543,8 +2543,9 @@ int finish_http_pack_request(struct http_pack_request *preq)
25432543
void http_install_packfile(struct packed_git *p,
25442544
struct packfile_list *list_to_remove_from)
25452545
{
2546+
struct odb_source_files *files = odb_source_files_downcast(the_repository->objects->sources);
25462547
packfile_list_remove(list_to_remove_from, p);
2547-
packfile_store_add_pack(the_repository->objects->sources->packfiles, p);
2548+
packfile_store_add_pack(files->packed, p);
25482549
}
25492550

25502551
struct http_pack_request *new_http_pack_request(

loose.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "path.h"
44
#include "object-file.h"
55
#include "odb.h"
6+
#include "odb/source-files.h"
67
#include "hex.h"
78
#include "repository.h"
89
#include "wrapper.h"
@@ -49,27 +50,29 @@ static int insert_loose_map(struct odb_source *source,
4950
const struct object_id *oid,
5051
const struct object_id *compat_oid)
5152
{
52-
struct loose_object_map *map = source->loose->map;
53+
struct odb_source_files *files = odb_source_files_downcast(source);
54+
struct loose_object_map *map = files->loose->map;
5355
int inserted = 0;
5456

5557
inserted |= insert_oid_pair(map->to_compat, oid, compat_oid);
5658
inserted |= insert_oid_pair(map->to_storage, compat_oid, oid);
5759
if (inserted)
58-
oidtree_insert(source->loose->cache, compat_oid);
60+
oidtree_insert(files->loose->cache, compat_oid);
5961

6062
return inserted;
6163
}
6264

6365
static int load_one_loose_object_map(struct repository *repo, struct odb_source *source)
6466
{
67+
struct odb_source_files *files = odb_source_files_downcast(source);
6568
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
6669
FILE *fp;
6770

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);
71+
if (!files->loose->map)
72+
loose_object_map_init(&files->loose->map);
73+
if (!files->loose->cache) {
74+
ALLOC_ARRAY(files->loose->cache, 1);
75+
oidtree_init(files->loose->cache);
7376
}
7477

7578
insert_loose_map(source, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
@@ -125,7 +128,8 @@ int repo_read_loose_object_map(struct repository *repo)
125128

126129
int repo_write_loose_object_map(struct repository *repo)
127130
{
128-
kh_oid_map_t *map = repo->objects->sources->loose->map->to_compat;
131+
struct odb_source_files *files = odb_source_files_downcast(repo->objects->sources);
132+
kh_oid_map_t *map = files->loose->map->to_compat;
129133
struct lock_file lock;
130134
int fd;
131135
khiter_t iter;
@@ -231,7 +235,8 @@ int repo_loose_object_map_oid(struct repository *repo,
231235
khiter_t pos;
232236

233237
for (source = repo->objects->sources; source; source = source->next) {
234-
struct loose_object_map *loose_map = source->loose->map;
238+
struct odb_source_files *files = odb_source_files_downcast(source);
239+
struct loose_object_map *loose_map = files->loose->map;
235240
if (!loose_map)
236241
continue;
237242
map = (to == repo->compat_hash_algo) ?

meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ libgit_sources = [
399399
'object-name.c',
400400
'object.c',
401401
'odb.c',
402+
'odb/source.c',
403+
'odb/source-files.c',
402404
'odb/streaming.c',
403405
'oid-array.c',
404406
'oidmap.c',

0 commit comments

Comments
 (0)