]>
Commit | Line | Data |
---|---|---|
a759bfa9 GS |
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" && | |
59f0d507 | 33 | git commit --allow-empty -m "empty" && |
a759bfa9 GS |
34 | git commit-graph write --reachable --changed-paths |
35 | ' | |
59f0d507 | 36 | |
a759bfa9 GS |
37 | graph_read_expect () { |
38 | NUM_CHUNKS=5 | |
39 | cat >expect <<- EOF | |
40 | header: 43475048 1 1 $NUM_CHUNKS 0 | |
41 | num_commits: $1 | |
42 | chunks: oid_fanout oid_lookup commit_metadata bloom_indexes bloom_data | |
43 | EOF | |
44 | test-tool read-graph >actual && | |
45 | test_cmp expect actual | |
46 | } | |
47 | ||
48 | test_expect_success 'commit-graph write wrote out the bloom chunks' ' | |
59f0d507 | 49 | graph_read_expect 16 |
a759bfa9 GS |
50 | ' |
51 | ||
52 | # Turn off any inherited trace2 settings for this test. | |
53 | sane_unset GIT_TRACE2 GIT_TRACE2_PERF GIT_TRACE2_EVENT | |
54 | sane_unset GIT_TRACE2_PERF_BRIEF | |
55 | sane_unset GIT_TRACE2_CONFIG_PARAMS | |
56 | ||
57 | setup () { | |
025d5294 | 58 | rm -f "$TRASH_DIRECTORY/trace.perf" && |
a759bfa9 GS |
59 | git -c core.commitGraph=false log --pretty="format:%s" $1 >log_wo_bloom && |
60 | GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.perf" git -c core.commitGraph=true log --pretty="format:%s" $1 >log_w_bloom | |
61 | } | |
62 | ||
63 | test_bloom_filters_used () { | |
64 | log_args=$1 | |
4f364405 | 65 | bloom_trace_prefix="statistics:{\"filter_not_present\":${2:-0},\"maybe\"" |
a759bfa9 GS |
66 | setup "$log_args" && |
67 | grep -q "$bloom_trace_prefix" "$TRASH_DIRECTORY/trace.perf" && | |
68 | test_cmp log_wo_bloom log_w_bloom && | |
69 | test_path_is_file "$TRASH_DIRECTORY/trace.perf" | |
70 | } | |
71 | ||
72 | test_bloom_filters_not_used () { | |
73 | log_args=$1 | |
74 | setup "$log_args" && | |
784ce03d | 75 | ! grep -q "statistics:{\"filter_not_present\":" "$TRASH_DIRECTORY/trace.perf" && |
a759bfa9 GS |
76 | test_cmp log_wo_bloom log_w_bloom |
77 | } | |
78 | ||
79 | 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 | |
80 | do | |
81 | for option in "" \ | |
82 | "--all" \ | |
83 | "--full-history" \ | |
84 | "--full-history --simplify-merges" \ | |
85 | "--simplify-merges" \ | |
86 | "--simplify-by-decoration" \ | |
87 | "--follow" \ | |
88 | "--first-parent" \ | |
89 | "--topo-order" \ | |
90 | "--date-order" \ | |
91 | "--author-date-order" \ | |
92 | "--ancestry-path side..master" | |
93 | do | |
94 | test_expect_success "git log option: $option for path: $path" ' | |
b66d8475 TB |
95 | test_bloom_filters_used "$option -- $path" && |
96 | test_config commitgraph.readChangedPaths false && | |
97 | test_bloom_filters_not_used "$option -- $path" | |
a759bfa9 GS |
98 | ' |
99 | done | |
100 | done | |
101 | ||
102 | test_expect_success 'git log -- folder works with and without the trailing slash' ' | |
103 | test_bloom_filters_used "-- A" && | |
104 | test_bloom_filters_used "-- A/" | |
105 | ' | |
106 | ||
107 | test_expect_success 'git log for path that does not exist. ' ' | |
108 | test_bloom_filters_used "-- path_does_not_exist" | |
109 | ' | |
110 | ||
111 | test_expect_success 'git log with --walk-reflogs does not use Bloom filters' ' | |
112 | test_bloom_filters_not_used "--walk-reflogs -- A" | |
113 | ' | |
114 | ||
115 | test_expect_success 'git log -- multiple path specs does not use Bloom filters' ' | |
116 | test_bloom_filters_not_used "-- file4 A/file1" | |
117 | ' | |
118 | ||
f3c2a368 TB |
119 | test_expect_success 'git log -- "." pathspec at root does not use Bloom filters' ' |
120 | test_bloom_filters_not_used "-- ." | |
121 | ' | |
122 | ||
a759bfa9 GS |
123 | test_expect_success 'git log with wildcard that resolves to a single path uses Bloom filters' ' |
124 | test_bloom_filters_used "-- *4" && | |
125 | test_bloom_filters_used "-- *renamed" | |
126 | ' | |
127 | ||
128 | test_expect_success 'git log with wildcard that resolves to a multiple paths does not uses Bloom filters' ' | |
129 | test_bloom_filters_not_used "-- *" && | |
130 | test_bloom_filters_not_used "-- file*" | |
131 | ' | |
132 | ||
133 | test_expect_success 'setup - add commit-graph to the chain without Bloom filters' ' | |
134 | test_commit c14 A/anotherFile2 && | |
135 | test_commit c15 A/B/anotherFile2 && | |
136 | test_commit c16 A/B/C/anotherFile2 && | |
0087a87b | 137 | git commit-graph write --reachable --split --no-changed-paths && |
a759bfa9 GS |
138 | test_line_count = 2 .git/objects/info/commit-graphs/commit-graph-chain |
139 | ' | |
140 | ||
4f364405 TB |
141 | test_expect_success 'use Bloom filters even if the latest graph does not have Bloom filters' ' |
142 | # Ensure that the number of empty filters is equal to the number of | |
143 | # filters in the latest graph layer to prove that they are loaded (and | |
144 | # ignored). | |
145 | test_bloom_filters_used "-- A/B" 3 | |
a759bfa9 GS |
146 | ' |
147 | ||
148 | test_expect_success 'setup - add commit-graph to the chain with Bloom filters' ' | |
149 | test_commit c17 A/anotherFile3 && | |
150 | git commit-graph write --reachable --changed-paths --split && | |
151 | test_line_count = 3 .git/objects/info/commit-graphs/commit-graph-chain | |
152 | ' | |
153 | ||
154 | test_bloom_filters_used_when_some_filters_are_missing () { | |
155 | log_args=$1 | |
59f0d507 | 156 | bloom_trace_prefix="statistics:{\"filter_not_present\":3,\"maybe\":6,\"definitely_not\":9" |
a759bfa9 GS |
157 | setup "$log_args" && |
158 | grep -q "$bloom_trace_prefix" "$TRASH_DIRECTORY/trace.perf" && | |
159 | test_cmp log_wo_bloom log_w_bloom | |
160 | } | |
161 | ||
162 | test_expect_success 'Use Bloom filters if they exist in the latest but not all commit graphs in the chain.' ' | |
163 | test_bloom_filters_used_when_some_filters_are_missing "-- A/B" | |
164 | ' | |
165 | ||
0087a87b DS |
166 | test_expect_success 'persist filter settings' ' |
167 | test_when_finished rm -rf .git/objects/info/commit-graph* && | |
168 | rm -rf .git/objects/info/commit-graph* && | |
169 | GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \ | |
170 | GIT_TRACE2_EVENT_NESTING=5 \ | |
171 | GIT_TEST_BLOOM_SETTINGS_NUM_HASHES=9 \ | |
172 | GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY=15 \ | |
173 | git commit-graph write --reachable --changed-paths && | |
97ffa4fa | 174 | grep "{\"hash_version\":1,\"num_hashes\":9,\"bits_per_entry\":15,\"max_changed_paths\":512" trace2.txt && |
0087a87b DS |
175 | GIT_TRACE2_EVENT="$(pwd)/trace2-auto.txt" \ |
176 | GIT_TRACE2_EVENT_NESTING=5 \ | |
177 | git commit-graph write --reachable --changed-paths && | |
97ffa4fa | 178 | grep "{\"hash_version\":1,\"num_hashes\":9,\"bits_per_entry\":15,\"max_changed_paths\":512" trace2-auto.txt |
0087a87b DS |
179 | ' |
180 | ||
b16a8277 DS |
181 | test_max_changed_paths () { |
182 | grep "\"max_changed_paths\":$1" $2 | |
183 | } | |
184 | ||
59f0d507 TB |
185 | test_filter_not_computed () { |
186 | grep "\"key\":\"filter-not-computed\",\"value\":\"$1\"" $2 | |
187 | } | |
188 | ||
b16a8277 DS |
189 | test_filter_computed () { |
190 | grep "\"key\":\"filter-computed\",\"value\":\"$1\"" $2 | |
191 | } | |
192 | ||
59f0d507 TB |
193 | test_filter_trunc_empty () { |
194 | grep "\"key\":\"filter-trunc-empty\",\"value\":\"$1\"" $2 | |
195 | } | |
196 | ||
b16a8277 DS |
197 | test_filter_trunc_large () { |
198 | grep "\"key\":\"filter-trunc-large\",\"value\":\"$1\"" $2 | |
199 | } | |
200 | ||
94919742 | 201 | test_expect_success 'correctly report changes over limit' ' |
b16a8277 | 202 | git init limits && |
94919742 | 203 | ( |
b16a8277 DS |
204 | cd limits && |
205 | mkdir d && | |
206 | mkdir d/e && | |
207 | ||
208 | for i in $(test_seq 1 2) | |
94919742 | 209 | do |
b16a8277 DS |
210 | printf $i >d/file$i.txt && |
211 | printf $i >d/e/file$i.txt || return 1 | |
94919742 | 212 | done && |
b16a8277 DS |
213 | |
214 | mkdir mode && | |
215 | printf bash >mode/script.sh && | |
216 | ||
217 | mkdir foo && | |
218 | touch foo/bar && | |
219 | touch foo.txt && | |
220 | ||
221 | git add d foo foo.txt mode && | |
94919742 | 222 | git commit -m "files" && |
b16a8277 DS |
223 | |
224 | # Commit has 7 file and 4 directory adds | |
225 | GIT_TEST_BLOOM_SETTINGS_MAX_CHANGED_PATHS=10 \ | |
226 | GIT_TRACE2_EVENT="$(pwd)/trace" \ | |
227 | git commit-graph write --reachable --changed-paths && | |
228 | test_max_changed_paths 10 trace && | |
229 | test_filter_computed 1 trace && | |
230 | test_filter_trunc_large 1 trace && | |
231 | ||
232 | for path in $(git ls-tree -r --name-only HEAD) | |
233 | do | |
234 | git -c commitGraph.readChangedPaths=false log \ | |
235 | -- $path >expect && | |
236 | git log -- $path >actual && | |
237 | test_cmp expect actual || return 1 | |
238 | done && | |
239 | ||
240 | # Make a variety of path changes | |
241 | printf new1 >d/e/file1.txt && | |
242 | printf new2 >d/file2.txt && | |
243 | rm d/e/file2.txt && | |
244 | rm -r foo && | |
245 | printf text >foo && | |
246 | mkdir f && | |
247 | printf new1 >f/file1.txt && | |
248 | ||
249 | # including a mode-only change (counts as modified) | |
250 | git update-index --chmod=+x mode/script.sh && | |
251 | ||
252 | git add foo d f && | |
253 | git commit -m "complicated" && | |
254 | ||
255 | # start from scratch and rebuild | |
256 | rm -f .git/objects/info/commit-graph && | |
257 | GIT_TEST_BLOOM_SETTINGS_MAX_CHANGED_PATHS=10 \ | |
258 | GIT_TRACE2_EVENT="$(pwd)/trace-edit" \ | |
259 | git commit-graph write --reachable --changed-paths && | |
260 | test_max_changed_paths 10 trace-edit && | |
261 | test_filter_computed 2 trace-edit && | |
262 | test_filter_trunc_large 2 trace-edit && | |
263 | ||
264 | for path in $(git ls-tree -r --name-only HEAD) | |
265 | do | |
266 | git -c commitGraph.readChangedPaths=false log \ | |
267 | -- $path >expect && | |
268 | git log -- $path >actual && | |
269 | test_cmp expect actual || return 1 | |
270 | done && | |
271 | ||
272 | # start from scratch and rebuild | |
273 | rm -f .git/objects/info/commit-graph && | |
274 | GIT_TEST_BLOOM_SETTINGS_MAX_CHANGED_PATHS=11 \ | |
275 | GIT_TRACE2_EVENT="$(pwd)/trace-update" \ | |
276 | git commit-graph write --reachable --changed-paths && | |
277 | test_max_changed_paths 11 trace-update && | |
278 | test_filter_computed 2 trace-update && | |
279 | test_filter_trunc_large 0 trace-update && | |
280 | ||
281 | for path in $(git ls-tree -r --name-only HEAD) | |
94919742 | 282 | do |
b16a8277 DS |
283 | git -c commitGraph.readChangedPaths=false log \ |
284 | -- $path >expect && | |
285 | git log -- $path >actual && | |
94919742 DS |
286 | test_cmp expect actual || return 1 |
287 | done | |
288 | ) | |
289 | ' | |
290 | ||
59f0d507 TB |
291 | test_expect_success 'correctly report commits with no changed paths' ' |
292 | git init empty && | |
293 | test_when_finished "rm -fr empty" && | |
294 | ( | |
295 | cd empty && | |
296 | ||
297 | git commit --allow-empty -m "initial commit" && | |
298 | ||
299 | GIT_TRACE2_EVENT="$(pwd)/trace.event" \ | |
300 | git commit-graph write --reachable --changed-paths && | |
301 | test_filter_computed 1 trace.event && | |
302 | test_filter_not_computed 0 trace.event && | |
303 | test_filter_trunc_empty 1 trace.event && | |
304 | test_filter_trunc_large 0 trace.event | |
305 | ) | |
306 | ' | |
307 | ||
066b70ae | 308 | test_done |