Skip to content

Commit 0e07103

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 be08c5e + 0c49455 commit 0e07103

22 files changed

+58
-65
lines changed

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ static void batch_each_object(struct batch_options *opt,
855855
struct packfile_store *packs = the_repository->objects->packfiles;
856856
struct packed_git *pack;
857857

858-
for (pack = packfile_store_get_all_packs(packs); pack; pack = pack->next) {
858+
packfile_store_for_each_pack(packs, pack) {
859859
if (bitmap_index_contains_pack(bitmap, pack) ||
860860
open_pack_index(pack))
861861
continue;

builtin/count-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int cmd_count_objects(int argc,
130130
struct strbuf pack_buf = STRBUF_INIT;
131131
struct strbuf garbage_buf = STRBUF_INIT;
132132

133-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
133+
packfile_store_for_each_pack(packs, p) {
134134
if (!p->pack_local)
135135
continue;
136136
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -874,18 +874,19 @@ static int check_pack_rev_indexes(struct repository *r, int show_progress)
874874
{
875875
struct packfile_store *packs = r->objects->packfiles;
876876
struct progress *progress = NULL;
877+
struct packed_git *p;
877878
uint32_t pack_count = 0;
878879
int res = 0;
879880

880881
if (show_progress) {
881-
for (struct packed_git *p = packfile_store_get_all_packs(packs); p; p = p->next)
882+
packfile_store_for_each_pack(packs, p)
882883
pack_count++;
883884
progress = start_delayed_progress(the_repository,
884885
"Verifying reverse pack-indexes", pack_count);
885886
pack_count = 0;
886887
}
887888

888-
for (struct packed_git *p = packfile_store_get_all_packs(packs); p; p = p->next) {
889+
packfile_store_for_each_pack(packs, p) {
889890
int load_error = load_pack_revindex_from_disk(p);
890891

891892
if (load_error < 0) {
@@ -1017,8 +1018,7 @@ int cmd_fsck(int argc,
10171018
struct progress *progress = NULL;
10181019

10191020
if (show_progress) {
1020-
for (p = packfile_store_get_all_packs(packs); p;
1021-
p = p->next) {
1021+
packfile_store_for_each_pack(packs, p) {
10221022
if (open_pack_index(p))
10231023
continue;
10241024
total += p->num_objects;
@@ -1027,8 +1027,8 @@ int cmd_fsck(int argc,
10271027
progress = start_progress(the_repository,
10281028
_("Checking objects"), total);
10291029
}
1030-
for (p = packfile_store_get_all_packs(packs); p;
1031-
p = p->next) {
1030+
1031+
packfile_store_for_each_pack(packs, p) {
10321032
/* verify gives error messages itself */
10331033
if (verify_pack(the_repository,
10341034
p, fsck_obj_buffer,

builtin/gc.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ static struct packed_git *find_base_packs(struct string_list *packs,
490490
struct packfile_store *packfiles = the_repository->objects->packfiles;
491491
struct packed_git *p, *base = NULL;
492492

493-
for (p = packfile_store_get_all_packs(packfiles); p; p = p->next) {
493+
packfile_store_for_each_pack(packfiles, p) {
494494
if (!p->pack_local || p->is_cruft)
495495
continue;
496496
if (limit) {
@@ -511,12 +511,12 @@ static int too_many_packs(struct gc_config *cfg)
511511
{
512512
struct packfile_store *packs = the_repository->objects->packfiles;
513513
struct packed_git *p;
514-
int cnt;
514+
int cnt = 0;
515515

516516
if (cfg->gc_auto_pack_limit <= 0)
517517
return 0;
518518

519-
for (cnt = 0, p = packfile_store_get_all_packs(packs); p; p = p->next) {
519+
packfile_store_for_each_pack(packs, p) {
520520
if (!p->pack_local)
521521
continue;
522522
if (p->pack_keep)
@@ -1422,9 +1422,9 @@ static int incremental_repack_auto_condition(struct gc_config *cfg UNUSED)
14221422
if (incremental_repack_auto_limit < 0)
14231423
return 1;
14241424

1425-
for (p = packfile_store_get_packs(the_repository->objects->packfiles);
1426-
count < incremental_repack_auto_limit && p;
1427-
p = p->next) {
1425+
packfile_store_for_each_pack(the_repository->objects->packfiles, p) {
1426+
if (count >= incremental_repack_auto_limit)
1427+
break;
14281428
if (!p->multi_pack_index)
14291429
count++;
14301430
}
@@ -1491,7 +1491,7 @@ static off_t get_auto_pack_size(void)
14911491
struct repository *r = the_repository;
14921492

14931493
odb_reprepare(r->objects);
1494-
for (p = packfile_store_get_all_packs(r->objects->packfiles); p; p = p->next) {
1494+
packfile_store_for_each_pack(r->objects->packfiles, p) {
14951495
if (p->pack_size > max_size) {
14961496
second_largest_size = max_size;
14971497
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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,7 +3855,7 @@ static void read_packs_list_from_stdin(struct rev_info *revs)
38553855
string_list_sort(&exclude_packs);
38563856
string_list_remove_duplicates(&exclude_packs, 0);
38573857

3858-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
3858+
packfile_store_for_each_pack(packs, p) {
38593859
const char *pack_name = pack_basename(p);
38603860

38613861
if ((item = string_list_lookup(&include_packs, pack_name)))
@@ -4106,7 +4106,7 @@ static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs
41064106
* Re-mark only the fresh packs as kept so that objects in
41074107
* unknown packs do not halt the reachability traversal early.
41084108
*/
4109-
for (p = packfile_store_get_all_packs(packs); p; p = p->next)
4109+
packfile_store_for_each_pack(packs, p)
41104110
p->pack_keep_in_core = 0;
41114111
mark_pack_kept_in_core(fresh_packs, 1);
41124112

@@ -4144,7 +4144,7 @@ static void read_cruft_objects(void)
41444144
string_list_sort(&discard_packs);
41454145
string_list_sort(&fresh_packs);
41464146

4147-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
4147+
packfile_store_for_each_pack(packs, p) {
41484148
const char *pack_name = pack_basename(p);
41494149
struct string_list_item *item;
41504150

@@ -4397,7 +4397,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
43974397
struct packed_git *p;
43984398

43994399
p = (last_found != (void *)1) ? last_found :
4400-
packfile_store_get_all_packs(packs);
4400+
packfile_store_get_packs(packs);
44014401

44024402
while (p) {
44034403
if ((!p->pack_local || p->pack_keep ||
@@ -4407,7 +4407,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
44074407
return 1;
44084408
}
44094409
if (p == last_found)
4410-
p = packfile_store_get_all_packs(packs);
4410+
p = packfile_store_get_packs(packs);
44114411
else
44124412
p = p->next;
44134413
if (p == last_found)
@@ -4445,7 +4445,7 @@ static void loosen_unused_packed_objects(void)
44454445
uint32_t loosened_objects_nr = 0;
44464446
struct object_id oid;
44474447

4448-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
4448+
packfile_store_for_each_pack(packs, p) {
44494449
if (!p->pack_local || p->pack_keep || p->pack_keep_in_core)
44504450
continue;
44514451

@@ -4749,7 +4749,7 @@ static void add_extra_kept_packs(const struct string_list *names)
47494749
if (!names->nr)
47504750
return;
47514751

4752-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
4752+
packfile_store_for_each_pack(packs, p) {
47534753
const char *name = basename(p->pack_name);
47544754
int i;
47554755

@@ -5190,7 +5190,7 @@ int cmd_pack_objects(int argc,
51905190
struct packfile_store *packs = the_repository->objects->packfiles;
51915191
struct packed_git *p;
51925192

5193-
for (p = packfile_store_get_all_packs(packs); p; p = p->next)
5193+
packfile_store_for_each_pack(packs, p)
51945194
if (p->pack_local && p->pack_keep)
51955195
break;
51965196
if (!p) /* no keep-able packs found */
@@ -5205,7 +5205,7 @@ int cmd_pack_objects(int argc,
52055205
struct packfile_store *packs = the_repository->objects->packfiles;
52065206
struct packed_git *p;
52075207

5208-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
5208+
packfile_store_for_each_pack(packs, p) {
52095209
if (!p->pack_local) {
52105210
have_non_local_packs = 1;
52115211
break;

builtin/pack-redundant.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -567,28 +567,24 @@ static struct pack_list * add_pack(struct packed_git *p)
567567
static struct pack_list * add_pack_file(const char *filename)
568568
{
569569
struct packfile_store *packs = the_repository->objects->packfiles;
570-
struct packed_git *p = packfile_store_get_all_packs(packs);
570+
struct packed_git *p;
571571

572572
if (strlen(filename) < 40)
573573
die("Bad pack filename: %s", filename);
574574

575-
while (p) {
575+
packfile_store_for_each_pack(packs, p)
576576
if (strstr(p->pack_name, filename))
577577
return add_pack(p);
578-
p = p->next;
579-
}
580578
die("Filename %s not found in packed_git", filename);
581579
}
582580

583581
static void load_all(void)
584582
{
585583
struct packfile_store *packs = the_repository->objects->packfiles;
586-
struct packed_git *p = packfile_store_get_all_packs(packs);
584+
struct packed_git *p;
587585

588-
while (p) {
586+
packfile_store_for_each_pack(packs, p)
589587
add_pack(p);
590-
p = p->next;
591-
}
592588
}
593589

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

connected.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
7777
struct packfile_store *packs = the_repository->objects->packfiles;
7878
struct packed_git *p;
7979

80-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
80+
packfile_store_for_each_pack(packs, p) {
8181
if (!p->pack_promisor)
8282
continue;
8383
if (find_pack_entry_one(oid, p))

http-backend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,13 @@ static void get_info_packs(struct strbuf *hdr, char *arg UNUSED)
607607
size_t cnt = 0;
608608

609609
select_getanyfile(hdr);
610-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
610+
packfile_store_for_each_pack(packs, p) {
611611
if (p->pack_local)
612612
cnt++;
613613
}
614614

615615
strbuf_grow(&buf, cnt * 53 + 2);
616-
for (p = packfile_store_get_all_packs(packs); p; p = p->next) {
616+
packfile_store_for_each_pack(packs, p) {
617617
if (p->pack_local)
618618
strbuf_addf(&buf, "P %s\n", p->pack_name + objdirlen + 6);
619619
}

0 commit comments

Comments
 (0)