Skip to content

Commit 8c13c31

Browse files
committed
Merge branch 'ps/packfile-store'
Code clean-up around the in-core list of all the pack files and object database(s). * ps/packfile-store: packfile: refactor `get_packed_git_mru()` to work on packfile store packfile: refactor `get_all_packs()` to work on packfile store packfile: refactor `get_packed_git()` to work on packfile store packfile: move `get_multi_pack_index()` into "midx.c" packfile: introduce function to load and add packfiles packfile: refactor `install_packed_git()` to work on packfile store packfile: split up responsibilities of `reprepare_packed_git()` packfile: refactor `prepare_packed_git()` to work on packfile store packfile: reorder functions to avoid function declaration odb: move kept cache into `struct packfile_store` odb: move MRU list of packfiles into `struct packfile_store` odb: move packfile map into `struct packfile_store` odb: move initialization bit into `struct packfile_store` odb: move list of packfiles into `struct packfile_store` packfile: introduce a new `struct packfile_store`
2 parents f4f7605 + dd52a29 commit 8c13c31

31 files changed

+396
-269
lines changed

builtin/backfill.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void download_batch(struct backfill_context *ctx)
5353
* We likely have a new packfile. Add it to the packed list to
5454
* avoid possible duplicate downloads of the same objects.
5555
*/
56-
reprepare_packed_git(ctx->repo);
56+
odb_reprepare(ctx->repo->objects);
5757
}
5858

5959
static int fill_missing_blobs(const char *path UNUSED,

builtin/cat-file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,10 @@ static void batch_each_object(struct batch_options *opt,
852852

853853
if (bitmap && !for_each_bitmapped_object(bitmap, &opt->objects_filter,
854854
batch_one_object_bitmapped, &payload)) {
855+
struct packfile_store *packs = the_repository->objects->packfiles;
855856
struct packed_git *pack;
856857

857-
for (pack = get_all_packs(the_repository); pack; pack = pack->next) {
858+
for (pack = packfile_store_get_all_packs(packs); pack; pack = pack->next) {
858859
if (bitmap_index_contains_pack(bitmap, pack) ||
859860
open_pack_index(pack))
860861
continue;

builtin/count-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,15 @@ int cmd_count_objects(int argc,
122122
count_loose, count_cruft, NULL, NULL);
123123

124124
if (verbose) {
125+
struct packfile_store *packs = the_repository->objects->packfiles;
125126
struct packed_git *p;
126127
unsigned long num_pack = 0;
127128
off_t size_pack = 0;
128129
struct strbuf loose_buf = STRBUF_INIT;
129130
struct strbuf pack_buf = STRBUF_INIT;
130131
struct strbuf garbage_buf = STRBUF_INIT;
131132

132-
for (p = get_all_packs(the_repository); p; p = p->next) {
133+
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
133134
if (!p->pack_local)
134135
continue;
135136
if (open_pack_index(p))

builtin/fast-import.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,11 +899,11 @@ static void end_packfile(void)
899899
idx_name = keep_pack(create_index());
900900

901901
/* Register the packfile with core git's machinery. */
902-
new_p = add_packed_git(pack_data->repo, idx_name, strlen(idx_name), 1);
902+
new_p = packfile_store_load_pack(pack_data->repo->objects->packfiles,
903+
idx_name, 1);
903904
if (!new_p)
904905
die("core git rejected index %s", idx_name);
905906
all_packs[pack_id] = new_p;
906-
install_packed_git(the_repository, new_p);
907907
free(idx_name);
908908

909909
/* Print the boundary */
@@ -954,6 +954,7 @@ static int store_object(
954954
struct object_id *oidout,
955955
uintmax_t mark)
956956
{
957+
struct packfile_store *packs = the_repository->objects->packfiles;
957958
void *out, *delta;
958959
struct object_entry *e;
959960
unsigned char hdr[96];
@@ -977,7 +978,7 @@ static int store_object(
977978
if (e->idx.offset) {
978979
duplicate_count_by_type[type]++;
979980
return 1;
980-
} else if (find_oid_pack(&oid, get_all_packs(the_repository))) {
981+
} else if (find_oid_pack(&oid, packfile_store_get_all_packs(packs))) {
981982
e->type = type;
982983
e->pack_id = MAX_PACK_ID;
983984
e->idx.offset = 1; /* just not zero! */
@@ -1094,6 +1095,7 @@ static void truncate_pack(struct hashfile_checkpoint *checkpoint)
10941095

10951096
static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
10961097
{
1098+
struct packfile_store *packs = the_repository->objects->packfiles;
10971099
size_t in_sz = 64 * 1024, out_sz = 64 * 1024;
10981100
unsigned char *in_buf = xmalloc(in_sz);
10991101
unsigned char *out_buf = xmalloc(out_sz);
@@ -1177,7 +1179,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
11771179
duplicate_count_by_type[OBJ_BLOB]++;
11781180
truncate_pack(&checkpoint);
11791181

1180-
} else if (find_oid_pack(&oid, get_all_packs(the_repository))) {
1182+
} else if (find_oid_pack(&oid, packfile_store_get_all_packs(packs))) {
11811183
e->type = OBJ_BLOB;
11821184
e->pack_id = MAX_PACK_ID;
11831185
e->idx.offset = 1; /* just not zero! */

builtin/fsck.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -867,19 +867,20 @@ static int mark_packed_for_connectivity(const struct object_id *oid,
867867

868868
static int check_pack_rev_indexes(struct repository *r, int show_progress)
869869
{
870+
struct packfile_store *packs = r->objects->packfiles;
870871
struct progress *progress = NULL;
871872
uint32_t pack_count = 0;
872873
int res = 0;
873874

874875
if (show_progress) {
875-
for (struct packed_git *p = get_all_packs(r); p; p = p->next)
876+
for (struct packed_git *p = packfile_store_get_all_packs(packs); p; p = p->next)
876877
pack_count++;
877878
progress = start_delayed_progress(the_repository,
878879
"Verifying reverse pack-indexes", pack_count);
879880
pack_count = 0;
880881
}
881882

882-
for (struct packed_git *p = get_all_packs(r); p; p = p->next) {
883+
for (struct packed_git *p = packfile_store_get_all_packs(packs); p; p = p->next) {
883884
int load_error = load_pack_revindex_from_disk(p);
884885

885886
if (load_error < 0) {
@@ -999,6 +1000,8 @@ int cmd_fsck(int argc,
9991000
for_each_packed_object(the_repository,
10001001
mark_packed_for_connectivity, NULL, 0);
10011002
} else {
1003+
struct packfile_store *packs = the_repository->objects->packfiles;
1004+
10021005
odb_prepare_alternates(the_repository->objects);
10031006
for (source = the_repository->objects->sources; source; source = source->next)
10041007
fsck_source(source);
@@ -1009,7 +1012,7 @@ int cmd_fsck(int argc,
10091012
struct progress *progress = NULL;
10101013

10111014
if (show_progress) {
1012-
for (p = get_all_packs(the_repository); p;
1015+
for (p = packfile_store_get_all_packs(packs); p;
10131016
p = p->next) {
10141017
if (open_pack_index(p))
10151018
continue;
@@ -1019,7 +1022,7 @@ int cmd_fsck(int argc,
10191022
progress = start_progress(the_repository,
10201023
_("Checking objects"), total);
10211024
}
1022-
for (p = get_all_packs(the_repository); p;
1025+
for (p = packfile_store_get_all_packs(packs); p;
10231026
p = p->next) {
10241027
/* verify gives error messages itself */
10251028
if (verify_pack(the_repository,

builtin/gc.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,10 @@ static int too_many_loose_objects(struct gc_config *cfg)
487487
static struct packed_git *find_base_packs(struct string_list *packs,
488488
unsigned long limit)
489489
{
490+
struct packfile_store *packfiles = the_repository->objects->packfiles;
490491
struct packed_git *p, *base = NULL;
491492

492-
for (p = get_all_packs(the_repository); p; p = p->next) {
493+
for (p = packfile_store_get_all_packs(packfiles); p; p = p->next) {
493494
if (!p->pack_local || p->is_cruft)
494495
continue;
495496
if (limit) {
@@ -508,13 +509,14 @@ static struct packed_git *find_base_packs(struct string_list *packs,
508509

509510
static int too_many_packs(struct gc_config *cfg)
510511
{
512+
struct packfile_store *packs = the_repository->objects->packfiles;
511513
struct packed_git *p;
512514
int cnt;
513515

514516
if (cfg->gc_auto_pack_limit <= 0)
515517
return 0;
516518

517-
for (cnt = 0, p = get_all_packs(the_repository); p; p = p->next) {
519+
for (cnt = 0, p = packfile_store_get_all_packs(packs); p; p = p->next) {
518520
if (!p->pack_local)
519521
continue;
520522
if (p->pack_keep)
@@ -1042,7 +1044,7 @@ int cmd_gc(int argc,
10421044
die(FAILED_RUN, "rerere");
10431045

10441046
report_garbage = report_pack_garbage;
1045-
reprepare_packed_git(the_repository);
1047+
odb_reprepare(the_repository->objects);
10461048
if (pack_garbage.nr > 0) {
10471049
close_object_store(the_repository->objects);
10481050
clean_pack_garbage();
@@ -1423,7 +1425,7 @@ static int incremental_repack_auto_condition(struct gc_config *cfg UNUSED)
14231425
if (incremental_repack_auto_limit < 0)
14241426
return 1;
14251427

1426-
for (p = get_packed_git(the_repository);
1428+
for (p = packfile_store_get_packs(the_repository->objects->packfiles);
14271429
count < incremental_repack_auto_limit && p;
14281430
p = p->next) {
14291431
if (!p->multi_pack_index)
@@ -1491,8 +1493,8 @@ static off_t get_auto_pack_size(void)
14911493
struct packed_git *p;
14921494
struct repository *r = the_repository;
14931495

1494-
reprepare_packed_git(r);
1495-
for (p = get_all_packs(r); p; p = p->next) {
1496+
odb_reprepare(r->objects);
1497+
for (p = packfile_store_get_all_packs(r->objects->packfiles); p; p = p->next) {
14961498
if (p->pack_size > max_size) {
14971499
second_largest_size = max_size;
14981500
max_size = p->pack_size;

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ int cmd_grep(int argc,
12141214
if (recurse_submodules)
12151215
repo_read_gitmodules(the_repository, 1);
12161216
if (startup_info->have_repository)
1217-
(void)get_packed_git(the_repository);
1217+
(void)packfile_store_get_packs(the_repository->objects->packfiles);
12181218

12191219
start_threads(&opt);
12201220
} else {

builtin/index-pack.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,13 +1640,9 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
16401640
rename_tmp_packfile(&final_index_name, curr_index_name, &index_name,
16411641
hash, "idx", 1);
16421642

1643-
if (do_fsck_object) {
1644-
struct packed_git *p;
1645-
p = add_packed_git(the_repository, final_index_name,
1646-
strlen(final_index_name), 0);
1647-
if (p)
1648-
install_packed_git(the_repository, p);
1649-
}
1643+
if (do_fsck_object)
1644+
packfile_store_load_pack(the_repository->objects->packfiles,
1645+
final_index_name, 0);
16501646

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

builtin/pack-objects.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,12 +1748,12 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17481748
}
17491749
}
17501750

1751-
list_for_each(pos, get_packed_git_mru(the_repository)) {
1751+
list_for_each(pos, packfile_store_get_packs_mru(the_repository->objects->packfiles)) {
17521752
struct packed_git *p = list_entry(pos, struct packed_git, mru);
17531753
want = want_object_in_pack_one(p, oid, exclude, found_pack, found_offset, found_mtime);
17541754
if (!exclude && want > 0)
17551755
list_move(&p->mru,
1756-
get_packed_git_mru(the_repository));
1756+
packfile_store_get_packs_mru(the_repository->objects->packfiles));
17571757
if (want != -1)
17581758
return want;
17591759
}
@@ -3831,6 +3831,7 @@ static int pack_mtime_cmp(const void *_a, const void *_b)
38313831

38323832
static void read_packs_list_from_stdin(struct rev_info *revs)
38333833
{
3834+
struct packfile_store *packs = the_repository->objects->packfiles;
38343835
struct strbuf buf = STRBUF_INIT;
38353836
struct string_list include_packs = STRING_LIST_INIT_DUP;
38363837
struct string_list exclude_packs = STRING_LIST_INIT_DUP;
@@ -3855,7 +3856,7 @@ static void read_packs_list_from_stdin(struct rev_info *revs)
38553856
string_list_sort(&exclude_packs);
38563857
string_list_remove_duplicates(&exclude_packs, 0);
38573858

3858-
for (p = get_all_packs(the_repository); p; p = p->next) {
3859+
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
38593860
const char *pack_name = pack_basename(p);
38603861

38613862
if ((item = string_list_lookup(&include_packs, pack_name)))
@@ -4076,6 +4077,7 @@ static void enumerate_cruft_objects(void)
40764077

40774078
static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs)
40784079
{
4080+
struct packfile_store *packs = the_repository->objects->packfiles;
40794081
struct packed_git *p;
40804082
struct rev_info revs;
40814083
int ret;
@@ -4105,7 +4107,7 @@ static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs
41054107
* Re-mark only the fresh packs as kept so that objects in
41064108
* unknown packs do not halt the reachability traversal early.
41074109
*/
4108-
for (p = get_all_packs(the_repository); p; p = p->next)
4110+
for (p = packfile_store_get_all_packs(packs); p; p = p->next)
41094111
p->pack_keep_in_core = 0;
41104112
mark_pack_kept_in_core(fresh_packs, 1);
41114113

@@ -4122,6 +4124,7 @@ static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs
41224124

41234125
static void read_cruft_objects(void)
41244126
{
4127+
struct packfile_store *packs = the_repository->objects->packfiles;
41254128
struct strbuf buf = STRBUF_INIT;
41264129
struct string_list discard_packs = STRING_LIST_INIT_DUP;
41274130
struct string_list fresh_packs = STRING_LIST_INIT_DUP;
@@ -4142,7 +4145,7 @@ static void read_cruft_objects(void)
41424145
string_list_sort(&discard_packs);
41434146
string_list_sort(&fresh_packs);
41444147

4145-
for (p = get_all_packs(the_repository); p; p = p->next) {
4148+
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
41464149
const char *pack_name = pack_basename(p);
41474150
struct string_list_item *item;
41484151

@@ -4390,11 +4393,12 @@ static void add_unreachable_loose_objects(struct rev_info *revs)
43904393

43914394
static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
43924395
{
4396+
struct packfile_store *packs = the_repository->objects->packfiles;
43934397
static struct packed_git *last_found = (void *)1;
43944398
struct packed_git *p;
43954399

43964400
p = (last_found != (void *)1) ? last_found :
4397-
get_all_packs(the_repository);
4401+
packfile_store_get_all_packs(packs);
43984402

43994403
while (p) {
44004404
if ((!p->pack_local || p->pack_keep ||
@@ -4404,7 +4408,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
44044408
return 1;
44054409
}
44064410
if (p == last_found)
4407-
p = get_all_packs(the_repository);
4411+
p = packfile_store_get_all_packs(packs);
44084412
else
44094413
p = p->next;
44104414
if (p == last_found)
@@ -4436,12 +4440,13 @@ static int loosened_object_can_be_discarded(const struct object_id *oid,
44364440

44374441
static void loosen_unused_packed_objects(void)
44384442
{
4443+
struct packfile_store *packs = the_repository->objects->packfiles;
44394444
struct packed_git *p;
44404445
uint32_t i;
44414446
uint32_t loosened_objects_nr = 0;
44424447
struct object_id oid;
44434448

4444-
for (p = get_all_packs(the_repository); p; p = p->next) {
4449+
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
44454450
if (!p->pack_local || p->pack_keep || p->pack_keep_in_core)
44464451
continue;
44474452

@@ -4742,12 +4747,13 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
47424747

47434748
static void add_extra_kept_packs(const struct string_list *names)
47444749
{
4750+
struct packfile_store *packs = the_repository->objects->packfiles;
47454751
struct packed_git *p;
47464752

47474753
if (!names->nr)
47484754
return;
47494755

4750-
for (p = get_all_packs(the_repository); p; p = p->next) {
4756+
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
47514757
const char *name = basename(p->pack_name);
47524758
int i;
47534759

@@ -5185,8 +5191,10 @@ int cmd_pack_objects(int argc,
51855191

51865192
add_extra_kept_packs(&keep_pack_list);
51875193
if (ignore_packed_keep_on_disk) {
5194+
struct packfile_store *packs = the_repository->objects->packfiles;
51885195
struct packed_git *p;
5189-
for (p = get_all_packs(the_repository); p; p = p->next)
5196+
5197+
for (p = packfile_store_get_all_packs(packs); p; p = p->next)
51905198
if (p->pack_local && p->pack_keep)
51915199
break;
51925200
if (!p) /* no keep-able packs found */
@@ -5198,8 +5206,10 @@ int cmd_pack_objects(int argc,
51985206
* want to unset "local" based on looking at packs, as
51995207
* it also covers non-local objects
52005208
*/
5209+
struct packfile_store *packs = the_repository->objects->packfiles;
52015210
struct packed_git *p;
5202-
for (p = get_all_packs(the_repository); p; p = p->next) {
5211+
5212+
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
52035213
if (!p->pack_local) {
52045214
have_non_local_packs = 1;
52055215
break;

builtin/pack-redundant.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ static struct pack_list * add_pack(struct packed_git *p)
566566

567567
static struct pack_list * add_pack_file(const char *filename)
568568
{
569-
struct packed_git *p = get_all_packs(the_repository);
569+
struct packfile_store *packs = the_repository->objects->packfiles;
570+
struct packed_git *p = packfile_store_get_all_packs(packs);
570571

571572
if (strlen(filename) < 40)
572573
die("Bad pack filename: %s", filename);
@@ -581,7 +582,8 @@ static struct pack_list * add_pack_file(const char *filename)
581582

582583
static void load_all(void)
583584
{
584-
struct packed_git *p = get_all_packs(the_repository);
585+
struct packfile_store *packs = the_repository->objects->packfiles;
586+
struct packed_git *p = packfile_store_get_all_packs(packs);
585587

586588
while (p) {
587589
add_pack(p);

0 commit comments

Comments
 (0)