Skip to content

Commit 464416a

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0a0dd63 commit 464416a

File tree

12 files changed

+5
-16
lines changed

12 files changed

+5
-16
lines changed

builtin/count-objects.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
122122
struct strbuf loose_buf = STRBUF_INIT;
123123
struct strbuf pack_buf = STRBUF_INIT;
124124
struct strbuf garbage_buf = STRBUF_INIT;
125-
if (!get_packed_git(the_repository))
126-
prepare_packed_git(the_repository);
125+
127126
for (p = get_packed_git(the_repository); p; p = p->next) {
128127
if (!p->pack_local)
129128
continue;

builtin/fsck.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
729729
uint32_t total = 0, count = 0;
730730
struct progress *progress = NULL;
731731

732-
prepare_packed_git(the_repository);
733-
734732
if (show_progress) {
735733
for (p = get_packed_git(the_repository); p;
736734
p = p->next) {

builtin/gc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ static int too_many_packs(void)
174174
if (gc_auto_pack_limit <= 0)
175175
return 0;
176176

177-
prepare_packed_git(the_repository);
178177
for (cnt = 0, p = get_packed_git(the_repository); p; p = p->next) {
179178
if (!p->pack_local)
180179
continue;

builtin/pack-objects.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3152,7 +3152,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
31523152
if (progress && all_progress_implied)
31533153
progress = 2;
31543154

3155-
prepare_packed_git(the_repository);
31563155
if (ignore_packed_keep) {
31573156
struct packed_git *p;
31583157
for (p = get_packed_git(the_repository); p; p = p->next)

builtin/pack-redundant.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,6 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
631631
break;
632632
}
633633

634-
prepare_packed_git(the_repository);
635-
636634
if (load_all_packs)
637635
load_all();
638636
else

fast-import.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3473,7 +3473,6 @@ int cmd_main(int argc, const char **argv)
34733473
rc_free[i].next = &rc_free[i + 1];
34743474
rc_free[cmd_save - 1].next = NULL;
34753475

3476-
prepare_packed_git(the_repository);
34773476
start_packfile();
34783477
set_die_routine(die_nicely);
34793478
set_checkpoint_signal();

http-backend.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ static void get_info_packs(struct strbuf *hdr, char *arg)
519519
size_t cnt = 0;
520520

521521
select_getanyfile(hdr);
522-
prepare_packed_git(the_repository);
523522
for (p = get_packed_git(the_repository); p; p = p->next) {
524523
if (p->pack_local)
525524
cnt++;

pack-bitmap.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ static int open_pack_bitmap(void)
336336

337337
assert(!bitmap_git.map && !bitmap_git.loaded);
338338

339-
prepare_packed_git(the_repository);
340339
for (p = get_packed_git(the_repository); p; p = p->next) {
341340
if (open_pack_bitmap_1(p) == 0)
342341
ret = 0;

packfile.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ static void prepare_packed_git_one(struct repository *r, char *objdir, int local
803803
strbuf_release(&path);
804804
}
805805

806+
static void prepare_packed_git(struct repository *r);
806807
/*
807808
* Give a fast, rough count of the number of objects in the repository. This
808809
* 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)
883884
list_add_tail(&p->mru, &r->objects->packed_git_mru);
884885
}
885886

886-
void prepare_packed_git(struct repository *r)
887+
static void prepare_packed_git(struct repository *r)
887888
{
888889
struct alternate_object_database *alt;
889890

@@ -907,11 +908,13 @@ void reprepare_packed_git(struct repository *r)
907908

908909
struct packed_git *get_packed_git(struct repository *r)
909910
{
911+
prepare_packed_git(r);
910912
return r->objects->packed_git;
911913
}
912914

913915
struct list_head *get_packed_git_mru(struct repository *r)
914916
{
917+
prepare_packed_git(r);
915918
return &r->objects->packed_git_mru;
916919
}
917920

packfile.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_
3434
#define PACKDIR_FILE_GARBAGE 4
3535
extern void (*report_garbage)(unsigned seen_bits, const char *path);
3636

37-
extern void prepare_packed_git(struct repository *r);
3837
extern void reprepare_packed_git(struct repository *r);
3938
extern void install_packed_git(struct repository *r, struct packed_git *pack);
4039

server-info.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ static void init_pack_info(const char *infofile, int force)
201201
objdir = get_object_directory();
202202
objdirlen = strlen(objdir);
203203

204-
prepare_packed_git(the_repository);
205204
for (p = get_packed_git(the_repository); p; p = p->next) {
206205
/* we ignore things on alternate path since they are
207206
* not available to the pullers in general.

sha1_name.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ static void find_short_packed_object(struct disambiguate_state *ds)
196196
{
197197
struct packed_git *p;
198198

199-
prepare_packed_git(the_repository);
200199
for (p = get_packed_git(the_repository); p && !ds->ambiguous;
201200
p = p->next)
202201
unique_in_pack(p, ds);
@@ -567,7 +566,6 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
567566
{
568567
struct packed_git *p;
569568

570-
prepare_packed_git(the_repository);
571569
for (p = get_packed_git(the_repository); p; p = p->next)
572570
find_abbrev_len_for_pack(p, mad);
573571
}

0 commit comments

Comments
 (0)