treewide: use get_all_packs

There are many places in the codebase that want to iterate over all packfiles known to Git. The purposes are wide-ranging, and those that can take advantage of the multi-pack-index already do. So, use get_all_packs() instead of get_packed_git() to be sure we are iterating over all packfiles. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Aug 20, 2018 at 16:52 UTC 454ea2e4d7036862e8b2f69ef2dea640f8787510
11 files changed +23 -23
builtin/count-objects.c
+1 -1
@@ -123,7 +123,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
123 struct strbuf pack_buf = STRBUF_INIT;
124 struct strbuf garbage_buf = STRBUF_INIT;
125
126 - for (p = get_packed_git(the_repository); p; p = p->next) {
126 + for (p = get_all_packs(the_repository); p; p = p->next) {
127 if (!p->pack_local)
128 continue;
129 if (open_pack_index(p))
builtin/fsck.c
+2 -2
@@ -740,7 +740,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
740 struct progress *progress = NULL;
741
742 if (show_progress) {
743 - for (p = get_packed_git(the_repository); p;
743 + for (p = get_all_packs(the_repository); p;
744 p = p->next) {
745 if (open_pack_index(p))
746 continue;
@@ -749,7 +749,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
749
750 progress = start_progress(_("Checking objects"), total);
751 }
752 - for (p = get_packed_git(the_repository); p;
752 + for (p = get_all_packs(the_repository); p;
753 p = p->next) {
754 /* verify gives error messages itself */
755 if (verify_pack(p, fsck_obj_buffer,
builtin/gc.c
+2 -2
@@ -183,7 +183,7 @@ static struct packed_git *find_base_packs(struct string_list *packs,
183 {
184 struct packed_git *p, *base = NULL;
185
186 - for (p = get_packed_git(the_repository); p; p = p->next) {
186 + for (p = get_all_packs(the_repository); p; p = p->next) {
187 if (!p->pack_local)
188 continue;
189 if (limit) {
@@ -208,7 +208,7 @@ static int too_many_packs(void)
208 if (gc_auto_pack_limit <= 0)
209 return 0;
210
211 - for (cnt = 0, p = get_packed_git(the_repository); p; p = p->next) {
211 + for (cnt = 0, p = get_all_packs(the_repository); p; p = p->next) {
212 if (!p->pack_local)
213 continue;
214 if (p->pack_keep)
builtin/pack-objects.c
+7 -7
@@ -2809,7 +2809,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
2809
2810 memset(&in_pack, 0, sizeof(in_pack));
2811
2812 - for (p = get_packed_git(the_repository); p; p = p->next) {
2812 + for (p = get_all_packs(the_repository); p; p = p->next) {
2813 struct object_id oid;
2814 struct object *o;
2815
@@ -2873,7 +2873,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
2873 struct packed_git *p;
2874
2875 p = (last_found != (void *)1) ? last_found :
2876 - get_packed_git(the_repository);
2876 + get_all_packs(the_repository);
2877
2878 while (p) {
2879 if ((!p->pack_local || p->pack_keep ||
@@ -2883,7 +2883,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
2883 return 1;
2884 }
2885 if (p == last_found)
2886 - p = get_packed_git(the_repository);
2886 + p = get_all_packs(the_repository);
2887 else
2888 p = p->next;
2889 if (p == last_found)
@@ -2919,7 +2919,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
2919 uint32_t i;
2920 struct object_id oid;
2921
2922 - for (p = get_packed_git(the_repository); p; p = p->next) {
2922 + for (p = get_all_packs(the_repository); p; p = p->next) {
2923 if (!p->pack_local || p->pack_keep || p->pack_keep_in_core)
2924 continue;
2925
@@ -3066,7 +3066,7 @@ static void add_extra_kept_packs(const struct string_list *names)
3066 if (!names->nr)
3067 return;
3068
3069 - for (p = get_packed_git(the_repository); p; p = p->next) {
3069 + for (p = get_all_packs(the_repository); p; p = p->next) {
3070 const char *name = basename(p->pack_name);
3071 int i;
3072
@@ -3339,7 +3339,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
3339 add_extra_kept_packs(&keep_pack_list);
3340 if (ignore_packed_keep_on_disk) {
3341 struct packed_git *p;
3342 - for (p = get_packed_git(the_repository); p; p = p->next)
3342 + for (p = get_all_packs(the_repository); p; p = p->next)
3343 if (p->pack_local && p->pack_keep)
3344 break;
3345 if (!p) /* no keep-able packs found */
@@ -3352,7 +3352,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
3352 * it also covers non-local objects
3353 */
3354 struct packed_git *p;
3355 - for (p = get_packed_git(the_repository); p; p = p->next) {
3355 + for (p = get_all_packs(the_repository); p; p = p->next) {
3356 if (!p->pack_local) {
3357 have_non_local_packs = 1;
3358 break;
builtin/pack-redundant.c
+2 -2
@@ -577,7 +577,7 @@ static struct pack_list * add_pack(struct packed_git *p)
577
578 static struct pack_list * add_pack_file(const char *filename)
579 {
580 - struct packed_git *p = get_packed_git(the_repository);
580 + struct packed_git *p = get_all_packs(the_repository);
581
582 if (strlen(filename) < 40)
583 die("Bad pack filename: %s", filename);
@@ -592,7 +592,7 @@ static struct pack_list * add_pack_file(const char *filename)
592
593 static void load_all(void)
594 {
595 - struct packed_git *p = get_packed_git(the_repository);
595 + struct packed_git *p = get_all_packs(the_repository);
596
597 while (p) {
598 add_pack(p);
fast-import.c
+2 -2
@@ -1068,7 +1068,7 @@ static int store_object(
1068 duplicate_count_by_type[type]++;
1069 return 1;
1070 } else if (find_sha1_pack(oid.hash,
1071 - get_packed_git(the_repository))) {
1071 + get_all_packs(the_repository))) {
1072 e->type = type;
1073 e->pack_id = MAX_PACK_ID;
1074 e->idx.offset = 1; /* just not zero! */
@@ -1266,7 +1266,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
1266 truncate_pack(&checkpoint);
1267
1268 } else if (find_sha1_pack(oid.hash,
1269 - get_packed_git(the_repository))) {
1269 + get_all_packs(the_repository))) {
1270 e->type = OBJ_BLOB;
1271 e->pack_id = MAX_PACK_ID;
1272 e->idx.offset = 1; /* just not zero! */
http-backend.c
+2 -2
@@ -595,13 +595,13 @@ static void get_info_packs(struct strbuf *hdr, char *arg)
595 size_t cnt = 0;
596
597 select_getanyfile(hdr);
598 - for (p = get_packed_git(the_repository); p; p = p->next) {
598 + for (p = get_all_packs(the_repository); p; p = p->next) {
599 if (p->pack_local)
600 cnt++;
601 }
602
603 strbuf_grow(&buf, cnt * 53 + 2);
604 - for (p = get_packed_git(the_repository); p; p = p->next) {
604 + for (p = get_all_packs(the_repository); p; p = p->next) {
605 if (p->pack_local)
606 strbuf_addf(&buf, "P %s\n", p->pack_name + objdirlen + 6);
607 }
pack-bitmap.c
+1 -1
@@ -335,7 +335,7 @@ static int open_pack_bitmap(struct bitmap_index *bitmap_git)
335
336 assert(!bitmap_git->map && !bitmap_git->loaded);
337
338 - for (p = get_packed_git(the_repository); p; p = p->next) {
338 + for (p = get_all_packs(the_repository); p; p = p->next) {
339 if (open_pack_bitmap_1(bitmap_git, p) == 0)
340 ret = 0;
341 }
pack-objects.c
+1 -1
@@ -99,7 +99,7 @@ static void prepare_in_pack_by_idx(struct packing_data *pdata)
99 * (i.e. in_pack_idx also zero) should return NULL.
100 */
101 mapping[cnt++] = NULL;
102 - for (p = get_packed_git(the_repository); p; p = p->next, cnt++) {
102 + for (p = get_all_packs(the_repository); p; p = p->next, cnt++) {
103 if (cnt == nr) {
104 free(mapping);
105 return;
packfile.c
+1 -1
@@ -2036,7 +2036,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data,
2036 int pack_errors = 0;
2037
2038 prepare_packed_git(the_repository);
2039 - for (p = the_repository->objects->packed_git; p; p = p->next) {
2039 + for (p = get_all_packs(the_repository); p; p = p->next) {
2040 if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
2041 continue;
2042 if ((flags & FOR_EACH_OBJECT_PROMISOR_ONLY) &&
server-info.c
+2 -2
@@ -199,7 +199,7 @@ static void init_pack_info(const char *infofile, int force)
199 objdir = get_object_directory();
200 objdirlen = strlen(objdir);
201
202 - for (p = get_packed_git(the_repository); p; p = p->next) {
202 + for (p = get_all_packs(the_repository); p; p = p->next) {
203 /* we ignore things on alternate path since they are
204 * not available to the pullers in general.
205 */
@@ -209,7 +209,7 @@ static void init_pack_info(const char *infofile, int force)
209 }
210 num_pack = i;
211 info = xcalloc(num_pack, sizeof(struct pack_info *));
212 - for (i = 0, p = get_packed_git(the_repository); p; p = p->next) {
212 + for (i = 0, p = get_all_packs(the_repository); p; p = p->next) {
213 if (!p->pack_local)
214 continue;
215 info[i] = xcalloc(1, sizeof(struct pack_info));