packfile: keep prepare_packed_git() private

The reason callers have to call this is to make sure either packed_git or packed_git_mru pointers are initialized since we don't do that by default. Sometimes it's hard to see this connection between where the function is called and where packed_git pointer is used (sometimes in separate functions). Keep this dependency internal because now all access to packed_git and packed_git_mru must go through get_xxx() wrappers. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Mar 23, 2018 at 18:45 UTC 464416a2eaadf84d2bfdf795007863d03b222b7c
12 files changed +5 -16
builtin/count-objects.c
+1 -2
@@ -122,8 +122,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
122 struct strbuf loose_buf = STRBUF_INIT;
123 struct strbuf pack_buf = STRBUF_INIT;
124 struct strbuf garbage_buf = STRBUF_INIT;
125 - if (!get_packed_git(the_repository))
126 - prepare_packed_git(the_repository);
125 +
126 for (p = get_packed_git(the_repository); p; p = p->next) {
127 if (!p->pack_local)
128 continue;
builtin/fsck.c
-2
@@ -729,8 +729,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
729 uint32_t total = 0, count = 0;
730 struct progress *progress = NULL;
731
732 - prepare_packed_git(the_repository);
733 -
732 if (show_progress) {
733 for (p = get_packed_git(the_repository); p;
734 p = p->next) {
builtin/gc.c
-1
@@ -174,7 +174,6 @@ static int too_many_packs(void)
174 if (gc_auto_pack_limit <= 0)
175 return 0;
176
177 - prepare_packed_git(the_repository);
177 for (cnt = 0, p = get_packed_git(the_repository); p; p = p->next) {
178 if (!p->pack_local)
179 continue;
builtin/pack-objects.c
-1
@@ -3152,7 +3152,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
3152 if (progress && all_progress_implied)
3153 progress = 2;
3154
3155 - prepare_packed_git(the_repository);
3155 if (ignore_packed_keep) {
3156 struct packed_git *p;
3157 for (p = get_packed_git(the_repository); p; p = p->next)
builtin/pack-redundant.c
-2
@@ -631,8 +631,6 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
631 break;
632 }
633
634 - prepare_packed_git(the_repository);
635 -
634 if (load_all_packs)
635 load_all();
636 else
fast-import.c
-1
@@ -3473,7 +3473,6 @@ int cmd_main(int argc, const char **argv)
3473 rc_free[i].next = &rc_free[i + 1];
3474 rc_free[cmd_save - 1].next = NULL;
3475
3476 - prepare_packed_git(the_repository);
3476 start_packfile();
3477 set_die_routine(die_nicely);
3478 set_checkpoint_signal();
http-backend.c
-1
@@ -519,7 +519,6 @@ static void get_info_packs(struct strbuf *hdr, char *arg)
519 size_t cnt = 0;
520
521 select_getanyfile(hdr);
522 - prepare_packed_git(the_repository);
522 for (p = get_packed_git(the_repository); p; p = p->next) {
523 if (p->pack_local)
524 cnt++;
pack-bitmap.c
-1
@@ -336,7 +336,6 @@ static int open_pack_bitmap(void)
336
337 assert(!bitmap_git.map && !bitmap_git.loaded);
338
339 - prepare_packed_git(the_repository);
339 for (p = get_packed_git(the_repository); p; p = p->next) {
340 if (open_pack_bitmap_1(p) == 0)
341 ret = 0;
packfile.c
+4 -1
@@ -803,6 +803,7 @@ static void prepare_packed_git_one(struct repository *r, char *objdir, int local
803 strbuf_release(&path);
804 }
805
806 +static void prepare_packed_git(struct repository *r);
807 /*
808 * Give a fast, rough count of the number of objects in the repository. This
809 * ignores loose objects completely. If you have a lot of them, then either
@@ -883,7 +884,7 @@ static void prepare_packed_git_mru(struct repository *r)
884 list_add_tail(&p->mru, &r->objects->packed_git_mru);
885 }
886
886 -void prepare_packed_git(struct repository *r)
887 +static void prepare_packed_git(struct repository *r)
888 {
889 struct alternate_object_database *alt;
890
@@ -907,11 +908,13 @@ void reprepare_packed_git(struct repository *r)
908
909 struct packed_git *get_packed_git(struct repository *r)
910 {
911 + prepare_packed_git(r);
912 return r->objects->packed_git;
913 }
914
915 struct list_head *get_packed_git_mru(struct repository *r)
916 {
917 + prepare_packed_git(r);
918 return &r->objects->packed_git_mru;
919 }
920
packfile.h
-1
@@ -34,7 +34,6 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_
34 #define PACKDIR_FILE_GARBAGE 4
35 extern void (*report_garbage)(unsigned seen_bits, const char *path);
36
37 -extern void prepare_packed_git(struct repository *r);
37 extern void reprepare_packed_git(struct repository *r);
38 extern void install_packed_git(struct repository *r, struct packed_git *pack);
39
server-info.c
-1
@@ -201,7 +201,6 @@ static void init_pack_info(const char *infofile, int force)
201 objdir = get_object_directory();
202 objdirlen = strlen(objdir);
203
204 - prepare_packed_git(the_repository);
204 for (p = get_packed_git(the_repository); p; p = p->next) {
205 /* we ignore things on alternate path since they are
206 * not available to the pullers in general.
sha1_name.c
-2
@@ -196,7 +196,6 @@ static void find_short_packed_object(struct disambiguate_state *ds)
196 {
197 struct packed_git *p;
198
199 - prepare_packed_git(the_repository);
199 for (p = get_packed_git(the_repository); p && !ds->ambiguous;
200 p = p->next)
201 unique_in_pack(p, ds);
@@ -567,7 +566,6 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
566 {
567 struct packed_git *p;
568
570 - prepare_packed_git(the_repository);
569 for (p = get_packed_git(the_repository); p; p = p->next)
570 find_abbrev_len_for_pack(p, mad);
571 }