test-reach: test commit_contains
The commit_contains method has two modes which depend on the given ref_filter struct. We have the "normal" algorithm (which is also the typically-slow operation) and the "tag" algorithm. This difference is essentially what changes performance for 'git branch --contains' versus 'git tag --contains'. There are thoughts that the data shapes used by these two applications justify the different implementations. Create tests using 'test-tool reach commit_contains [--tag]' to cover both methods. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Jul 20, 2018 at 16:33 UTC
1fee1242577ae23b32c33ff1122402bb228f2692
2 files changed
+46
t/helper/test-reach.c
+12
@@ -4,6 +4,7 @@
4
#include "commit-reach.h"
5
#include "config.h"
6
#include "parse-options.h"
7
+#include "ref-filter.h"
8
#include "string-list.h"
9
#include "tag.h"
10
@@ -112,6 +113,17 @@ int cmd__reach(int ac, const char **av)
113
print_sorted_commit_ids(list);
114
} else if (!strcmp(av[1], "can_all_from_reach")) {
115
printf("%s(X,Y):%d\n", av[1], can_all_from_reach(X, Y, 1));
116
+ } else if (!strcmp(av[1], "commit_contains")) {
117
+ struct ref_filter filter;
118
+ struct contains_cache cache;
119
+ init_contains_cache(&cache);
120
+
121
+ if (ac > 2 && !strcmp(av[2], "--tag"))
122
+ filter.with_commit_tag_algo = 1;
123
+ else
124
+ filter.with_commit_tag_algo = 0;
125
+
126
+ printf("%s(_,A,X,_):%d\n", av[1], commit_contains(&filter, A, X, &cache));
127
}
128
129
exit(0);
t/t6600-test-reach.sh
+34
@@ -205,4 +205,38 @@ test_expect_success 'can_all_from_reach:miss' '
205
test_three_modes can_all_from_reach
206
'
207
208
+test_expect_success 'commit_contains:hit' '
209
+ cat >input <<-\EOF &&
210
+ A:commit-7-7
211
+ X:commit-2-10
212
+ X:commit-3-9
213
+ X:commit-4-8
214
+ X:commit-5-7
215
+ X:commit-6-6
216
+ X:commit-7-5
217
+ X:commit-8-4
218
+ X:commit-9-3
219
+ EOF
220
+ echo "commit_contains(_,A,X,_):1" >expect &&
221
+ test_three_modes commit_contains &&
222
+ test_three_modes commit_contains --tag
223
+'
224
+
225
+test_expect_success 'commit_contains:miss' '
226
+ cat >input <<-\EOF &&
227
+ A:commit-6-5
228
+ X:commit-2-10
229
+ X:commit-3-9
230
+ X:commit-4-8
231
+ X:commit-5-7
232
+ X:commit-6-6
233
+ X:commit-7-5
234
+ X:commit-8-4
235
+ X:commit-9-3
236
+ EOF
237
+ echo "commit_contains(_,A,X,_):0" >expect &&
238
+ test_three_modes commit_contains &&
239
+ test_three_modes commit_contains --tag
240
+'
241
+
242
test_done