Skip to content

Commit 5554738

Browse files
committed
Merge branch 'ps/remove-packfile-store-get-packs'
Two slightly different ways to get at "all the packfiles" in API has been cleaned up. * 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 c43d4cf + ecad863 commit 5554738

22 files changed

+60
-90
lines changed

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
@@ -867,20 +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;
871870
struct progress *progress = NULL;
871+
struct packed_git *p;
872872
uint32_t pack_count = 0;
873873
int res = 0;
874874

875875
if (show_progress) {
876-
for (struct packed_git *p = packfile_store_get_all_packs(packs); p; p = p->next)
876+
repo_for_each_pack(r, p)
877877
pack_count++;
878878
progress = start_delayed_progress(the_repository,
879879
"Verifying reverse pack-indexes", pack_count);
880880
pack_count = 0;
881881
}
882882

883-
for (struct packed_git *p = packfile_store_get_all_packs(packs); p; p = p->next) {
883+
repo_for_each_pack(r, p) {
884884
int load_error = load_pack_revindex_from_disk(p);
885885

886886
if (load_error < 0) {
@@ -1000,8 +1000,6 @@ int cmd_fsck(int argc,
10001000
for_each_packed_object(the_repository,
10011001
mark_packed_for_connectivity, NULL, 0);
10021002
} else {
1003-
struct packfile_store *packs = the_repository->objects->packfiles;
1004-
10051003
odb_prepare_alternates(the_repository->objects);
10061004
for (source = the_repository->objects->sources; source; source = source->next)
10071005
fsck_source(source);
@@ -1012,8 +1010,7 @@ int cmd_fsck(int argc,
10121010
struct progress *progress = NULL;
10131011

10141012
if (show_progress) {
1015-
for (p = packfile_store_get_all_packs(packs); p;
1016-
p = p->next) {
1013+
repo_for_each_pack(the_repository, p) {
10171014
if (open_pack_index(p))
10181015
continue;
10191016
total += p->num_objects;
@@ -1022,8 +1019,8 @@ int cmd_fsck(int argc,
10221019
progress = start_progress(the_repository,
10231020
_("Checking objects"), total);
10241021
}
1025-
for (p = packfile_store_get_all_packs(packs); p;
1026-
p = p->next) {
1022+
1023+
repo_for_each_pack(the_repository, p) {
10271024
/* verify gives error messages itself */
10281025
if (verify_pack(the_repository,
10291026
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)
@@ -1425,9 +1423,9 @@ static int incremental_repack_auto_condition(struct gc_config *cfg UNUSED)
14251423
if (incremental_repack_auto_limit < 0)
14261424
return 1;
14271425

1428-
for (p = packfile_store_get_packs(the_repository->objects->packfiles);
1429-
count < incremental_repack_auto_limit && p;
1430-
p = p->next) {
1426+
repo_for_each_pack(the_repository, p) {
1427+
if (count >= incremental_repack_auto_limit)
1428+
break;
14311429
if (!p->multi_pack_index)
14321430
count++;
14331431
}
@@ -1494,7 +1492,7 @@ static off_t get_auto_pack_size(void)
14941492
struct repository *r = the_repository;
14951493

14961494
odb_reprepare(r->objects);
1497-
for (p = packfile_store_get_all_packs(r->objects->packfiles); p; p = p->next) {
1495+
repo_for_each_pack(r, p) {
14981496
if (p->pack_size > max_size) {
14991497
second_largest_size = max_size;
15001498
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
@@ -3831,12 +3831,10 @@ 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;
38353834
struct strbuf buf = STRBUF_INIT;
38363835
struct string_list include_packs = STRING_LIST_INIT_DUP;
38373836
struct string_list exclude_packs = STRING_LIST_INIT_DUP;
38383837
struct string_list_item *item = NULL;
3839-
38403838
struct packed_git *p;
38413839

38423840
while (strbuf_getline(&buf, stdin) != EOF) {
@@ -3856,7 +3854,7 @@ static void read_packs_list_from_stdin(struct rev_info *revs)
38563854
string_list_sort(&exclude_packs);
38573855
string_list_remove_duplicates(&exclude_packs, 0);
38583856

3859-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
3857+
repo_for_each_pack(the_repository, p) {
38603858
const char *pack_name = pack_basename(p);
38613859

38623860
if ((item = string_list_lookup(&include_packs, pack_name)))
@@ -4077,7 +4075,6 @@ static void enumerate_cruft_objects(void)
40774075

40784076
static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs)
40794077
{
4080-
struct packfile_store *packs = the_repository->objects->packfiles;
40814078
struct packed_git *p;
40824079
struct rev_info revs;
40834080
int ret;
@@ -4107,7 +4104,7 @@ static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs
41074104
* Re-mark only the fresh packs as kept so that objects in
41084105
* unknown packs do not halt the reachability traversal early.
41094106
*/
4110-
for (p = packfile_store_get_all_packs(packs); p; p = p->next)
4107+
repo_for_each_pack(the_repository, p)
41114108
p->pack_keep_in_core = 0;
41124109
mark_pack_kept_in_core(fresh_packs, 1);
41134110

@@ -4124,7 +4121,6 @@ static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs
41244121

41254122
static void read_cruft_objects(void)
41264123
{
4127-
struct packfile_store *packs = the_repository->objects->packfiles;
41284124
struct strbuf buf = STRBUF_INIT;
41294125
struct string_list discard_packs = STRING_LIST_INIT_DUP;
41304126
struct string_list fresh_packs = STRING_LIST_INIT_DUP;
@@ -4145,7 +4141,7 @@ static void read_cruft_objects(void)
41454141
string_list_sort(&discard_packs);
41464142
string_list_sort(&fresh_packs);
41474143

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

@@ -4398,7 +4394,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
43984394
struct packed_git *p;
43994395

44004396
p = (last_found != (void *)1) ? last_found :
4401-
packfile_store_get_all_packs(packs);
4397+
packfile_store_get_packs(packs);
44024398

44034399
while (p) {
44044400
if ((!p->pack_local || p->pack_keep ||
@@ -4408,7 +4404,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
44084404
return 1;
44094405
}
44104406
if (p == last_found)
4411-
p = packfile_store_get_all_packs(packs);
4407+
p = packfile_store_get_packs(packs);
44124408
else
44134409
p = p->next;
44144410
if (p == last_found)
@@ -4440,13 +4436,12 @@ static int loosened_object_can_be_discarded(const struct object_id *oid,
44404436

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

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

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

47484743
static void add_extra_kept_packs(const struct string_list *names)
47494744
{
4750-
struct packfile_store *packs = the_repository->objects->packfiles;
47514745
struct packed_git *p;
47524746

47534747
if (!names->nr)
47544748
return;
47554749

4756-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
4750+
repo_for_each_pack(the_repository, p) {
47574751
const char *name = basename(p->pack_name);
47584752
int i;
47594753

@@ -5191,10 +5185,9 @@ int cmd_pack_objects(int argc,
51915185

51925186
add_extra_kept_packs(&keep_pack_list);
51935187
if (ignore_packed_keep_on_disk) {
5194-
struct packfile_store *packs = the_repository->objects->packfiles;
51955188
struct packed_git *p;
51965189

5197-
for (p = packfile_store_get_all_packs(packs); p; p = p->next)
5190+
repo_for_each_pack(the_repository, p)
51985191
if (p->pack_local && p->pack_keep)
51995192
break;
52005193
if (!p) /* no keep-able packs found */
@@ -5206,10 +5199,9 @@ int cmd_pack_objects(int argc,
52065199
* want to unset "local" based on looking at packs, as
52075200
* it also covers non-local objects
52085201
*/
5209-
struct packfile_store *packs = the_repository->objects->packfiles;
52105202
struct packed_git *p;
52115203

5212-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
5204+
repo_for_each_pack(the_repository, p) {
52135205
if (!p->pack_local) {
52145206
have_non_local_packs = 1;
52155207
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
@@ -603,19 +603,18 @@ 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;
607606
struct strbuf buf = STRBUF_INIT;
608607
struct packed_git *p;
609608
size_t cnt = 0;
610609

611610
select_getanyfile(hdr);
612-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
611+
repo_for_each_pack(the_repository, p) {
613612
if (p->pack_local)
614613
cnt++;
615614
}
616615

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

0 commit comments

Comments
 (0)