Skip to content

Commit 84e408e

Browse files
committed
Merge branch 'ps/remove-packfile-store-get-packs' into seen
Two slightly different ways to get at "all the packfiles" in API has been cleaned up. Comments? * ps/remove-packfile-store-get-packs: packfile: rename `packfile_store_get_all_packs()` packfile: introduce macro to iterate through packs packfile: drop `packfile_store_get_packs()` builtin/grep: simplify how we preload packs builtin/gc: convert to use `packfile_store_get_all_packs()` object-name: convert to use `packfile_store_get_all_packs()`
2 parents 1c3a7de + b009b55 commit 84e408e

22 files changed

Lines changed: 60 additions & 90 deletions

builtin/cat-file.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,9 @@ 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;
856855
struct packed_git *pack;
857856

858-
for (pack = packfile_store_get_all_packs(packs); pack; pack = pack->next) {
857+
repo_for_each_pack(the_repository, pack) {
859858
if (bitmap_index_contains_pack(bitmap, pack) ||
860859
open_pack_index(pack))
861860
continue;

builtin/count-objects.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,14 @@ 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;
126125
struct packed_git *p;
127126
unsigned long num_pack = 0;
128127
off_t size_pack = 0;
129128
struct strbuf loose_buf = STRBUF_INIT;
130129
struct strbuf pack_buf = STRBUF_INIT;
131130
struct strbuf garbage_buf = STRBUF_INIT;
132131

133-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
132+
repo_for_each_pack(the_repository, p) {
134133
if (!p->pack_local)
135134
continue;
136135
if (open_pack_index(p))

builtin/fast-import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ static int store_object(
979979
if (e->idx.offset) {
980980
duplicate_count_by_type[type]++;
981981
return 1;
982-
} else if (find_oid_pack(&oid, packfile_store_get_all_packs(packs))) {
982+
} else if (find_oid_pack(&oid, packfile_store_get_packs(packs))) {
983983
e->type = type;
984984
e->pack_id = MAX_PACK_ID;
985985
e->idx.offset = 1; /* just not zero! */
@@ -1180,7 +1180,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
11801180
duplicate_count_by_type[OBJ_BLOB]++;
11811181
truncate_pack(&checkpoint);
11821182

1183-
} else if (find_oid_pack(&oid, packfile_store_get_all_packs(packs))) {
1183+
} else if (find_oid_pack(&oid, packfile_store_get_packs(packs))) {
11841184
e->type = OBJ_BLOB;
11851185
e->pack_id = MAX_PACK_ID;
11861186
e->idx.offset = 1; /* just not zero! */

builtin/fsck.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -872,20 +872,20 @@ static int mark_packed_for_connectivity(const struct object_id *oid,
872872

873873
static int check_pack_rev_indexes(struct repository *r, int show_progress)
874874
{
875-
struct packfile_store *packs = r->objects->packfiles;
876875
struct progress *progress = NULL;
876+
struct packed_git *p;
877877
uint32_t pack_count = 0;
878878
int res = 0;
879879

880880
if (show_progress) {
881-
for (struct packed_git *p = packfile_store_get_all_packs(packs); p; p = p->next)
881+
repo_for_each_pack(r, p)
882882
pack_count++;
883883
progress = start_delayed_progress(the_repository,
884884
"Verifying reverse pack-indexes", pack_count);
885885
pack_count = 0;
886886
}
887887

888-
for (struct packed_git *p = packfile_store_get_all_packs(packs); p; p = p->next) {
888+
repo_for_each_pack(r, p) {
889889
int load_error = load_pack_revindex_from_disk(p);
890890

891891
if (load_error < 0) {
@@ -1005,8 +1005,6 @@ int cmd_fsck(int argc,
10051005
for_each_packed_object(the_repository,
10061006
mark_packed_for_connectivity, NULL, 0);
10071007
} else {
1008-
struct packfile_store *packs = the_repository->objects->packfiles;
1009-
10101008
odb_prepare_alternates(the_repository->objects);
10111009
for (source = the_repository->objects->sources; source; source = source->next)
10121010
fsck_source(source);
@@ -1017,8 +1015,7 @@ int cmd_fsck(int argc,
10171015
struct progress *progress = NULL;
10181016

10191017
if (show_progress) {
1020-
for (p = packfile_store_get_all_packs(packs); p;
1021-
p = p->next) {
1018+
repo_for_each_pack(the_repository, p) {
10221019
if (open_pack_index(p))
10231020
continue;
10241021
total += p->num_objects;
@@ -1027,8 +1024,8 @@ int cmd_fsck(int argc,
10271024
progress = start_progress(the_repository,
10281025
_("Checking objects"), total);
10291026
}
1030-
for (p = packfile_store_get_all_packs(packs); p;
1031-
p = p->next) {
1027+
1028+
repo_for_each_pack(the_repository, p) {
10321029
/* verify gives error messages itself */
10331030
if (verify_pack(the_repository,
10341031
p, fsck_obj_buffer,

builtin/gc.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,9 @@ 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;
491490
struct packed_git *p, *base = NULL;
492491

493-
for (p = packfile_store_get_all_packs(packfiles); p; p = p->next) {
492+
repo_for_each_pack(the_repository, p) {
494493
if (!p->pack_local || p->is_cruft)
495494
continue;
496495
if (limit) {
@@ -509,14 +508,13 @@ static struct packed_git *find_base_packs(struct string_list *packs,
509508

510509
static int too_many_packs(struct gc_config *cfg)
511510
{
512-
struct packfile_store *packs = the_repository->objects->packfiles;
513511
struct packed_git *p;
514-
int cnt;
512+
int cnt = 0;
515513

516514
if (cfg->gc_auto_pack_limit <= 0)
517515
return 0;
518516

519-
for (cnt = 0, p = packfile_store_get_all_packs(packs); p; p = p->next) {
517+
repo_for_each_pack(the_repository, p) {
520518
if (!p->pack_local)
521519
continue;
522520
if (p->pack_keep)
@@ -1422,9 +1420,9 @@ static int incremental_repack_auto_condition(struct gc_config *cfg UNUSED)
14221420
if (incremental_repack_auto_limit < 0)
14231421
return 1;
14241422

1425-
for (p = packfile_store_get_packs(the_repository->objects->packfiles);
1426-
count < incremental_repack_auto_limit && p;
1427-
p = p->next) {
1423+
repo_for_each_pack(the_repository, p) {
1424+
if (count >= incremental_repack_auto_limit)
1425+
break;
14281426
if (!p->multi_pack_index)
14291427
count++;
14301428
}
@@ -1491,7 +1489,7 @@ static off_t get_auto_pack_size(void)
14911489
struct repository *r = the_repository;
14921490

14931491
odb_reprepare(r->objects);
1494-
for (p = packfile_store_get_all_packs(r->objects->packfiles); p; p = p->next) {
1492+
repo_for_each_pack(r, p) {
14951493
if (p->pack_size > max_size) {
14961494
second_largest_size = max_size;
14971495
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)packfile_store_get_packs(the_repository->objects->packfiles);
1217+
packfile_store_prepare(the_repository->objects->packfiles);
12181218

12191219
start_threads(&opt);
12201220
} else {

builtin/pack-objects.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3830,12 +3830,10 @@ static int pack_mtime_cmp(const void *_a, const void *_b)
38303830

38313831
static void read_packs_list_from_stdin(struct rev_info *revs)
38323832
{
3833-
struct packfile_store *packs = the_repository->objects->packfiles;
38343833
struct strbuf buf = STRBUF_INIT;
38353834
struct string_list include_packs = STRING_LIST_INIT_DUP;
38363835
struct string_list exclude_packs = STRING_LIST_INIT_DUP;
38373836
struct string_list_item *item = NULL;
3838-
38393837
struct packed_git *p;
38403838

38413839
while (strbuf_getline(&buf, stdin) != EOF) {
@@ -3855,7 +3853,7 @@ static void read_packs_list_from_stdin(struct rev_info *revs)
38553853
string_list_sort(&exclude_packs);
38563854
string_list_remove_duplicates(&exclude_packs, 0);
38573855

3858-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
3856+
repo_for_each_pack(the_repository, p) {
38593857
const char *pack_name = pack_basename(p);
38603858

38613859
if ((item = string_list_lookup(&include_packs, pack_name)))
@@ -4076,7 +4074,6 @@ static void enumerate_cruft_objects(void)
40764074

40774075
static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs)
40784076
{
4079-
struct packfile_store *packs = the_repository->objects->packfiles;
40804077
struct packed_git *p;
40814078
struct rev_info revs;
40824079
int ret;
@@ -4106,7 +4103,7 @@ static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs
41064103
* Re-mark only the fresh packs as kept so that objects in
41074104
* unknown packs do not halt the reachability traversal early.
41084105
*/
4109-
for (p = packfile_store_get_all_packs(packs); p; p = p->next)
4106+
repo_for_each_pack(the_repository, p)
41104107
p->pack_keep_in_core = 0;
41114108
mark_pack_kept_in_core(fresh_packs, 1);
41124109

@@ -4123,7 +4120,6 @@ static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs
41234120

41244121
static void read_cruft_objects(void)
41254122
{
4126-
struct packfile_store *packs = the_repository->objects->packfiles;
41274123
struct strbuf buf = STRBUF_INIT;
41284124
struct string_list discard_packs = STRING_LIST_INIT_DUP;
41294125
struct string_list fresh_packs = STRING_LIST_INIT_DUP;
@@ -4144,7 +4140,7 @@ static void read_cruft_objects(void)
41444140
string_list_sort(&discard_packs);
41454141
string_list_sort(&fresh_packs);
41464142

4147-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
4143+
repo_for_each_pack(the_repository, p) {
41484144
const char *pack_name = pack_basename(p);
41494145
struct string_list_item *item;
41504146

@@ -4397,7 +4393,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
43974393
struct packed_git *p;
43984394

43994395
p = (last_found != (void *)1) ? last_found :
4400-
packfile_store_get_all_packs(packs);
4396+
packfile_store_get_packs(packs);
44014397

44024398
while (p) {
44034399
if ((!p->pack_local || p->pack_keep ||
@@ -4407,7 +4403,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
44074403
return 1;
44084404
}
44094405
if (p == last_found)
4410-
p = packfile_store_get_all_packs(packs);
4406+
p = packfile_store_get_packs(packs);
44114407
else
44124408
p = p->next;
44134409
if (p == last_found)
@@ -4439,13 +4435,12 @@ static int loosened_object_can_be_discarded(const struct object_id *oid,
44394435

44404436
static void loosen_unused_packed_objects(void)
44414437
{
4442-
struct packfile_store *packs = the_repository->objects->packfiles;
44434438
struct packed_git *p;
44444439
uint32_t i;
44454440
uint32_t loosened_objects_nr = 0;
44464441
struct object_id oid;
44474442

4448-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
4443+
repo_for_each_pack(the_repository, p) {
44494444
if (!p->pack_local || p->pack_keep || p->pack_keep_in_core)
44504445
continue;
44514446

@@ -4743,13 +4738,12 @@ static void get_object_list(struct rev_info *revs, struct strvec *argv)
47434738

47444739
static void add_extra_kept_packs(const struct string_list *names)
47454740
{
4746-
struct packfile_store *packs = the_repository->objects->packfiles;
47474741
struct packed_git *p;
47484742

47494743
if (!names->nr)
47504744
return;
47514745

4752-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
4746+
repo_for_each_pack(the_repository, p) {
47534747
const char *name = basename(p->pack_name);
47544748
int i;
47554749

@@ -5187,10 +5181,9 @@ int cmd_pack_objects(int argc,
51875181

51885182
add_extra_kept_packs(&keep_pack_list);
51895183
if (ignore_packed_keep_on_disk) {
5190-
struct packfile_store *packs = the_repository->objects->packfiles;
51915184
struct packed_git *p;
51925185

5193-
for (p = packfile_store_get_all_packs(packs); p; p = p->next)
5186+
repo_for_each_pack(the_repository, p)
51945187
if (p->pack_local && p->pack_keep)
51955188
break;
51965189
if (!p) /* no keep-able packs found */
@@ -5202,10 +5195,9 @@ int cmd_pack_objects(int argc,
52025195
* want to unset "local" based on looking at packs, as
52035196
* it also covers non-local objects
52045197
*/
5205-
struct packfile_store *packs = the_repository->objects->packfiles;
52065198
struct packed_git *p;
52075199

5208-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
5200+
repo_for_each_pack(the_repository, p) {
52095201
if (!p->pack_local) {
52105202
have_non_local_packs = 1;
52115203
break;

builtin/pack-redundant.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -566,29 +566,23 @@ 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 packfile_store *packs = the_repository->objects->packfiles;
570-
struct packed_git *p = packfile_store_get_all_packs(packs);
569+
struct packed_git *p;
571570

572571
if (strlen(filename) < 40)
573572
die("Bad pack filename: %s", filename);
574573

575-
while (p) {
574+
repo_for_each_pack(the_repository, p)
576575
if (strstr(p->pack_name, filename))
577576
return add_pack(p);
578-
p = p->next;
579-
}
580577
die("Filename %s not found in packed_git", filename);
581578
}
582579

583580
static void load_all(void)
584581
{
585-
struct packfile_store *packs = the_repository->objects->packfiles;
586-
struct packed_git *p = packfile_store_get_all_packs(packs);
582+
struct packed_git *p;
587583

588-
while (p) {
584+
repo_for_each_pack(the_repository, p)
589585
add_pack(p);
590-
p = p->next;
591-
}
592586
}
593587

594588
int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) {

connected.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ 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;
7877
struct packed_git *p;
7978

80-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
79+
repo_for_each_pack(the_repository, p) {
8180
if (!p->pack_promisor)
8281
continue;
8382
if (find_pack_entry_one(oid, p))

http-backend.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,19 +601,18 @@ static void get_head(struct strbuf *hdr, char *arg UNUSED)
601601
static void get_info_packs(struct strbuf *hdr, char *arg UNUSED)
602602
{
603603
size_t objdirlen = strlen(repo_get_object_directory(the_repository));
604-
struct packfile_store *packs = the_repository->objects->packfiles;
605604
struct strbuf buf = STRBUF_INIT;
606605
struct packed_git *p;
607606
size_t cnt = 0;
608607

609608
select_getanyfile(hdr);
610-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
609+
repo_for_each_pack(the_repository, p) {
611610
if (p->pack_local)
612611
cnt++;
613612
}
614613

615614
strbuf_grow(&buf, cnt * 53 + 2);
616-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
615+
repo_for_each_pack(the_repository, p) {
617616
if (p->pack_local)
618617
strbuf_addf(&buf, "P %s\n", p->pack_name + objdirlen + 6);
619618
}

0 commit comments

Comments
 (0)