1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-09 17:16:34 +02:00

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()
This commit is contained in:
Junio C Hamano 2018-11-13 22:37:19 +09:00
commit 5fb9263295
8 changed files with 42 additions and 11 deletions

View File

@ -431,8 +431,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
char *fname, *fname_old;
if (!midx_cleared) {
/* if we move a packfile, it will invalidated the midx */
clear_midx_file(get_object_directory());
clear_midx_file(the_repository);
midx_cleared = 1;
}
@ -561,6 +560,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
if (!no_update_server_info)
update_server_info(0);
remove_temporary_files();
if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
write_midx_file(get_object_directory());
string_list_clear(&names, 0);
string_list_clear(&rollback, 0);
string_list_clear(&existing_packs, 0);

26
midx.c
View File

@ -176,9 +176,13 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
return NULL;
}
static void close_midx(struct multi_pack_index *m)
void close_midx(struct multi_pack_index *m)
{
uint32_t i;
if (!m)
return;
munmap((unsigned char *)m->data, m->data_len);
close(m->fd);
m->fd = -1;
@ -186,7 +190,7 @@ static void close_midx(struct multi_pack_index *m)
for (i = 0; i < m->num_packs; i++) {
if (m->packs[i]) {
close_pack(m->packs[i]);
free(m->packs);
free(m->packs[i]);
}
}
FREE_AND_NULL(m->packs);
@ -331,9 +335,14 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i
struct multi_pack_index *m;
struct multi_pack_index *m_search;
int config_value;
static int env_value = -1;
if (repo_config_get_bool(r, "core.multipackindex", &config_value) ||
!config_value)
if (env_value < 0)
env_value = git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0);
if (!env_value &&
(repo_config_get_bool(r, "core.multipackindex", &config_value) ||
!config_value))
return 0;
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)
return 0;
}
void clear_midx_file(const char *object_dir)
void clear_midx_file(struct repository *r)
{
char *midx = get_midx_filename(object_dir);
char *midx = get_midx_filename(r->objects->objectdir);
if (r->objects && r->objects->multi_pack_index) {
close_midx(r->objects->multi_pack_index);
r->objects->multi_pack_index = NULL;
}
if (remove_path(midx)) {
UNLEAK(midx);

6
midx.h
View File

@ -6,6 +6,8 @@
struct object_id;
struct pack_entry;
#define GIT_TEST_MULTI_PACK_INDEX "GIT_TEST_MULTI_PACK_INDEX"
struct multi_pack_index {
struct multi_pack_index *next;
@ -45,7 +47,9 @@ int midx_contains_pack(struct multi_pack_index *m, const char *idx_name);
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);
int write_midx_file(const char *object_dir);
void clear_midx_file(const char *object_dir);
void clear_midx_file(struct repository *r);
int verify_midx_file(const char *object_dir);
void close_midx(struct multi_pack_index *m);
#endif

View File

@ -345,6 +345,11 @@ void close_all_packs(struct raw_object_store *o)
BUG("want to close pack marked 'do-not-close'");
else
close_pack(p);
if (o->multi_pack_index) {
close_midx(o->multi_pack_index);
o->multi_pack_index = NULL;
}
}
/*

View File

@ -344,6 +344,10 @@ of the index for the whole test suite by bypassing the default number of
cache entries and thread minimums. Setting this to 1 will make the
index loading single threaded.
GIT_TEST_MULTI_PACK_INDEX=<boolean>, when true, forces the multi-pack-
index to be written after every 'git repack' command, and overrides the
'core.multiPackIndex' setting to true.
Naming Tests
------------

View File

@ -191,6 +191,7 @@ test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pa
test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
rm -f .git/objects/pack/multi-pack-index &&
test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
git index-pack 3b.pack &&

View File

@ -271,7 +271,7 @@ test_expect_success 'git-fsck incorrect offset' '
test_expect_success 'repack removes multi-pack-index' '
test_path_is_file $objdir/pack/multi-pack-index &&
git repack -adf &&
GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf &&
test_path_is_missing $objdir/pack/multi-pack-index
'

View File

@ -1558,7 +1558,7 @@ test_expect_success 'O: blank lines not necessary after other commands' '
INPUT_END
git fast-import <input &&
test 8 = $(find .git/objects/pack -type f | wc -l) &&
test 8 = $(find .git/objects/pack -type f | grep -v multi-pack-index | wc -l) &&
test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
test_cmp expect actual