Git fork

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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
d2779beb 751808b2

+76 -42
+2 -1
builtin/cat-file.c
··· 852 852 853 853 if (bitmap && !for_each_bitmapped_object(bitmap, &opt->objects_filter, 854 854 batch_one_object_bitmapped, &payload)) { 855 + struct packfile_store *packs = the_repository->objects->packfiles; 855 856 struct packed_git *pack; 856 857 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) { 858 859 if (bitmap_index_contains_pack(bitmap, pack) || 859 860 open_pack_index(pack)) 860 861 continue;
+2 -1
builtin/count-objects.c
··· 122 122 count_loose, count_cruft, NULL, NULL); 123 123 124 124 if (verbose) { 125 + struct packfile_store *packs = the_repository->objects->packfiles; 125 126 struct packed_git *p; 126 127 unsigned long num_pack = 0; 127 128 off_t size_pack = 0; ··· 129 130 struct strbuf pack_buf = STRBUF_INIT; 130 131 struct strbuf garbage_buf = STRBUF_INIT; 131 132 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) { 133 134 if (!p->pack_local) 134 135 continue; 135 136 if (open_pack_index(p))
+4 -2
builtin/fast-import.c
··· 952 952 struct object_id *oidout, 953 953 uintmax_t mark) 954 954 { 955 + struct packfile_store *packs = the_repository->objects->packfiles; 955 956 void *out, *delta; 956 957 struct object_entry *e; 957 958 unsigned char hdr[96]; ··· 975 976 if (e->idx.offset) { 976 977 duplicate_count_by_type[type]++; 977 978 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))) { 979 980 e->type = type; 980 981 e->pack_id = MAX_PACK_ID; 981 982 e->idx.offset = 1; /* just not zero! */ ··· 1092 1093 1093 1094 static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) 1094 1095 { 1096 + struct packfile_store *packs = the_repository->objects->packfiles; 1095 1097 size_t in_sz = 64 * 1024, out_sz = 64 * 1024; 1096 1098 unsigned char *in_buf = xmalloc(in_sz); 1097 1099 unsigned char *out_buf = xmalloc(out_sz); ··· 1175 1177 duplicate_count_by_type[OBJ_BLOB]++; 1176 1178 truncate_pack(&checkpoint); 1177 1179 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))) { 1179 1181 e->type = OBJ_BLOB; 1180 1182 e->pack_id = MAX_PACK_ID; 1181 1183 e->idx.offset = 1; /* just not zero! */
+7 -4
builtin/fsck.c
··· 867 867 868 868 static int check_pack_rev_indexes(struct repository *r, int show_progress) 869 869 { 870 + struct packfile_store *packs = r->objects->packfiles; 870 871 struct progress *progress = NULL; 871 872 uint32_t pack_count = 0; 872 873 int res = 0; 873 874 874 875 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) 876 877 pack_count++; 877 878 progress = start_delayed_progress(the_repository, 878 879 "Verifying reverse pack-indexes", pack_count); 879 880 pack_count = 0; 880 881 } 881 882 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) { 883 884 int load_error = load_pack_revindex_from_disk(p); 884 885 885 886 if (load_error < 0) { ··· 999 1000 for_each_packed_object(the_repository, 1000 1001 mark_packed_for_connectivity, NULL, 0); 1001 1002 } else { 1003 + struct packfile_store *packs = the_repository->objects->packfiles; 1004 + 1002 1005 odb_prepare_alternates(the_repository->objects); 1003 1006 for (source = the_repository->objects->sources; source; source = source->next) 1004 1007 fsck_source(source); ··· 1009 1012 struct progress *progress = NULL; 1010 1013 1011 1014 if (show_progress) { 1012 - for (p = get_all_packs(the_repository); p; 1015 + for (p = packfile_store_get_all_packs(packs); p; 1013 1016 p = p->next) { 1014 1017 if (open_pack_index(p)) 1015 1018 continue; ··· 1019 1022 progress = start_progress(the_repository, 1020 1023 _("Checking objects"), total); 1021 1024 } 1022 - for (p = get_all_packs(the_repository); p; 1025 + for (p = packfile_store_get_all_packs(packs); p; 1023 1026 p = p->next) { 1024 1027 /* verify gives error messages itself */ 1025 1028 if (verify_pack(the_repository,
+5 -3
builtin/gc.c
··· 487 487 static struct packed_git *find_base_packs(struct string_list *packs, 488 488 unsigned long limit) 489 489 { 490 + struct packfile_store *packfiles = the_repository->objects->packfiles; 490 491 struct packed_git *p, *base = NULL; 491 492 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) { 493 494 if (!p->pack_local || p->is_cruft) 494 495 continue; 495 496 if (limit) { ··· 508 509 509 510 static int too_many_packs(struct gc_config *cfg) 510 511 { 512 + struct packfile_store *packs = the_repository->objects->packfiles; 511 513 struct packed_git *p; 512 514 int cnt; 513 515 514 516 if (cfg->gc_auto_pack_limit <= 0) 515 517 return 0; 516 518 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) { 518 520 if (!p->pack_local) 519 521 continue; 520 522 if (p->pack_keep) ··· 1492 1494 struct repository *r = the_repository; 1493 1495 1494 1496 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) { 1496 1498 if (p->pack_size > max_size) { 1497 1499 second_largest_size = max_size; 1498 1500 max_size = p->pack_size;
+19 -9
builtin/pack-objects.c
··· 3831 3831 3832 3832 static void read_packs_list_from_stdin(struct rev_info *revs) 3833 3833 { 3834 + struct packfile_store *packs = the_repository->objects->packfiles; 3834 3835 struct strbuf buf = STRBUF_INIT; 3835 3836 struct string_list include_packs = STRING_LIST_INIT_DUP; 3836 3837 struct string_list exclude_packs = STRING_LIST_INIT_DUP; ··· 3855 3856 string_list_sort(&exclude_packs); 3856 3857 string_list_remove_duplicates(&exclude_packs, 0); 3857 3858 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) { 3859 3860 const char *pack_name = pack_basename(p); 3860 3861 3861 3862 if ((item = string_list_lookup(&include_packs, pack_name))) ··· 4076 4077 4077 4078 static void enumerate_and_traverse_cruft_objects(struct string_list *fresh_packs) 4078 4079 { 4080 + struct packfile_store *packs = the_repository->objects->packfiles; 4079 4081 struct packed_git *p; 4080 4082 struct rev_info revs; 4081 4083 int ret; ··· 4105 4107 * Re-mark only the fresh packs as kept so that objects in 4106 4108 * unknown packs do not halt the reachability traversal early. 4107 4109 */ 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) 4109 4111 p->pack_keep_in_core = 0; 4110 4112 mark_pack_kept_in_core(fresh_packs, 1); 4111 4113 ··· 4122 4124 4123 4125 static void read_cruft_objects(void) 4124 4126 { 4127 + struct packfile_store *packs = the_repository->objects->packfiles; 4125 4128 struct strbuf buf = STRBUF_INIT; 4126 4129 struct string_list discard_packs = STRING_LIST_INIT_DUP; 4127 4130 struct string_list fresh_packs = STRING_LIST_INIT_DUP; ··· 4142 4145 string_list_sort(&discard_packs); 4143 4146 string_list_sort(&fresh_packs); 4144 4147 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) { 4146 4149 const char *pack_name = pack_basename(p); 4147 4150 struct string_list_item *item; 4148 4151 ··· 4390 4393 4391 4394 static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid) 4392 4395 { 4396 + struct packfile_store *packs = the_repository->objects->packfiles; 4393 4397 static struct packed_git *last_found = (void *)1; 4394 4398 struct packed_git *p; 4395 4399 4396 4400 p = (last_found != (void *)1) ? last_found : 4397 - get_all_packs(the_repository); 4401 + packfile_store_get_all_packs(packs); 4398 4402 4399 4403 while (p) { 4400 4404 if ((!p->pack_local || p->pack_keep || ··· 4404 4408 return 1; 4405 4409 } 4406 4410 if (p == last_found) 4407 - p = get_all_packs(the_repository); 4411 + p = packfile_store_get_all_packs(packs); 4408 4412 else 4409 4413 p = p->next; 4410 4414 if (p == last_found) ··· 4436 4440 4437 4441 static void loosen_unused_packed_objects(void) 4438 4442 { 4443 + struct packfile_store *packs = the_repository->objects->packfiles; 4439 4444 struct packed_git *p; 4440 4445 uint32_t i; 4441 4446 uint32_t loosened_objects_nr = 0; 4442 4447 struct object_id oid; 4443 4448 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) { 4445 4450 if (!p->pack_local || p->pack_keep || p->pack_keep_in_core) 4446 4451 continue; 4447 4452 ··· 4742 4747 4743 4748 static void add_extra_kept_packs(const struct string_list *names) 4744 4749 { 4750 + struct packfile_store *packs = the_repository->objects->packfiles; 4745 4751 struct packed_git *p; 4746 4752 4747 4753 if (!names->nr) 4748 4754 return; 4749 4755 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) { 4751 4757 const char *name = basename(p->pack_name); 4752 4758 int i; 4753 4759 ··· 5185 5191 5186 5192 add_extra_kept_packs(&keep_pack_list); 5187 5193 if (ignore_packed_keep_on_disk) { 5194 + struct packfile_store *packs = the_repository->objects->packfiles; 5188 5195 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) 5190 5198 if (p->pack_local && p->pack_keep) 5191 5199 break; 5192 5200 if (!p) /* no keep-able packs found */ ··· 5198 5206 * want to unset "local" based on looking at packs, as 5199 5207 * it also covers non-local objects 5200 5208 */ 5209 + struct packfile_store *packs = the_repository->objects->packfiles; 5201 5210 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) { 5203 5213 if (!p->pack_local) { 5204 5214 have_non_local_packs = 1; 5205 5215 break;
+4 -2
builtin/pack-redundant.c
··· 566 566 567 567 static struct pack_list * add_pack_file(const char *filename) 568 568 { 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); 570 571 571 572 if (strlen(filename) < 40) 572 573 die("Bad pack filename: %s", filename); ··· 581 582 582 583 static void load_all(void) 583 584 { 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); 585 587 586 588 while (p) { 587 589 add_pack(p);
+6 -3
builtin/repack.c
··· 265 265 static void collect_pack_filenames(struct existing_packs *existing, 266 266 const struct string_list *extra_keep) 267 267 { 268 + struct packfile_store *packs = the_repository->objects->packfiles; 268 269 struct packed_git *p; 269 270 struct strbuf buf = STRBUF_INIT; 270 271 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) { 272 273 int i; 273 274 const char *base; 274 275 ··· 497 498 struct existing_packs *existing, 498 499 const struct pack_objects_args *args) 499 500 { 501 + struct packfile_store *packs = the_repository->objects->packfiles; 500 502 struct packed_git *p; 501 503 struct strbuf buf = STRBUF_INIT; 502 504 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) { 504 506 if (args->local && !p->pack_local) 505 507 /* 506 508 * When asked to only repack local packfiles we skip ··· 1137 1139 static void combine_small_cruft_packs(FILE *in, size_t combine_cruft_below_size, 1138 1140 struct existing_packs *existing) 1139 1141 { 1142 + struct packfile_store *packs = the_repository->objects->packfiles; 1140 1143 struct packed_git *p; 1141 1144 struct strbuf buf = STRBUF_INIT; 1142 1145 size_t i; 1143 1146 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) { 1145 1148 if (!(p->is_cruft && p->pack_local)) 1146 1149 continue; 1147 1150
+2 -1
connected.c
··· 74 74 */ 75 75 odb_reprepare(the_repository->objects); 76 76 do { 77 + struct packfile_store *packs = the_repository->objects->packfiles; 77 78 struct packed_git *p; 78 79 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) { 80 81 if (!p->pack_promisor) 81 82 continue; 82 83 if (find_pack_entry_one(oid, p))
+3 -2
http-backend.c
··· 603 603 static void get_info_packs(struct strbuf *hdr, char *arg UNUSED) 604 604 { 605 605 size_t objdirlen = strlen(repo_get_object_directory(the_repository)); 606 + struct packfile_store *packs = the_repository->objects->packfiles; 606 607 struct strbuf buf = STRBUF_INIT; 607 608 struct packed_git *p; 608 609 size_t cnt = 0; 609 610 610 611 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) { 612 613 if (p->pack_local) 613 614 cnt++; 614 615 } 615 616 616 617 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) { 618 619 if (p->pack_local) 619 620 strbuf_addf(&buf, "P %s\n", p->pack_name + objdirlen + 6); 620 621 }
+2 -1
http.c
··· 2408 2408 static int fetch_and_setup_pack_index(struct packed_git **packs_head, 2409 2409 unsigned char *sha1, const char *base_url) 2410 2410 { 2411 + struct packfile_store *packs = the_repository->objects->packfiles; 2411 2412 struct packed_git *new_pack, *p; 2412 2413 char *tmp_idx = NULL; 2413 2414 int ret; ··· 2416 2417 * If we already have the pack locally, no need to fetch its index or 2417 2418 * even add it to list; we already have all of its objects. 2418 2419 */ 2419 - for (p = get_all_packs(the_repository); p; p = p->next) { 2420 + for (p = packfile_store_get_all_packs(packs); p; p = p->next) { 2420 2421 if (hasheq(p->hash, sha1, the_repository->hash_algo)) 2421 2422 return 0; 2422 2423 }
+2 -2
pack-bitmap.c
··· 664 664 struct packed_git *p; 665 665 int ret = -1; 666 666 667 - for (p = get_all_packs(r); p; p = p->next) { 667 + for (p = packfile_store_get_all_packs(r->objects->packfiles); p; p = p->next) { 668 668 if (open_pack_bitmap_1(bitmap_git, p) == 0) { 669 669 ret = 0; 670 670 /* ··· 3362 3362 free(midx_bitmap_name); 3363 3363 } 3364 3364 3365 - for (struct packed_git *p = get_all_packs(r); 3365 + for (struct packed_git *p = packfile_store_get_all_packs(r->objects->packfiles); 3366 3366 p; p = p->next) { 3367 3367 char *pack_bitmap_name = pack_bitmap_filename(p); 3368 3368 res |= verify_bitmap_file(r->hash_algo, pack_bitmap_name);
+2 -1
pack-objects.c
··· 86 86 87 87 static void prepare_in_pack_by_idx(struct packing_data *pdata) 88 88 { 89 + struct packfile_store *packs = pdata->repo->objects->packfiles; 89 90 struct packed_git **mapping, *p; 90 91 int cnt = 0, nr = 1U << OE_IN_PACK_BITS; 91 92 ··· 95 96 * (i.e. in_pack_idx also zero) should return NULL. 96 97 */ 97 98 mapping[cnt++] = NULL; 98 - for (p = get_all_packs(pdata->repo); p; p = p->next, cnt++) { 99 + for (p = packfile_store_get_all_packs(packs); p; p = p->next, cnt++) { 99 100 if (cnt == nr) { 100 101 free(mapping); 101 102 return;
+6 -6
packfile.c
··· 1033 1033 return store->packs; 1034 1034 } 1035 1035 1036 - struct packed_git *get_all_packs(struct repository *r) 1036 + struct packed_git *packfile_store_get_all_packs(struct packfile_store *store) 1037 1037 { 1038 - packfile_store_prepare(r->objects->packfiles); 1038 + packfile_store_prepare(store); 1039 1039 1040 - for (struct odb_source *source = r->objects->sources; source; source = source->next) { 1040 + for (struct odb_source *source = store->odb->sources; source; source = source->next) { 1041 1041 struct multi_pack_index *m = source->midx; 1042 1042 if (!m) 1043 1043 continue; ··· 1045 1045 prepare_midx_pack(m, i); 1046 1046 } 1047 1047 1048 - return r->objects->packfiles->packs; 1048 + return store->packs; 1049 1049 } 1050 1050 1051 1051 struct list_head *get_packed_git_mru(struct repository *r) ··· 2105 2105 * covers, one kept and one not kept, but the midx returns only 2106 2106 * the non-kept version. 2107 2107 */ 2108 - for (p = get_all_packs(r); p; p = p->next) { 2108 + for (p = packfile_store_get_all_packs(r->objects->packfiles); p; p = p->next) { 2109 2109 if ((p->pack_keep && (flags & ON_DISK_KEEP_PACKS)) || 2110 2110 (p->pack_keep_in_core && (flags & IN_CORE_KEEP_PACKS))) { 2111 2111 ALLOC_GROW(packs, nr + 1, alloc); ··· 2202 2202 int r = 0; 2203 2203 int pack_errors = 0; 2204 2204 2205 - for (p = get_all_packs(repo); p; p = p->next) { 2205 + for (p = packfile_store_get_all_packs(repo->objects->packfiles); p; p = p->next) { 2206 2206 if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local) 2207 2207 continue; 2208 2208 if ((flags & FOR_EACH_OBJECT_PROMISOR_ONLY) &&
+6 -1
packfile.h
··· 143 143 struct packed_git *packfile_store_get_packs(struct packfile_store *store); 144 144 145 145 /* 146 + * Get all packs managed by the given store, including packfiles that are 147 + * referenced by multi-pack indices. 148 + */ 149 + struct packed_git *packfile_store_get_all_packs(struct packfile_store *store); 150 + 151 + /* 146 152 * Open the packfile and add it to the store if it isn't yet known. Returns 147 153 * either the newly opened packfile or the preexisting packfile. Returns a 148 154 * `NULL` pointer in case the packfile could not be opened. ··· 227 233 extern void (*report_garbage)(unsigned seen_bits, const char *path); 228 234 229 235 struct list_head *get_packed_git_mru(struct repository *r); 230 - struct packed_git *get_all_packs(struct repository *r); 231 236 232 237 /* 233 238 * Give a rough count of objects in the repository. This sacrifices accuracy
+2 -1
server-info.c
··· 287 287 288 288 static void init_pack_info(struct repository *r, const char *infofile, int force) 289 289 { 290 + struct packfile_store *packs = r->objects->packfiles; 290 291 struct packed_git *p; 291 292 int stale; 292 293 int i; 293 294 size_t alloc = 0; 294 295 295 - for (p = get_all_packs(r); p; p = p->next) { 296 + for (p = packfile_store_get_all_packs(packs); p; p = p->next) { 296 297 /* we ignore things on alternate path since they are 297 298 * not available to the pullers in general. 298 299 */
+1 -1
t/helper/test-find-pack.c
··· 39 39 if (repo_get_oid(the_repository, argv[0], &oid)) 40 40 die("cannot parse %s as an object name", argv[0]); 41 41 42 - for (p = get_all_packs(the_repository); p; p = p->next) 42 + for (p = packfile_store_get_all_packs(the_repository->objects->packfiles); p; p = p->next) 43 43 if (find_pack_entry_one(&oid, p)) { 44 44 printf("%s\n", p->pack_name); 45 45 actual_count++;
+1 -1
t/helper/test-pack-mtimes.c
··· 37 37 if (argc != 2) 38 38 usage(pack_mtimes_usage); 39 39 40 - for (p = get_all_packs(the_repository); p; p = p->next) { 40 + for (p = packfile_store_get_all_packs(the_repository->objects->packfiles); p; p = p->next) { 41 41 strbuf_addstr(&buf, basename(p->pack_name)); 42 42 strbuf_strip_suffix(&buf, ".pack"); 43 43 strbuf_addstr(&buf, ".mtimes");