Merge branch 'dl/python-2.7-is-the-floor-version'
[git] / t / t4216-log-bloom.sh
1 #!/bin/sh
2
3 test_description='git log for a path with Bloom filters'
4 . ./test-lib.sh
5
6 GIT_TEST_COMMIT_GRAPH=0
7 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
8
9 test_expect_success 'setup test - repo, commits, commit graph, log outputs' '
10         git init &&
11         mkdir A A/B A/B/C &&
12         test_commit c1 A/file1 &&
13         test_commit c2 A/B/file2 &&
14         test_commit c3 A/B/C/file3 &&
15         test_commit c4 A/file1 &&
16         test_commit c5 A/B/file2 &&
17         test_commit c6 A/B/C/file3 &&
18         test_commit c7 A/file1 &&
19         test_commit c8 A/B/file2 &&
20         test_commit c9 A/B/C/file3 &&
21         test_commit c10 file_to_be_deleted &&
22         git checkout -b side HEAD~4 &&
23         test_commit side-1 file4 &&
24         git checkout master &&
25         git merge side &&
26         test_commit c11 file5 &&
27         mv file5 file5_renamed &&
28         git add file5_renamed &&
29         git commit -m "rename" &&
30         rm file_to_be_deleted &&
31         git add . &&
32         git commit -m "file removed" &&
33         git commit-graph write --reachable --changed-paths
34 '
35 graph_read_expect () {
36         NUM_CHUNKS=5
37         cat >expect <<- EOF
38         header: 43475048 1 1 $NUM_CHUNKS 0
39         num_commits: $1
40         chunks: oid_fanout oid_lookup commit_metadata bloom_indexes bloom_data
41         EOF
42         test-tool read-graph >actual &&
43         test_cmp expect actual
44 }
45
46 test_expect_success 'commit-graph write wrote out the bloom chunks' '
47         graph_read_expect 15
48 '
49
50 # Turn off any inherited trace2 settings for this test.
51 sane_unset GIT_TRACE2 GIT_TRACE2_PERF GIT_TRACE2_EVENT
52 sane_unset GIT_TRACE2_PERF_BRIEF
53 sane_unset GIT_TRACE2_CONFIG_PARAMS
54
55 setup () {
56         rm "$TRASH_DIRECTORY/trace.perf"
57         git -c core.commitGraph=false log --pretty="format:%s" $1 >log_wo_bloom &&
58         GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.perf" git -c core.commitGraph=true log --pretty="format:%s" $1 >log_w_bloom
59 }
60
61 test_bloom_filters_used () {
62         log_args=$1
63         bloom_trace_prefix="statistics:{\"filter_not_present\":0,\"zero_length_filter\":0,\"maybe\""
64         setup "$log_args" &&
65         grep -q "$bloom_trace_prefix" "$TRASH_DIRECTORY/trace.perf" &&
66         test_cmp log_wo_bloom log_w_bloom &&
67     test_path_is_file "$TRASH_DIRECTORY/trace.perf"
68 }
69
70 test_bloom_filters_not_used () {
71         log_args=$1
72         setup "$log_args" &&
73         ! grep -q "statistics:{\"filter_not_present\":" "$TRASH_DIRECTORY/trace.perf" &&
74         test_cmp log_wo_bloom log_w_bloom
75 }
76
77 for path in A A/B A/B/C A/file1 A/B/file2 A/B/C/file3 file4 file5 file5_renamed file_to_be_deleted
78 do
79         for option in "" \
80               "--all" \
81                       "--full-history" \
82                       "--full-history --simplify-merges" \
83                       "--simplify-merges" \
84                       "--simplify-by-decoration" \
85                       "--follow" \
86                       "--first-parent" \
87                       "--topo-order" \
88                       "--date-order" \
89                       "--author-date-order" \
90                       "--ancestry-path side..master"
91         do
92                 test_expect_success "git log option: $option for path: $path" '
93                         test_bloom_filters_used "$option -- $path"
94                 '
95         done
96 done
97
98 test_expect_success 'git log -- folder works with and without the trailing slash' '
99         test_bloom_filters_used "-- A" &&
100         test_bloom_filters_used "-- A/"
101 '
102
103 test_expect_success 'git log for path that does not exist. ' '
104         test_bloom_filters_used "-- path_does_not_exist"
105 '
106
107 test_expect_success 'git log with --walk-reflogs does not use Bloom filters' '
108         test_bloom_filters_not_used "--walk-reflogs -- A"
109 '
110
111 test_expect_success 'git log -- multiple path specs does not use Bloom filters' '
112         test_bloom_filters_not_used "-- file4 A/file1"
113 '
114
115 test_expect_success 'git log with wildcard that resolves to a single path uses Bloom filters' '
116         test_bloom_filters_used "-- *4" &&
117         test_bloom_filters_used "-- *renamed"
118 '
119
120 test_expect_success 'git log with wildcard that resolves to a multiple paths does not uses Bloom filters' '
121         test_bloom_filters_not_used "-- *" &&
122         test_bloom_filters_not_used "-- file*"
123 '
124
125 test_expect_success 'setup - add commit-graph to the chain without Bloom filters' '
126         test_commit c14 A/anotherFile2 &&
127         test_commit c15 A/B/anotherFile2 &&
128         test_commit c16 A/B/C/anotherFile2 &&
129         GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0 git commit-graph write --reachable --split &&
130         test_line_count = 2 .git/objects/info/commit-graphs/commit-graph-chain
131 '
132
133 test_expect_success 'Do not use Bloom filters if the latest graph does not have Bloom filters.' '
134         test_bloom_filters_not_used "-- A/B"
135 '
136
137 test_expect_success 'setup - add commit-graph to the chain with Bloom filters' '
138         test_commit c17 A/anotherFile3 &&
139         git commit-graph write --reachable --changed-paths --split &&
140         test_line_count = 3 .git/objects/info/commit-graphs/commit-graph-chain
141 '
142
143 test_bloom_filters_used_when_some_filters_are_missing () {
144         log_args=$1
145         bloom_trace_prefix="statistics:{\"filter_not_present\":3,\"zero_length_filter\":0,\"maybe\":8,\"definitely_not\":6"
146         setup "$log_args" &&
147         grep -q "$bloom_trace_prefix" "$TRASH_DIRECTORY/trace.perf" &&
148         test_cmp log_wo_bloom log_w_bloom
149 }
150
151 test_expect_success 'Use Bloom filters if they exist in the latest but not all commit graphs in the chain.' '
152         test_bloom_filters_used_when_some_filters_are_missing "-- A/B"
153 '
154
155 test_done