Skip to content

Commit cada553

Browse files
authored
Merge pull request libgit2#4754 from libgit2/ethomson/threads
threads::diff: use separate git_repository objects
2 parents c1ef58a + 2afd018 commit cada553

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

tests/threads/diff.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,29 @@ static void free_trees(void)
7676
static void *run_index_diffs(void *arg)
7777
{
7878
int thread = *(int *)arg;
79+
git_repository *repo;
7980
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
8081
git_diff *diff = NULL;
8182
size_t i;
8283
int exp[4] = { 0, 0, 0, 0 };
8384

85+
cl_git_pass(git_repository_open(&repo, git_repository_path(_repo)));
86+
8487
switch (thread & 0x03) {
8588
case 0: /* diff index to workdir */;
86-
cl_git_pass(git_diff_index_to_workdir(&diff, _repo, NULL, &opts));
89+
cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts));
8790
break;
8891
case 1: /* diff tree 'a' to index */;
89-
cl_git_pass(git_diff_tree_to_index(&diff, _repo, _a, NULL, &opts));
92+
cl_git_pass(git_diff_tree_to_index(&diff, repo, _a, NULL, &opts));
9093
break;
9194
case 2: /* diff tree 'b' to index */;
92-
cl_git_pass(git_diff_tree_to_index(&diff, _repo, _b, NULL, &opts));
95+
cl_git_pass(git_diff_tree_to_index(&diff, repo, _b, NULL, &opts));
9396
break;
9497
case 3: /* diff index to workdir (explicit index) */;
9598
{
9699
git_index *idx;
97-
cl_git_pass(git_repository_index(&idx, _repo));
98-
cl_git_pass(git_diff_index_to_workdir(&diff, _repo, idx, &opts));
100+
cl_git_pass(git_repository_index(&idx, repo));
101+
cl_git_pass(git_diff_index_to_workdir(&diff, repo, idx, &opts));
99102
git_index_free(idx);
100103
break;
101104
}
@@ -132,6 +135,7 @@ static void *run_index_diffs(void *arg)
132135
}
133136

134137
git_diff_free(diff);
138+
git_repository_free(repo);
135139
giterr_clear();
136140

137141
return arg;
@@ -152,8 +156,10 @@ static void *run_index_diffs_with_modifier(void *arg)
152156
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
153157
git_diff *diff = NULL;
154158
git_index *idx = NULL;
159+
git_repository *repo;
155160

156-
cl_git_pass(git_repository_index(&idx, _repo));
161+
cl_git_pass(git_repository_open(&repo, git_repository_path(_repo)));
162+
cl_git_pass(git_repository_index(&idx, repo));
157163

158164
/* have first thread altering the index as we go */
159165
if (thread == 0) {
@@ -176,17 +182,17 @@ static void *run_index_diffs_with_modifier(void *arg)
176182

177183
switch (thread & 0x03) {
178184
case 0: /* diff index to workdir */;
179-
cl_git_pass(git_diff_index_to_workdir(&diff, _repo, idx, &opts));
185+
cl_git_pass(git_diff_index_to_workdir(&diff, repo, idx, &opts));
180186
break;
181187
case 1: /* diff tree 'a' to index */;
182-
cl_git_pass(git_diff_tree_to_index(&diff, _repo, _a, idx, &opts));
188+
cl_git_pass(git_diff_tree_to_index(&diff, repo, _a, idx, &opts));
183189
break;
184190
case 2: /* diff tree 'b' to index */;
185-
cl_git_pass(git_diff_tree_to_index(&diff, _repo, _b, idx, &opts));
191+
cl_git_pass(git_diff_tree_to_index(&diff, repo, _b, idx, &opts));
186192
break;
187193
case 3: /* diff index to workdir reversed */;
188194
opts.flags |= GIT_DIFF_REVERSE;
189-
cl_git_pass(git_diff_index_to_workdir(&diff, _repo, idx, &opts));
195+
cl_git_pass(git_diff_index_to_workdir(&diff, repo, idx, &opts));
190196
break;
191197
}
192198

@@ -196,6 +202,7 @@ static void *run_index_diffs_with_modifier(void *arg)
196202

197203
done:
198204
git_index_free(idx);
205+
git_repository_free(repo);
199206
giterr_clear();
200207

201208
return arg;

tests/threads/iterator.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ void test_threads_iterator__cleanup(void)
1212
static void *run_workdir_iterator(void *arg)
1313
{
1414
int error = 0;
15+
git_repository *repo;
1516
git_iterator *iter;
1617
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
1718
const git_index_entry *entry = NULL;
1819

1920
iter_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
2021

22+
cl_git_pass(git_repository_open(&repo, git_repository_path(_repo)));
2123
cl_git_pass(git_iterator_for_workdir(
22-
&iter, _repo, NULL, NULL, &iter_opts));
24+
&iter, repo, NULL, NULL, &iter_opts));
2325

2426
while (!error) {
2527
if (entry && entry->mode == GIT_FILEMODE_TREE) {
@@ -38,6 +40,7 @@ static void *run_workdir_iterator(void *arg)
3840
cl_assert_equal_i(GIT_ITEROVER, error);
3941

4042
git_iterator_free(iter);
43+
git_repository_free(repo);
4144
giterr_clear();
4245
return arg;
4346
}

0 commit comments

Comments
 (0)