Skip to content

Commit d0547f1

Browse files
committed
Merge branch 'ds/midx-too-many-packs' into jch
The code to generate the multi-pack idx file was not prepared to see too many packfiles and ran out of open file descriptor, which has been corrected. * ds/midx-too-many-packs: midx: add packs to packed_git linked list midx: pass a repository pointer
2 parents 5bbfaa6 + af96fe3 commit d0547f1

File tree

7 files changed

+51
-47
lines changed

7 files changed

+51
-47
lines changed

builtin/multi-pack-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int cmd_multi_pack_index(int argc, const char **argv,
4646
if (!strcmp(argv[0], "write"))
4747
return write_midx_file(opts.object_dir);
4848
if (!strcmp(argv[0], "verify"))
49-
return verify_midx_file(opts.object_dir);
49+
return verify_midx_file(the_repository, opts.object_dir);
5050

5151
die(_("unrecognized verb: %s"), argv[0]);
5252
}

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ static int want_object_in_pack(const struct object_id *oid,
10801080

10811081
for (m = get_multi_pack_index(the_repository); m; m = m->next) {
10821082
struct pack_entry e;
1083-
if (fill_midx_entry(oid, &e, m)) {
1083+
if (fill_midx_entry(the_repository, oid, &e, m)) {
10841084
struct packed_git *p = e.p;
10851085
off_t offset;
10861086

midx.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,17 @@ void close_midx(struct multi_pack_index *m)
192192
m->fd = -1;
193193

194194
for (i = 0; i < m->num_packs; i++) {
195-
if (m->packs[i]) {
196-
close_pack(m->packs[i]);
197-
free(m->packs[i]);
198-
}
195+
if (m->packs[i])
196+
m->packs[i]->multi_pack_index = 0;
199197
}
200198
FREE_AND_NULL(m->packs);
201199
FREE_AND_NULL(m->pack_names);
202200
}
203201

204-
int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
202+
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id)
205203
{
206204
struct strbuf pack_name = STRBUF_INIT;
205+
struct packed_git *p;
207206

208207
if (pack_int_id >= m->num_packs)
209208
die(_("bad pack-int-id: %u (%u total packs)"),
@@ -215,9 +214,18 @@ int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
215214
strbuf_addf(&pack_name, "%s/pack/%s", m->object_dir,
216215
m->pack_names[pack_int_id]);
217216

218-
m->packs[pack_int_id] = add_packed_git(pack_name.buf, pack_name.len, m->local);
217+
p = add_packed_git(pack_name.buf, pack_name.len, m->local);
219218
strbuf_release(&pack_name);
220-
return !m->packs[pack_int_id];
219+
220+
if (!p)
221+
return 1;
222+
223+
p->multi_pack_index = 1;
224+
m->packs[pack_int_id] = p;
225+
install_packed_git(r, p);
226+
list_add_tail(&p->mru, &r->objects->packed_git_mru);
227+
228+
return 0;
221229
}
222230

223231
int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result)
@@ -261,7 +269,10 @@ static uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos)
261269
return get_be32(m->chunk_object_offsets + pos * MIDX_CHUNK_OFFSET_WIDTH);
262270
}
263271

264-
static int nth_midxed_pack_entry(struct multi_pack_index *m, struct pack_entry *e, uint32_t pos)
272+
static int nth_midxed_pack_entry(struct repository *r,
273+
struct multi_pack_index *m,
274+
struct pack_entry *e,
275+
uint32_t pos)
265276
{
266277
uint32_t pack_int_id;
267278
struct packed_git *p;
@@ -271,7 +282,7 @@ static int nth_midxed_pack_entry(struct multi_pack_index *m, struct pack_entry *
271282

272283
pack_int_id = nth_midxed_pack_int_id(m, pos);
273284

274-
if (prepare_midx_pack(m, pack_int_id))
285+
if (prepare_midx_pack(r, m, pack_int_id))
275286
die(_("error preparing packfile from multi-pack-index"));
276287
p = m->packs[pack_int_id];
277288

@@ -301,14 +312,17 @@ static int nth_midxed_pack_entry(struct multi_pack_index *m, struct pack_entry *
301312
return 1;
302313
}
303314

304-
int fill_midx_entry(const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m)
315+
int fill_midx_entry(struct repository * r,
316+
const struct object_id *oid,
317+
struct pack_entry *e,
318+
struct multi_pack_index *m)
305319
{
306320
uint32_t pos;
307321

308322
if (!bsearch_midx(oid, m, &pos))
309323
return 0;
310324

311-
return nth_midxed_pack_entry(m, e, pos);
325+
return nth_midxed_pack_entry(r, m, e, pos);
312326
}
313327

314328
/* Match "foo.idx" against either "foo.pack" _or_ "foo.idx". */
@@ -1020,7 +1034,7 @@ static int compare_pair_pos_vs_id(const void *_a, const void *_b)
10201034
display_progress(progress, _n); \
10211035
} while (0)
10221036

1023-
int verify_midx_file(const char *object_dir)
1037+
int verify_midx_file(struct repository *r, const char *object_dir)
10241038
{
10251039
struct pair_pos_vs_id *pairs = NULL;
10261040
uint32_t i;
@@ -1034,7 +1048,7 @@ int verify_midx_file(const char *object_dir)
10341048
progress = start_progress(_("Looking for referenced packfiles"),
10351049
m->num_packs);
10361050
for (i = 0; i < m->num_packs; i++) {
1037-
if (prepare_midx_pack(m, i))
1051+
if (prepare_midx_pack(r, m, i))
10381052
midx_report("failed to load pack in position %d", i);
10391053

10401054
display_progress(progress, i + 1);
@@ -1099,7 +1113,7 @@ int verify_midx_file(const char *object_dir)
10991113

11001114
nth_midxed_object_oid(&oid, m, pairs[i].pos);
11011115

1102-
if (!fill_midx_entry(&oid, &e, m)) {
1116+
if (!fill_midx_entry(r, &oid, &e, m)) {
11031117
midx_report(_("failed to load pack entry for oid[%d] = %s"),
11041118
pairs[i].pos, oid_to_hex(&oid));
11051119
continue;

midx.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
struct object_id;
77
struct pack_entry;
8+
struct repository;
89

910
#define GIT_TEST_MULTI_PACK_INDEX "GIT_TEST_MULTI_PACK_INDEX"
1011

@@ -37,18 +38,18 @@ struct multi_pack_index {
3738
};
3839

3940
struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
40-
int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id);
41+
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);
4142
int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result);
4243
struct object_id *nth_midxed_object_oid(struct object_id *oid,
4344
struct multi_pack_index *m,
4445
uint32_t n);
45-
int fill_midx_entry(const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m);
46+
int fill_midx_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m);
4647
int midx_contains_pack(struct multi_pack_index *m, const char *idx_or_pack_name);
4748
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);
4849

4950
int write_midx_file(const char *object_dir);
5051
void clear_midx_file(struct repository *r);
51-
int verify_midx_file(const char *object_dir);
52+
int verify_midx_file(struct repository *r, const char *object_dir);
5253

5354
void close_midx(struct multi_pack_index *m);
5455

object-store.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ struct packed_git {
7676
pack_keep_in_core:1,
7777
freshened:1,
7878
do_not_close:1,
79-
pack_promisor:1;
79+
pack_promisor:1,
80+
multi_pack_index:1;
8081
unsigned char hash[GIT_MAX_RAWSZ];
8182
struct revindex_entry *revindex;
8283
/* something like ".git/objects/pack/xxxxx.pack" */
@@ -128,12 +129,6 @@ struct raw_object_store {
128129
/* A most-recently-used ordered version of the packed_git list. */
129130
struct list_head packed_git_mru;
130131

131-
/*
132-
* A linked list containing all packfiles, starting with those
133-
* contained in the multi_pack_index.
134-
*/
135-
struct packed_git *all_packs;
136-
137132
/*
138133
* A fast, rough count of the number of objects in the repository.
139134
* These two fields are not meant for direct access. Use

packfile.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -994,8 +994,6 @@ static void prepare_packed_git(struct repository *r)
994994
}
995995
rearrange_packed_git(r);
996996

997-
r->objects->all_packs = NULL;
998-
999997
prepare_packed_git_mru(r);
1000998
r->objects->packed_git_initialized = 1;
1001999
}
@@ -1026,26 +1024,16 @@ struct multi_pack_index *get_multi_pack_index(struct repository *r)
10261024

10271025
struct packed_git *get_all_packs(struct repository *r)
10281026
{
1029-
prepare_packed_git(r);
1030-
1031-
if (!r->objects->all_packs) {
1032-
struct packed_git *p = r->objects->packed_git;
1033-
struct multi_pack_index *m;
1034-
1035-
for (m = r->objects->multi_pack_index; m; m = m->next) {
1036-
uint32_t i;
1037-
for (i = 0; i < m->num_packs; i++) {
1038-
if (!prepare_midx_pack(m, i)) {
1039-
m->packs[i]->next = p;
1040-
p = m->packs[i];
1041-
}
1042-
}
1043-
}
1027+
struct multi_pack_index *m;
10441028

1045-
r->objects->all_packs = p;
1029+
prepare_packed_git(r);
1030+
for (m = r->objects->multi_pack_index; m; m = m->next) {
1031+
uint32_t i;
1032+
for (i = 0; i < m->num_packs; i++)
1033+
prepare_midx_pack(r, m, i);
10461034
}
10471035

1048-
return r->objects->all_packs;
1036+
return r->objects->packed_git;
10491037
}
10501038

10511039
struct list_head *get_packed_git_mru(struct repository *r)
@@ -1998,13 +1986,13 @@ int find_pack_entry(struct repository *r, const struct object_id *oid, struct pa
19981986
return 0;
19991987

20001988
for (m = r->objects->multi_pack_index; m; m = m->next) {
2001-
if (fill_midx_entry(oid, e, m))
1989+
if (fill_midx_entry(r, oid, e, m))
20021990
return 1;
20031991
}
20041992

20051993
list_for_each(pos, &r->objects->packed_git_mru) {
20061994
struct packed_git *p = list_entry(pos, struct packed_git, mru);
2007-
if (fill_pack_entry(oid, e, p)) {
1995+
if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) {
20081996
list_move(&p->mru, &r->objects->packed_git_mru);
20091997
return 1;
20101998
}

sha1-name.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ static void unique_in_pack(struct packed_git *p,
157157
uint32_t num, i, first = 0;
158158
const struct object_id *current = NULL;
159159

160+
if (p->multi_pack_index)
161+
return;
162+
160163
if (open_pack_index(p) || !p->num_objects)
161164
return;
162165

@@ -625,6 +628,9 @@ static void find_abbrev_len_for_pack(struct packed_git *p,
625628
struct object_id oid;
626629
const struct object_id *mad_oid;
627630

631+
if (p->multi_pack_index)
632+
return;
633+
628634
if (open_pack_index(p) || !p->num_objects)
629635
return;
630636

0 commit comments

Comments
 (0)