Skip to content

Commit d2779be

Browse files
pks-tgitster
authored andcommitted
packfile: refactor get_all_packs() to work on packfile store
The `get_all_packs()` function prepares the packfile store and then returns its packfiles. Refactor it to accept a packfile store instead of a repository to clarify its scope. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 751808b commit d2779be

18 files changed

+76
-42
lines changed

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ static int store_object(
952952
struct object_id *oidout,
953953
uintmax_t mark)
954954
{
955+
struct packfile_store *packs = the_repository->objects->packfiles;
955956
void *out, *delta;
956957
struct object_entry *e;
957958
unsigned char hdr[96];
@@ -975,7 +976,7 @@ static int store_object(
975976
if (e->idx.offset) {
976977
duplicate_count_by_type[type]++;
977978
return 1;
978-
} else if (find_oid_pack(&oid, get_all_packs(the_repository))) {
979+
} else if (find_oid_pack(&oid, packfile_store_get_all_packs(packs))) {
979980
e->type = type;
980981
e->pack_id = MAX_PACK_ID;
981982
e->idx.offset = 1; /* just not zero! */
@@ -1092,6 +1093,7 @@ static void truncate_pack(struct hashfile_checkpoint *checkpoint)
10921093

10931094
static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
10941095
{
1096+
struct packfile_store *packs = the_repository->objects->packfiles;
10951097
size_t in_sz = 64 * 1024, out_sz = 64 * 1024;
10961098
unsigned char *in_buf = xmalloc(in_sz);
10971099
unsigned char *out_buf = xmalloc(out_sz);
@@ -1175,7 +1177,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
11751177
duplicate_count_by_type[OBJ_BLOB]++;
11761178
truncate_pack(&checkpoint);
11771179

1178-
} else if (find_oid_pack(&oid, get_all_packs(the_repository))) {
1180+
} else if (find_oid_pack(&oid, packfile_store_get_all_packs(packs))) {
11791181
e->type = OBJ_BLOB;
11801182
e->pack_id = MAX_PACK_ID;
11811183
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: 5 additions & 3 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)
@@ -1492,7 +1494,7 @@ static off_t get_auto_pack_size(void)
14921494
struct repository *r = the_repository;
14931495

14941496
odb_reprepare(r->objects);
1495-
for (p = get_all_packs(r); p; p = p->next) {
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/pack-objects.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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, int ac, const char **av)
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);

builtin/repack.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,11 @@ static void existing_packs_release(struct existing_packs *existing)
265265
static void collect_pack_filenames(struct existing_packs *existing,
266266
const struct string_list *extra_keep)
267267
{
268+
struct packfile_store *packs = the_repository->objects->packfiles;
268269
struct packed_git *p;
269270
struct strbuf buf = STRBUF_INIT;
270271

271-
for (p = get_all_packs(the_repository); p; p = p->next) {
272+
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
272273
int i;
273274
const char *base;
274275

@@ -497,10 +498,11 @@ static void init_pack_geometry(struct pack_geometry *geometry,
497498
struct existing_packs *existing,
498499
const struct pack_objects_args *args)
499500
{
501+
struct packfile_store *packs = the_repository->objects->packfiles;
500502
struct packed_git *p;
501503
struct strbuf buf = STRBUF_INIT;
502504

503-
for (p = get_all_packs(the_repository); p; p = p->next) {
505+
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
504506
if (args->local && !p->pack_local)
505507
/*
506508
* When asked to only repack local packfiles we skip
@@ -1137,11 +1139,12 @@ static int write_filtered_pack(const struct pack_objects_args *args,
11371139
static void combine_small_cruft_packs(FILE *in, size_t combine_cruft_below_size,
11381140
struct existing_packs *existing)
11391141
{
1142+
struct packfile_store *packs = the_repository->objects->packfiles;
11401143
struct packed_git *p;
11411144
struct strbuf buf = STRBUF_INIT;
11421145
size_t i;
11431146

1144-
for (p = get_all_packs(the_repository); p; p = p->next) {
1147+
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
11451148
if (!(p->is_cruft && p->pack_local))
11461149
continue;
11471150

connected.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
7474
*/
7575
odb_reprepare(the_repository->objects);
7676
do {
77+
struct packfile_store *packs = the_repository->objects->packfiles;
7778
struct packed_git *p;
7879

79-
for (p = get_all_packs(the_repository); p; p = p->next) {
80+
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
8081
if (!p->pack_promisor)
8182
continue;
8283
if (find_pack_entry_one(oid, p))

http-backend.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,18 +603,19 @@ static void get_head(struct strbuf *hdr, char *arg UNUSED)
603603
static void get_info_packs(struct strbuf *hdr, char *arg UNUSED)
604604
{
605605
size_t objdirlen = strlen(repo_get_object_directory(the_repository));
606+
struct packfile_store *packs = the_repository->objects->packfiles;
606607
struct strbuf buf = STRBUF_INIT;
607608
struct packed_git *p;
608609
size_t cnt = 0;
609610

610611
select_getanyfile(hdr);
611-
for (p = get_all_packs(the_repository); p; p = p->next) {
612+
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
612613
if (p->pack_local)
613614
cnt++;
614615
}
615616

616617
strbuf_grow(&buf, cnt * 53 + 2);
617-
for (p = get_all_packs(the_repository); p; p = p->next) {
618+
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
618619
if (p->pack_local)
619620
strbuf_addf(&buf, "P %s\n", p->pack_name + objdirlen + 6);
620621
}

0 commit comments

Comments
 (0)