Commit 2afd01857d2f589c694a247072dbce01528edad8

Edward Thomson 2018-08-19T12:57:29

threads::iterator: use separate repository objects Our thread policies state that we cannot re-use the `git_repository` across threads. Our tests cannot deviate from that. Courtesy of Ximin Luo, https://github.com/infinity0: https://github.com/libgit2/libgit2/issues/4753#issuecomment-412247757

diff --git a/tests/threads/iterator.c b/tests/threads/iterator.c
index 6b86cf1..d93c891 100644
--- a/tests/threads/iterator.c
+++ b/tests/threads/iterator.c
@@ -12,14 +12,16 @@ void test_threads_iterator__cleanup(void)
 static void *run_workdir_iterator(void *arg)
 {
 	int error = 0;
+	git_repository *repo;
 	git_iterator *iter;
 	git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
 	const git_index_entry *entry = NULL;
 
 	iter_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
 
+	cl_git_pass(git_repository_open(&repo, git_repository_path(_repo)));
 	cl_git_pass(git_iterator_for_workdir(
-		&iter, _repo, NULL, NULL, &iter_opts));
+		&iter, repo, NULL, NULL, &iter_opts));
 
 	while (!error) {
 		if (entry && entry->mode == GIT_FILEMODE_TREE) {
@@ -38,6 +40,7 @@ static void *run_workdir_iterator(void *arg)
 	cl_assert_equal_i(GIT_ITEROVER, error);
 
 	git_iterator_free(iter);
+	git_repository_free(repo);
 	giterr_clear();
 	return arg;
 }