]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4216-log-bloom.sh
Merge branch 'hn/refs-ref-log-only-bit'
[thirdparty/git.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 test_oid_cache <<-EOF
36 oid_version sha1:1
37 oid_version sha256:2
38 EOF
39 '
40 graph_read_expect () {
41 NUM_CHUNKS=5
42 cat >expect <<- EOF
43 header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0
44 num_commits: $1
45 chunks: oid_fanout oid_lookup commit_metadata bloom_indexes bloom_data
46 EOF
47 test-tool read-graph >actual &&
48 test_cmp expect actual
49 }
50
51 test_expect_success 'commit-graph write wrote out the bloom chunks' '
52 graph_read_expect 15
53 '
54
55 # Turn off any inherited trace2 settings for this test.
56 sane_unset GIT_TRACE2 GIT_TRACE2_PERF GIT_TRACE2_EVENT
57 sane_unset GIT_TRACE2_PERF_BRIEF
58 sane_unset GIT_TRACE2_CONFIG_PARAMS
59
60 setup () {
61 rm "$TRASH_DIRECTORY/trace.perf"
62 git -c core.commitGraph=false log --pretty="format:%s" $1 >log_wo_bloom &&
63 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.perf" git -c core.commitGraph=true log --pretty="format:%s" $1 >log_w_bloom
64 }
65
66 test_bloom_filters_used () {
67 log_args=$1
68 bloom_trace_prefix="statistics:{\"filter_not_present\":0,\"maybe\""
69 setup "$log_args" &&
70 grep -q "$bloom_trace_prefix" "$TRASH_DIRECTORY/trace.perf" &&
71 test_cmp log_wo_bloom log_w_bloom &&
72 test_path_is_file "$TRASH_DIRECTORY/trace.perf"
73 }
74
75 test_bloom_filters_not_used () {
76 log_args=$1
77 setup "$log_args" &&
78 ! grep -q "statistics:{\"filter_not_present\":" "$TRASH_DIRECTORY/trace.perf" &&
79 test_cmp log_wo_bloom log_w_bloom
80 }
81
82 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
83 do
84 for option in "" \
85 "--all" \
86 "--full-history" \
87 "--full-history --simplify-merges" \
88 "--simplify-merges" \
89 "--simplify-by-decoration" \
90 "--follow" \
91 "--first-parent" \
92 "--topo-order" \
93 "--date-order" \
94 "--author-date-order" \
95 "--ancestry-path side..master"
96 do
97 test_expect_success "git log option: $option for path: $path" '
98 test_bloom_filters_used "$option -- $path"
99 '
100 done
101 done
102
103 test_expect_success 'git log -- folder works with and without the trailing slash' '
104 test_bloom_filters_used "-- A" &&
105 test_bloom_filters_used "-- A/"
106 '
107
108 test_expect_success 'git log for path that does not exist. ' '
109 test_bloom_filters_used "-- path_does_not_exist"
110 '
111
112 test_expect_success 'git log with --walk-reflogs does not use Bloom filters' '
113 test_bloom_filters_not_used "--walk-reflogs -- A"
114 '
115
116 test_expect_success 'git log -- multiple path specs does not use Bloom filters' '
117 test_bloom_filters_not_used "-- file4 A/file1"
118 '
119
120 test_expect_success 'git log -- "." pathspec at root does not use Bloom filters' '
121 test_bloom_filters_not_used "-- ."
122 '
123
124 test_expect_success 'git log with wildcard that resolves to a single path uses Bloom filters' '
125 test_bloom_filters_used "-- *4" &&
126 test_bloom_filters_used "-- *renamed"
127 '
128
129 test_expect_success 'git log with wildcard that resolves to a multiple paths does not uses Bloom filters' '
130 test_bloom_filters_not_used "-- *" &&
131 test_bloom_filters_not_used "-- file*"
132 '
133
134 test_expect_success 'setup - add commit-graph to the chain without Bloom filters' '
135 test_commit c14 A/anotherFile2 &&
136 test_commit c15 A/B/anotherFile2 &&
137 test_commit c16 A/B/C/anotherFile2 &&
138 git commit-graph write --reachable --split --no-changed-paths &&
139 test_line_count = 2 .git/objects/info/commit-graphs/commit-graph-chain
140 '
141
142 test_expect_success 'Do not use Bloom filters if the latest graph does not have Bloom filters.' '
143 test_bloom_filters_not_used "-- A/B"
144 '
145
146 test_expect_success 'setup - add commit-graph to the chain with Bloom filters' '
147 test_commit c17 A/anotherFile3 &&
148 git commit-graph write --reachable --changed-paths --split &&
149 test_line_count = 3 .git/objects/info/commit-graphs/commit-graph-chain
150 '
151
152 test_bloom_filters_used_when_some_filters_are_missing () {
153 log_args=$1
154 bloom_trace_prefix="statistics:{\"filter_not_present\":3,\"maybe\":6,\"definitely_not\":8"
155 setup "$log_args" &&
156 grep -q "$bloom_trace_prefix" "$TRASH_DIRECTORY/trace.perf" &&
157 test_cmp log_wo_bloom log_w_bloom
158 }
159
160 test_expect_success 'Use Bloom filters if they exist in the latest but not all commit graphs in the chain.' '
161 test_bloom_filters_used_when_some_filters_are_missing "-- A/B"
162 '
163
164 test_expect_success 'persist filter settings' '
165 test_when_finished rm -rf .git/objects/info/commit-graph* &&
166 rm -rf .git/objects/info/commit-graph* &&
167 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
168 GIT_TRACE2_EVENT_NESTING=5 \
169 GIT_TEST_BLOOM_SETTINGS_NUM_HASHES=9 \
170 GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY=15 \
171 git commit-graph write --reachable --changed-paths &&
172 grep "{\"hash_version\":1,\"num_hashes\":9,\"bits_per_entry\":15}" trace2.txt &&
173 GIT_TRACE2_EVENT="$(pwd)/trace2-auto.txt" \
174 GIT_TRACE2_EVENT_NESTING=5 \
175 git commit-graph write --reachable --changed-paths &&
176 grep "{\"hash_version\":1,\"num_hashes\":9,\"bits_per_entry\":15}" trace2-auto.txt
177 '
178
179 test_expect_success 'correctly report changes over limit' '
180 git init 513changes &&
181 (
182 cd 513changes &&
183 for i in $(test_seq 1 513)
184 do
185 echo $i >file$i.txt || return 1
186 done &&
187 git add . &&
188 git commit -m "files" &&
189 git commit-graph write --reachable --changed-paths &&
190 for i in $(test_seq 1 513)
191 do
192 git -c core.commitGraph=false log -- file$i.txt >expect &&
193 git log -- file$i.txt >actual &&
194 test_cmp expect actual || return 1
195 done
196 )
197 '
198
199 test_done