Skip to content

Commit caa68db

Browse files
committed
Merge branch 'sb/packfiles-in-repository' into next
Refactoring of the internal global data structure continues. * sb/packfiles-in-repository: packfile: keep prepare_packed_git() private packfile: allow find_pack_entry to handle arbitrary repositories packfile: add repository argument to find_pack_entry packfile: allow reprepare_packed_git to handle arbitrary repositories packfile: allow prepare_packed_git to handle arbitrary repositories packfile: allow prepare_packed_git_one to handle arbitrary repositories packfile: add repository argument to reprepare_packed_git packfile: add repository argument to prepare_packed_git packfile: add repository argument to prepare_packed_git_one packfile: allow install_packed_git to handle arbitrary repositories packfile: allow rearrange_packed_git to handle arbitrary repositories packfile: allow prepare_packed_git_mru to handle arbitrary repositories
2 parents 93e3475 + 464416a commit caa68db

17 files changed

+58
-67
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();
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
@@ -735,8 +735,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
735735
uint32_t total = 0, count = 0;
736736
struct progress *progress = NULL;
737737

738-
prepare_packed_git();
739-
740738
if (show_progress) {
741739
for (p = get_packed_git(the_repository); p;
742740
p = p->next) {

builtin/gc.c

Lines changed: 1 addition & 2 deletions
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();
178177
for (cnt = 0, p = get_packed_git(the_repository); p; p = p->next) {
179178
if (!p->pack_local)
180179
continue;
@@ -481,7 +480,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
481480
return error(FAILED_RUN, rerere.argv[0]);
482481

483482
report_garbage = report_pack_garbage;
484-
reprepare_packed_git();
483+
reprepare_packed_git(the_repository);
485484
if (pack_garbage.nr > 0)
486485
clean_pack_garbage();
487486

builtin/pack-objects.c

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

3151-
prepare_packed_git();
31523151
if (ignore_packed_keep) {
31533152
struct packed_git *p;
31543153
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();
635-
636634
if (load_all_packs)
637635
load_all();
638636
else

builtin/receive-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "builtin.h"
2+
#include "repository.h"
23
#include "config.h"
34
#include "lockfile.h"
45
#include "pack.h"
@@ -1778,7 +1779,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
17781779
status = finish_command(&child);
17791780
if (status)
17801781
return "index-pack abnormal exit";
1781-
reprepare_packed_git();
1782+
reprepare_packed_git(the_repository);
17821783
}
17831784
return NULL;
17841785
}

bulk-checkin.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
#include "cache.h"
55
#include "bulk-checkin.h"
6+
#include "repository.h"
67
#include "csum-file.h"
78
#include "pack.h"
89
#include "strbuf.h"
@@ -57,7 +58,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
5758

5859
strbuf_release(&packname);
5960
/* Make objects we just wrote available to ourselves */
60-
reprepare_packed_git();
61+
reprepare_packed_git(the_repository);
6162
}
6263

6364
static int already_written(struct bulk_checkin_state *state, struct object_id *oid)

fast-import.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ static void end_packfile(void)
992992
if (!new_p)
993993
die("core git rejected index %s", idx_name);
994994
all_packs[pack_id] = new_p;
995-
install_packed_git(new_p);
995+
install_packed_git(the_repository, new_p);
996996
free(idx_name);
997997

998998
/* Print the boundary */
@@ -3430,7 +3430,6 @@ int cmd_main(int argc, const char **argv)
34303430
rc_free[i].next = &rc_free[i + 1];
34313431
rc_free[cmd_save - 1].next = NULL;
34323432

3433-
prepare_packed_git();
34343433
start_packfile();
34353434
set_die_routine(die_nicely);
34363435
set_checkpoint_signal();

fetch-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cache.h"
2+
#include "repository.h"
23
#include "config.h"
34
#include "lockfile.h"
45
#include "refs.h"
@@ -1567,7 +1568,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
15671568
else
15681569
ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought,
15691570
&si, pack_lockfile);
1570-
reprepare_packed_git();
1571+
reprepare_packed_git(the_repository);
15711572
update_shallow(args, sought, nr_sought, &si);
15721573
clear_shallow_info(&si);
15731574
return ref_cpy;

http-backend.c

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

525525
select_getanyfile(hdr);
526-
prepare_packed_git();
527526
for (p = get_packed_git(the_repository); p; p = p->next) {
528527
if (p->pack_local)
529528
cnt++;

http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ int finish_http_pack_request(struct http_pack_request *preq)
21302130
return -1;
21312131
}
21322132

2133-
install_packed_git(p);
2133+
install_packed_git(the_repository, p);
21342134
free(tmp_idx);
21352135
return 0;
21362136
}

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();
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: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -680,13 +680,13 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
680680
return p;
681681
}
682682

683-
void install_packed_git(struct packed_git *pack)
683+
void install_packed_git(struct repository *r, struct packed_git *pack)
684684
{
685685
if (pack->pack_fd != -1)
686686
pack_open_fds++;
687687

688-
pack->next = the_repository->objects->packed_git;
689-
the_repository->objects->packed_git = pack;
688+
pack->next = r->objects->packed_git;
689+
r->objects->packed_git = pack;
690690
}
691691

692692
void (*report_garbage)(unsigned seen_bits, const char *path);
@@ -735,7 +735,7 @@ static void report_pack_garbage(struct string_list *list)
735735
report_helper(list, seen_bits, first, list->nr);
736736
}
737737

738-
static void prepare_packed_git_one(char *objdir, int local)
738+
static void prepare_packed_git_one(struct repository *r, char *objdir, int local)
739739
{
740740
struct strbuf path = STRBUF_INIT;
741741
size_t dirnamelen;
@@ -768,7 +768,7 @@ static void prepare_packed_git_one(char *objdir, int local)
768768
base_len = path.len;
769769
if (strip_suffix_mem(path.buf, &base_len, ".idx")) {
770770
/* Don't reopen a pack we already have. */
771-
for (p = the_repository->objects->packed_git; p;
771+
for (p = r->objects->packed_git; p;
772772
p = p->next) {
773773
size_t len;
774774
if (strip_suffix(p->pack_name, ".pack", &len) &&
@@ -782,7 +782,7 @@ static void prepare_packed_git_one(char *objdir, int local)
782782
* corresponding .pack file that we can map.
783783
*/
784784
(p = add_packed_git(path.buf, path.len, local)) != NULL)
785-
install_packed_git(p);
785+
install_packed_git(r, p);
786786
}
787787

788788
if (!report_garbage)
@@ -803,6 +803,7 @@ static void prepare_packed_git_one(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
@@ -816,7 +817,7 @@ unsigned long approximate_object_count(void)
816817
unsigned long count;
817818
struct packed_git *p;
818819

819-
prepare_packed_git();
820+
prepare_packed_git(the_repository);
820821
count = 0;
821822
for (p = the_repository->objects->packed_git; p; p = p->next) {
822823
if (open_pack_index(p))
@@ -866,52 +867,54 @@ static int sort_pack(const void *a_, const void *b_)
866867
return -1;
867868
}
868869

869-
static void rearrange_packed_git(void)
870+
static void rearrange_packed_git(struct repository *r)
870871
{
871-
the_repository->objects->packed_git = llist_mergesort(
872-
the_repository->objects->packed_git, get_next_packed_git,
872+
r->objects->packed_git = llist_mergesort(
873+
r->objects->packed_git, get_next_packed_git,
873874
set_next_packed_git, sort_pack);
874875
}
875876

876-
static void prepare_packed_git_mru(void)
877+
static void prepare_packed_git_mru(struct repository *r)
877878
{
878879
struct packed_git *p;
879880

880-
INIT_LIST_HEAD(&the_repository->objects->packed_git_mru);
881+
INIT_LIST_HEAD(&r->objects->packed_git_mru);
881882

882-
for (p = the_repository->objects->packed_git; p; p = p->next)
883-
list_add_tail(&p->mru, &the_repository->objects->packed_git_mru);
883+
for (p = r->objects->packed_git; p; p = p->next)
884+
list_add_tail(&p->mru, &r->objects->packed_git_mru);
884885
}
885886

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

890-
if (the_repository->objects->packed_git_initialized)
891+
if (r->objects->packed_git_initialized)
891892
return;
892-
prepare_packed_git_one(get_object_directory(), 1);
893-
prepare_alt_odb(the_repository);
894-
for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next)
895-
prepare_packed_git_one(alt->path, 0);
896-
rearrange_packed_git();
897-
prepare_packed_git_mru();
898-
the_repository->objects->packed_git_initialized = 1;
893+
prepare_packed_git_one(r, r->objects->objectdir, 1);
894+
prepare_alt_odb(r);
895+
for (alt = r->objects->alt_odb_list; alt; alt = alt->next)
896+
prepare_packed_git_one(r, alt->path, 0);
897+
rearrange_packed_git(r);
898+
prepare_packed_git_mru(r);
899+
r->objects->packed_git_initialized = 1;
899900
}
900901

901-
void reprepare_packed_git(void)
902+
void reprepare_packed_git(struct repository *r)
902903
{
903-
the_repository->objects->approximate_object_count_valid = 0;
904-
the_repository->objects->packed_git_initialized = 0;
905-
prepare_packed_git();
904+
r->objects->approximate_object_count_valid = 0;
905+
r->objects->packed_git_initialized = 0;
906+
prepare_packed_git(r);
906907
}
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

@@ -1834,23 +1837,18 @@ static int fill_pack_entry(const unsigned char *sha1,
18341837
return 1;
18351838
}
18361839

1837-
/*
1838-
* Iff a pack file contains the object named by sha1, return true and
1839-
* store its location to e.
1840-
*/
1841-
int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
1840+
int find_pack_entry(struct repository *r, const unsigned char *sha1, struct pack_entry *e)
18421841
{
18431842
struct list_head *pos;
18441843

1845-
prepare_packed_git();
1846-
if (!the_repository->objects->packed_git)
1844+
prepare_packed_git(r);
1845+
if (!r->objects->packed_git)
18471846
return 0;
18481847

1849-
list_for_each(pos, &the_repository->objects->packed_git_mru) {
1848+
list_for_each(pos, &r->objects->packed_git_mru) {
18501849
struct packed_git *p = list_entry(pos, struct packed_git, mru);
18511850
if (fill_pack_entry(sha1, e, p)) {
1852-
list_move(&p->mru,
1853-
&the_repository->objects->packed_git_mru);
1851+
list_move(&p->mru, &r->objects->packed_git_mru);
18541852
return 1;
18551853
}
18561854
}
@@ -1860,7 +1858,7 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
18601858
int has_sha1_pack(const unsigned char *sha1)
18611859
{
18621860
struct pack_entry e;
1863-
return find_pack_entry(sha1, &e);
1861+
return find_pack_entry(the_repository, sha1, &e);
18641862
}
18651863

18661864
int has_pack_index(const unsigned char *sha1)
@@ -1896,7 +1894,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)
18961894
int r = 0;
18971895
int pack_errors = 0;
18981896

1899-
prepare_packed_git();
1897+
prepare_packed_git(the_repository);
19001898
for (p = the_repository->objects->packed_git; p; p = p->next) {
19011899
if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
19021900
continue;

packfile.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ 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(void);
38-
extern void reprepare_packed_git(void);
39-
extern void install_packed_git(struct packed_git *pack);
37+
extern void reprepare_packed_git(struct repository *r);
38+
extern void install_packed_git(struct repository *r, struct packed_git *pack);
4039

4140
struct packed_git *get_packed_git(struct repository *r);
4241
struct list_head *get_packed_git_mru(struct repository *r);
@@ -131,7 +130,11 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje
131130
extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
132131
extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
133132

134-
extern int find_pack_entry(const unsigned char *sha1, struct pack_entry *e);
133+
/*
134+
* Iff a pack file in the given repository contains the object named by sha1,
135+
* return true and store its location to e.
136+
*/
137+
extern int find_pack_entry(struct repository *r, const unsigned char *sha1, struct pack_entry *e);
135138

136139
extern int has_sha1_pack(const unsigned char *sha1);
137140

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();
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_file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
12681268
}
12691269

12701270
while (1) {
1271-
if (find_pack_entry(real->hash, &e))
1271+
if (find_pack_entry(the_repository, real->hash, &e))
12721272
break;
12731273

12741274
if (flags & OBJECT_INFO_IGNORE_LOOSE)
@@ -1280,8 +1280,8 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
12801280

12811281
/* Not a loose object; someone else may have just packed it. */
12821282
if (!(flags & OBJECT_INFO_QUICK)) {
1283-
reprepare_packed_git();
1284-
if (find_pack_entry(real->hash, &e))
1283+
reprepare_packed_git(the_repository);
1284+
if (find_pack_entry(the_repository, real->hash, &e))
12851285
break;
12861286
}
12871287

@@ -1669,7 +1669,7 @@ static int freshen_loose_object(const unsigned char *sha1)
16691669
static int freshen_packed_object(const unsigned char *sha1)
16701670
{
16711671
struct pack_entry e;
1672-
if (!find_pack_entry(sha1, &e))
1672+
if (!find_pack_entry(the_repository, sha1, &e))
16731673
return 0;
16741674
if (e.p->freshened)
16751675
return 1;

0 commit comments

Comments
 (0)