Skip to content

Commit 5fb9263

Browse files
committed
Merge branch 'ds/test-multi-pack-index'
Tests for the recently introduced multi-pack index machinery. * ds/test-multi-pack-index: packfile: close multi-pack-index in close_all_packs multi-pack-index: define GIT_TEST_MULTI_PACK_INDEX midx: close multi-pack-index on repack midx: fix broken free() in close_midx()
2 parents 25e4da8 + dc7d664 commit 5fb9263

File tree

8 files changed

+42
-11
lines changed

8 files changed

+42
-11
lines changed

builtin/repack.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
431431
char *fname, *fname_old;
432432

433433
if (!midx_cleared) {
434-
/* if we move a packfile, it will invalidated the midx */
435-
clear_midx_file(get_object_directory());
434+
clear_midx_file(the_repository);
436435
midx_cleared = 1;
437436
}
438437

@@ -561,6 +560,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
561560
if (!no_update_server_info)
562561
update_server_info(0);
563562
remove_temporary_files();
563+
564+
if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
565+
write_midx_file(get_object_directory());
566+
564567
string_list_clear(&names, 0);
565568
string_list_clear(&rollback, 0);
566569
string_list_clear(&existing_packs, 0);

midx.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,21 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
176176
return NULL;
177177
}
178178

179-
static void close_midx(struct multi_pack_index *m)
179+
void close_midx(struct multi_pack_index *m)
180180
{
181181
uint32_t i;
182+
183+
if (!m)
184+
return;
185+
182186
munmap((unsigned char *)m->data, m->data_len);
183187
close(m->fd);
184188
m->fd = -1;
185189

186190
for (i = 0; i < m->num_packs; i++) {
187191
if (m->packs[i]) {
188192
close_pack(m->packs[i]);
189-
free(m->packs);
193+
free(m->packs[i]);
190194
}
191195
}
192196
FREE_AND_NULL(m->packs);
@@ -331,9 +335,14 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i
331335
struct multi_pack_index *m;
332336
struct multi_pack_index *m_search;
333337
int config_value;
338+
static int env_value = -1;
334339

335-
if (repo_config_get_bool(r, "core.multipackindex", &config_value) ||
336-
!config_value)
340+
if (env_value < 0)
341+
env_value = git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0);
342+
343+
if (!env_value &&
344+
(repo_config_get_bool(r, "core.multipackindex", &config_value) ||
345+
!config_value))
337346
return 0;
338347

339348
for (m_search = r->objects->multi_pack_index; m_search; m_search = m_search->next)
@@ -914,9 +923,14 @@ int write_midx_file(const char *object_dir)
914923
return 0;
915924
}
916925

917-
void clear_midx_file(const char *object_dir)
926+
void clear_midx_file(struct repository *r)
918927
{
919-
char *midx = get_midx_filename(object_dir);
928+
char *midx = get_midx_filename(r->objects->objectdir);
929+
930+
if (r->objects && r->objects->multi_pack_index) {
931+
close_midx(r->objects->multi_pack_index);
932+
r->objects->multi_pack_index = NULL;
933+
}
920934

921935
if (remove_path(midx)) {
922936
UNLEAK(midx);

midx.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
struct object_id;
77
struct pack_entry;
88

9+
#define GIT_TEST_MULTI_PACK_INDEX "GIT_TEST_MULTI_PACK_INDEX"
10+
911
struct multi_pack_index {
1012
struct multi_pack_index *next;
1113

@@ -45,7 +47,9 @@ int midx_contains_pack(struct multi_pack_index *m, const char *idx_name);
4547
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);
4648

4749
int write_midx_file(const char *object_dir);
48-
void clear_midx_file(const char *object_dir);
50+
void clear_midx_file(struct repository *r);
4951
int verify_midx_file(const char *object_dir);
5052

53+
void close_midx(struct multi_pack_index *m);
54+
5155
#endif

packfile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ void close_all_packs(struct raw_object_store *o)
345345
BUG("want to close pack marked 'do-not-close'");
346346
else
347347
close_pack(p);
348+
349+
if (o->multi_pack_index) {
350+
close_midx(o->multi_pack_index);
351+
o->multi_pack_index = NULL;
352+
}
348353
}
349354

350355
/*

t/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ of the index for the whole test suite by bypassing the default number of
344344
cache entries and thread minimums. Setting this to 1 will make the
345345
index loading single threaded.
346346

347+
GIT_TEST_MULTI_PACK_INDEX=<boolean>, when true, forces the multi-pack-
348+
index to be written after every 'git repack' command, and overrides the
349+
'core.multiPackIndex' setting to true.
350+
347351
Naming Tests
348352
------------
349353

t/t5310-pack-bitmaps.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pa
191191

192192
test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
193193
mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
194+
rm -f .git/objects/pack/multi-pack-index &&
194195
test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
195196
echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
196197
git index-pack 3b.pack &&

t/t5319-multi-pack-index.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ test_expect_success 'git-fsck incorrect offset' '
271271

272272
test_expect_success 'repack removes multi-pack-index' '
273273
test_path_is_file $objdir/pack/multi-pack-index &&
274-
git repack -adf &&
274+
GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf &&
275275
test_path_is_missing $objdir/pack/multi-pack-index
276276
'
277277

t/t9300-fast-import.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ test_expect_success 'O: blank lines not necessary after other commands' '
15581558
INPUT_END
15591559
15601560
git fast-import <input &&
1561-
test 8 = $(find .git/objects/pack -type f | wc -l) &&
1561+
test 8 = $(find .git/objects/pack -type f | grep -v multi-pack-index | wc -l) &&
15621562
test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
15631563
git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
15641564
test_cmp expect actual

0 commit comments

Comments
 (0)