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()maint
						commit
						5fb9263295
					
				|  | @ -431,8 +431,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) | ||||||
| 			char *fname, *fname_old; | 			char *fname, *fname_old; | ||||||
|  |  | ||||||
| 			if (!midx_cleared) { | 			if (!midx_cleared) { | ||||||
| 				/* if we move a packfile, it will invalidated the midx */ | 				clear_midx_file(the_repository); | ||||||
| 				clear_midx_file(get_object_directory()); |  | ||||||
| 				midx_cleared = 1; | 				midx_cleared = 1; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | @ -561,6 +560,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix) | ||||||
| 	if (!no_update_server_info) | 	if (!no_update_server_info) | ||||||
| 		update_server_info(0); | 		update_server_info(0); | ||||||
| 	remove_temporary_files(); | 	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(&names, 0); | ||||||
| 	string_list_clear(&rollback, 0); | 	string_list_clear(&rollback, 0); | ||||||
| 	string_list_clear(&existing_packs, 0); | 	string_list_clear(&existing_packs, 0); | ||||||
|  |  | ||||||
							
								
								
									
										26
									
								
								midx.c
								
								
								
								
							
							
						
						
									
										26
									
								
								midx.c
								
								
								
								
							|  | @ -176,9 +176,13 @@ cleanup_fail: | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void close_midx(struct multi_pack_index *m) | void close_midx(struct multi_pack_index *m) | ||||||
| { | { | ||||||
| 	uint32_t i; | 	uint32_t i; | ||||||
|  |  | ||||||
|  | 	if (!m) | ||||||
|  | 		return; | ||||||
|  |  | ||||||
| 	munmap((unsigned char *)m->data, m->data_len); | 	munmap((unsigned char *)m->data, m->data_len); | ||||||
| 	close(m->fd); | 	close(m->fd); | ||||||
| 	m->fd = -1; | 	m->fd = -1; | ||||||
|  | @ -186,7 +190,7 @@ static void close_midx(struct multi_pack_index *m) | ||||||
| 	for (i = 0; i < m->num_packs; i++) { | 	for (i = 0; i < m->num_packs; i++) { | ||||||
| 		if (m->packs[i]) { | 		if (m->packs[i]) { | ||||||
| 			close_pack(m->packs[i]); | 			close_pack(m->packs[i]); | ||||||
| 			free(m->packs); | 			free(m->packs[i]); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	FREE_AND_NULL(m->packs); | 	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; | ||||||
| 	struct multi_pack_index *m_search; | 	struct multi_pack_index *m_search; | ||||||
| 	int config_value; | 	int config_value; | ||||||
|  | 	static int env_value = -1; | ||||||
|  |  | ||||||
| 	if (repo_config_get_bool(r, "core.multipackindex", &config_value) || | 	if (env_value < 0) | ||||||
| 	    !config_value) | 		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; | 		return 0; | ||||||
|  |  | ||||||
| 	for (m_search = r->objects->multi_pack_index; m_search; m_search = m_search->next) | 	for (m_search = r->objects->multi_pack_index; m_search; m_search = m_search->next) | ||||||
|  | @ -914,9 +923,14 @@ cleanup: | ||||||
| 	return 0; | 	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)) { | 	if (remove_path(midx)) { | ||||||
| 		UNLEAK(midx); | 		UNLEAK(midx); | ||||||
|  |  | ||||||
							
								
								
									
										6
									
								
								midx.h
								
								
								
								
							
							
						
						
									
										6
									
								
								midx.h
								
								
								
								
							|  | @ -6,6 +6,8 @@ | ||||||
| struct object_id; | struct object_id; | ||||||
| struct pack_entry; | struct pack_entry; | ||||||
|  |  | ||||||
|  | #define GIT_TEST_MULTI_PACK_INDEX "GIT_TEST_MULTI_PACK_INDEX" | ||||||
|  |  | ||||||
| struct multi_pack_index { | struct multi_pack_index { | ||||||
| 	struct multi_pack_index *next; | 	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 prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local); | ||||||
|  |  | ||||||
| int write_midx_file(const char *object_dir); | 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); | int verify_midx_file(const char *object_dir); | ||||||
|  |  | ||||||
|  | void close_midx(struct multi_pack_index *m); | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | @ -345,6 +345,11 @@ void close_all_packs(struct raw_object_store *o) | ||||||
| 			BUG("want to close pack marked 'do-not-close'"); | 			BUG("want to close pack marked 'do-not-close'"); | ||||||
| 		else | 		else | ||||||
| 			close_pack(p); | 			close_pack(p); | ||||||
|  |  | ||||||
|  | 	if (o->multi_pack_index) { | ||||||
|  | 		close_midx(o->multi_pack_index); | ||||||
|  | 		o->multi_pack_index = NULL; | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  |  | ||||||
							
								
								
									
										4
									
								
								t/README
								
								
								
								
							
							
						
						
									
										4
									
								
								t/README
								
								
								
								
							|  | @ -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 | cache entries and thread minimums. Setting this to 1 will make the | ||||||
| index loading single threaded. | 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 | Naming Tests | ||||||
| ------------ | ------------ | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @ -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)' ' | test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' ' | ||||||
| 	mv .git/objects/pack/$packbitmap.* alt.git/objects/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/" && | 	test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" && | ||||||
| 	echo HEAD | git pack-objects --local --stdout --revs >3b.pack && | 	echo HEAD | git pack-objects --local --stdout --revs >3b.pack && | ||||||
| 	git index-pack 3b.pack && | 	git index-pack 3b.pack && | ||||||
|  |  | ||||||
|  | @ -271,7 +271,7 @@ test_expect_success 'git-fsck incorrect offset' ' | ||||||
|  |  | ||||||
| test_expect_success 'repack removes multi-pack-index' ' | test_expect_success 'repack removes multi-pack-index' ' | ||||||
| 	test_path_is_file $objdir/pack/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 | 	test_path_is_missing $objdir/pack/multi-pack-index | ||||||
| ' | ' | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @ -1558,7 +1558,7 @@ test_expect_success 'O: blank lines not necessary after other commands' ' | ||||||
| 	INPUT_END | 	INPUT_END | ||||||
|  |  | ||||||
| 	git fast-import <input && | 	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^) && | 	test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) && | ||||||
| 	git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual && | 	git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual && | ||||||
| 	test_cmp expect actual | 	test_cmp expect actual | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Junio C Hamano
						Junio C Hamano