Skip to content

Commit 1fee124

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1792bc1 commit 1fee124

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

t/helper/test-reach.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "commit-reach.h"
55
#include "config.h"
66
#include "parse-options.h"
7+
#include "ref-filter.h"
78
#include "string-list.h"
89
#include "tag.h"
910

@@ -112,6 +113,17 @@ int cmd__reach(int ac, const char **av)
112113
print_sorted_commit_ids(list);
113114
} else if (!strcmp(av[1], "can_all_from_reach")) {
114115
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));
115127
}
116128

117129
exit(0);

t/t6600-test-reach.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,38 @@ test_expect_success 'can_all_from_reach:miss' '
205205
test_three_modes can_all_from_reach
206206
'
207207

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+
208242
test_done

0 commit comments

Comments
 (0)