threads::diff: use separate git_repository objects Our thread policies state that we cannot re-use the `git_repository` across threads. Our tests cannot deviate from that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
diff --git a/tests/threads/diff.c b/tests/threads/diff.c
index 2560402..ab34b32 100644
--- a/tests/threads/diff.c
+++ b/tests/threads/diff.c
@@ -76,26 +76,29 @@ static void free_trees(void)
static void *run_index_diffs(void *arg)
{
int thread = *(int *)arg;
+ git_repository *repo;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff *diff = NULL;
size_t i;
int exp[4] = { 0, 0, 0, 0 };
+ cl_git_pass(git_repository_open(&repo, git_repository_path(_repo)));
+
switch (thread & 0x03) {
case 0: /* diff index to workdir */;
- cl_git_pass(git_diff_index_to_workdir(&diff, _repo, NULL, &opts));
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts));
break;
case 1: /* diff tree 'a' to index */;
- cl_git_pass(git_diff_tree_to_index(&diff, _repo, _a, NULL, &opts));
+ cl_git_pass(git_diff_tree_to_index(&diff, repo, _a, NULL, &opts));
break;
case 2: /* diff tree 'b' to index */;
- cl_git_pass(git_diff_tree_to_index(&diff, _repo, _b, NULL, &opts));
+ cl_git_pass(git_diff_tree_to_index(&diff, repo, _b, NULL, &opts));
break;
case 3: /* diff index to workdir (explicit index) */;
{
git_index *idx;
- cl_git_pass(git_repository_index(&idx, _repo));
- cl_git_pass(git_diff_index_to_workdir(&diff, _repo, idx, &opts));
+ cl_git_pass(git_repository_index(&idx, repo));
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, idx, &opts));
git_index_free(idx);
break;
}
@@ -132,6 +135,7 @@ static void *run_index_diffs(void *arg)
}
git_diff_free(diff);
+ git_repository_free(repo);
giterr_clear();
return arg;
@@ -152,8 +156,10 @@ static void *run_index_diffs_with_modifier(void *arg)
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff *diff = NULL;
git_index *idx = NULL;
+ git_repository *repo;
- cl_git_pass(git_repository_index(&idx, _repo));
+ cl_git_pass(git_repository_open(&repo, git_repository_path(_repo)));
+ cl_git_pass(git_repository_index(&idx, repo));
/* have first thread altering the index as we go */
if (thread == 0) {
@@ -176,17 +182,17 @@ static void *run_index_diffs_with_modifier(void *arg)
switch (thread & 0x03) {
case 0: /* diff index to workdir */;
- cl_git_pass(git_diff_index_to_workdir(&diff, _repo, idx, &opts));
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, idx, &opts));
break;
case 1: /* diff tree 'a' to index */;
- cl_git_pass(git_diff_tree_to_index(&diff, _repo, _a, idx, &opts));
+ cl_git_pass(git_diff_tree_to_index(&diff, repo, _a, idx, &opts));
break;
case 2: /* diff tree 'b' to index */;
- cl_git_pass(git_diff_tree_to_index(&diff, _repo, _b, idx, &opts));
+ cl_git_pass(git_diff_tree_to_index(&diff, repo, _b, idx, &opts));
break;
case 3: /* diff index to workdir reversed */;
opts.flags |= GIT_DIFF_REVERSE;
- cl_git_pass(git_diff_index_to_workdir(&diff, _repo, idx, &opts));
+ cl_git_pass(git_diff_index_to_workdir(&diff, repo, idx, &opts));
break;
}
@@ -196,6 +202,7 @@ static void *run_index_diffs_with_modifier(void *arg)
done:
git_index_free(idx);
+ git_repository_free(repo);
giterr_clear();
return arg;