Skip to content

Commit a80d72d

Browse files
stefanbellergitster
authored andcommitted
object-store: move packed_git and packed_git_mru to object store
In a process with multiple repositories open, packfile accessors should be associated to a single repository and not shared globally. Move packed_git and packed_git_mru into the_repository and adjust callers to reflect this. [nd: while at there, wrap access to these two fields in get_packed_git() and get_packed_git_mru(). This allows us to lazily initialize these fields without caller doing that explicitly] Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 97501e9 commit a80d72d

22 files changed

+128
-74
lines changed

builtin/count-objects.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "cache.h"
88
#include "config.h"
99
#include "dir.h"
10+
#include "repository.h"
1011
#include "builtin.h"
1112
#include "parse-options.h"
1213
#include "quote.h"
@@ -121,9 +122,9 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
121122
struct strbuf loose_buf = STRBUF_INIT;
122123
struct strbuf pack_buf = STRBUF_INIT;
123124
struct strbuf garbage_buf = STRBUF_INIT;
124-
if (!packed_git)
125+
if (!get_packed_git(the_repository))
125126
prepare_packed_git();
126-
for (p = packed_git; p; p = p->next) {
127+
for (p = get_packed_git(the_repository); p; p = p->next) {
127128
if (!p->pack_local)
128129
continue;
129130
if (open_pack_index(p))

builtin/fsck.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,15 +732,17 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
732732
prepare_packed_git();
733733

734734
if (show_progress) {
735-
for (p = packed_git; p; p = p->next) {
735+
for (p = get_packed_git(the_repository); p;
736+
p = p->next) {
736737
if (open_pack_index(p))
737738
continue;
738739
total += p->num_objects;
739740
}
740741

741742
progress = start_progress(_("Checking objects"), total);
742743
}
743-
for (p = packed_git; p; p = p->next) {
744+
for (p = get_packed_git(the_repository); p;
745+
p = p->next) {
744746
/* verify gives error messages itself */
745747
if (verify_pack(p, fsck_obj_buffer,
746748
progress, count))

builtin/gc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
#include "builtin.h"
14+
#include "repository.h"
1415
#include "config.h"
1516
#include "tempfile.h"
1617
#include "lockfile.h"
@@ -20,6 +21,7 @@
2021
#include "argv-array.h"
2122
#include "commit.h"
2223
#include "packfile.h"
24+
#include "object-store.h"
2325

2426
#define FAILED_RUN "failed to run %s"
2527

@@ -173,7 +175,7 @@ static int too_many_packs(void)
173175
return 0;
174176

175177
prepare_packed_git();
176-
for (cnt = 0, p = packed_git; p; p = p->next) {
178+
for (cnt = 0, p = get_packed_git(the_repository); p; p = p->next) {
177179
if (!p->pack_local)
178180
continue;
179181
if (p->pack_keep)

builtin/index-pack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "streaming.h"
1414
#include "thread-utils.h"
1515
#include "packfile.h"
16+
#include "object-store.h"
1617

1718
static const char index_pack_usage[] =
1819
"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";

builtin/pack-objects.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "builtin.h"
22
#include "cache.h"
3+
#include "repository.h"
34
#include "config.h"
45
#include "attr.h"
56
#include "object.h"
@@ -28,6 +29,7 @@
2829
#include "argv-array.h"
2930
#include "list.h"
3031
#include "packfile.h"
32+
#include "object-store.h"
3133

3234
static const char *pack_usage[] = {
3335
N_("git pack-objects --stdout [<options>...] [< <ref-list> | < <object-list>]"),
@@ -1025,8 +1027,7 @@ static int want_object_in_pack(const struct object_id *oid,
10251027
if (want != -1)
10261028
return want;
10271029
}
1028-
1029-
list_for_each(pos, &packed_git_mru) {
1030+
list_for_each(pos, get_packed_git_mru(the_repository)) {
10301031
struct packed_git *p = list_entry(pos, struct packed_git, mru);
10311032
off_t offset;
10321033

@@ -1044,7 +1045,8 @@ static int want_object_in_pack(const struct object_id *oid,
10441045
}
10451046
want = want_found_object(exclude, p);
10461047
if (!exclude && want > 0)
1047-
list_move(&p->mru, &packed_git_mru);
1048+
list_move(&p->mru,
1049+
get_packed_git_mru(the_repository));
10481050
if (want != -1)
10491051
return want;
10501052
}
@@ -2673,7 +2675,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
26732675

26742676
memset(&in_pack, 0, sizeof(in_pack));
26752677

2676-
for (p = packed_git; p; p = p->next) {
2678+
for (p = get_packed_git(the_repository); p; p = p->next) {
26772679
struct object_id oid;
26782680
struct object *o;
26792681

@@ -2736,7 +2738,8 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
27362738
static struct packed_git *last_found = (void *)1;
27372739
struct packed_git *p;
27382740

2739-
p = (last_found != (void *)1) ? last_found : packed_git;
2741+
p = (last_found != (void *)1) ? last_found :
2742+
get_packed_git(the_repository);
27402743

27412744
while (p) {
27422745
if ((!p->pack_local || p->pack_keep) &&
@@ -2745,7 +2748,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
27452748
return 1;
27462749
}
27472750
if (p == last_found)
2748-
p = packed_git;
2751+
p = get_packed_git(the_repository);
27492752
else
27502753
p = p->next;
27512754
if (p == last_found)
@@ -2781,7 +2784,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
27812784
uint32_t i;
27822785
struct object_id oid;
27832786

2784-
for (p = packed_git; p; p = p->next) {
2787+
for (p = get_packed_git(the_repository); p; p = p->next) {
27852788
if (!p->pack_local || p->pack_keep)
27862789
continue;
27872790

@@ -3152,7 +3155,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
31523155
prepare_packed_git();
31533156
if (ignore_packed_keep) {
31543157
struct packed_git *p;
3155-
for (p = packed_git; p; p = p->next)
3158+
for (p = get_packed_git(the_repository); p; p = p->next)
31563159
if (p->pack_local && p->pack_keep)
31573160
break;
31583161
if (!p) /* no keep-able packs found */
@@ -3165,7 +3168,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
31653168
* also covers non-local objects
31663169
*/
31673170
struct packed_git *p;
3168-
for (p = packed_git; p; p = p->next) {
3171+
for (p = get_packed_git(the_repository); p; p = p->next) {
31693172
if (!p->pack_local) {
31703173
have_non_local_packs = 1;
31713174
break;

builtin/pack-redundant.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
*/
88

99
#include "builtin.h"
10+
#include "repository.h"
1011
#include "packfile.h"
12+
#include "object-store.h"
1113

1214
#define BLKSIZE 512
1315

@@ -571,7 +573,7 @@ static struct pack_list * add_pack(struct packed_git *p)
571573

572574
static struct pack_list * add_pack_file(const char *filename)
573575
{
574-
struct packed_git *p = packed_git;
576+
struct packed_git *p = get_packed_git(the_repository);
575577

576578
if (strlen(filename) < 40)
577579
die("Bad pack filename: %s", filename);
@@ -586,7 +588,7 @@ static struct pack_list * add_pack_file(const char *filename)
586588

587589
static void load_all(void)
588590
{
589-
struct packed_git *p = packed_git;
591+
struct packed_git *p = get_packed_git(the_repository);
590592

591593
while (p) {
592594
add_pack(p);

cache.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,35 +1585,6 @@ struct pack_window {
15851585
unsigned int inuse_cnt;
15861586
};
15871587

1588-
extern struct packed_git {
1589-
struct packed_git *next;
1590-
struct list_head mru;
1591-
struct pack_window *windows;
1592-
off_t pack_size;
1593-
const void *index_data;
1594-
size_t index_size;
1595-
uint32_t num_objects;
1596-
uint32_t num_bad_objects;
1597-
unsigned char *bad_object_sha1;
1598-
int index_version;
1599-
time_t mtime;
1600-
int pack_fd;
1601-
unsigned pack_local:1,
1602-
pack_keep:1,
1603-
freshened:1,
1604-
do_not_close:1,
1605-
pack_promisor:1;
1606-
unsigned char sha1[20];
1607-
struct revindex_entry *revindex;
1608-
/* something like ".git/objects/pack/xxxxx.pack" */
1609-
char pack_name[FLEX_ARRAY]; /* more */
1610-
} *packed_git;
1611-
1612-
/*
1613-
* A most-recently-used ordered version of the packed_git list.
1614-
*/
1615-
extern struct list_head packed_git_mru;
1616-
16171588
struct pack_entry {
16181589
off_t offset;
16191590
unsigned char sha1[20];

fast-import.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Format of STDIN stream:
154154

155155
#include "builtin.h"
156156
#include "cache.h"
157+
#include "repository.h"
157158
#include "config.h"
158159
#include "lockfile.h"
159160
#include "object.h"
@@ -168,6 +169,7 @@ Format of STDIN stream:
168169
#include "dir.h"
169170
#include "run-command.h"
170171
#include "packfile.h"
172+
#include "object-store.h"
171173

172174
#define PACK_ID_BITS 16
173175
#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
@@ -1110,7 +1112,8 @@ static int store_object(
11101112
if (e->idx.offset) {
11111113
duplicate_count_by_type[type]++;
11121114
return 1;
1113-
} else if (find_sha1_pack(oid.hash, packed_git)) {
1115+
} else if (find_sha1_pack(oid.hash,
1116+
get_packed_git(the_repository))) {
11141117
e->type = type;
11151118
e->pack_id = MAX_PACK_ID;
11161119
e->idx.offset = 1; /* just not zero! */
@@ -1305,7 +1308,8 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
13051308
duplicate_count_by_type[OBJ_BLOB]++;
13061309
truncate_pack(&checkpoint);
13071310

1308-
} else if (find_sha1_pack(oid.hash, packed_git)) {
1311+
} else if (find_sha1_pack(oid.hash,
1312+
get_packed_git(the_repository))) {
13091313
e->type = OBJ_BLOB;
13101314
e->pack_id = MAX_PACK_ID;
13111315
e->idx.offset = 1; /* just not zero! */

http-backend.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "cache.h"
22
#include "config.h"
3+
#include "repository.h"
34
#include "refs.h"
45
#include "pkt-line.h"
56
#include "object.h"
@@ -10,6 +11,7 @@
1011
#include "url.h"
1112
#include "argv-array.h"
1213
#include "packfile.h"
14+
#include "object-store.h"
1315

1416
static const char content_type[] = "Content-Type";
1517
static const char content_length[] = "Content-Length";
@@ -518,13 +520,13 @@ static void get_info_packs(struct strbuf *hdr, char *arg)
518520

519521
select_getanyfile(hdr);
520522
prepare_packed_git();
521-
for (p = packed_git; p; p = p->next) {
523+
for (p = get_packed_git(the_repository); p; p = p->next) {
522524
if (p->pack_local)
523525
cnt++;
524526
}
525527

526528
strbuf_grow(&buf, cnt * 53 + 2);
527-
for (p = packed_git; p; p = p->next) {
529+
for (p = get_packed_git(the_repository); p; p = p->next) {
528530
if (p->pack_local)
529531
strbuf_addf(&buf, "P %s\n", p->pack_name + objdirlen + 6);
530532
}

http-push.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "sigchain.h"
1313
#include "argv-array.h"
1414
#include "packfile.h"
15+
#include "object-store.h"
1516

1617
#ifdef EXPAT_NEEDS_XMLPARSE_H
1718
#include <xmlparse.h>

0 commit comments

Comments
 (0)