Merge branch 'gc/use-repo-settings'
[git/debian.git] / t / lib-bitmap.sh
blob21d0392ddac5a2e21f8ce090d87efc6cda4e4d9a
1 # Helpers for scripts testing bitmap functionality; see t5310 for
2 # example usage.
4 # Compare a file containing rev-list bitmap traversal output to its non-bitmap
5 # counterpart. You can't just use test_cmp for this, because the two produce
6 # subtly different output:
8 # - regular output is in traversal order, whereas bitmap is split by type,
9 # with non-packed objects at the end
11 # - regular output has a space and the pathname appended to non-commit
12 # objects; bitmap output omits this
14 # This function normalizes and compares the two. The second file should
15 # always be the bitmap output.
16 test_bitmap_traversal () {
17 if test "$1" = "--no-confirm-bitmaps"
18 then
19 shift
20 elif cmp "$1" "$2"
21 then
22 echo >&2 "identical raw outputs; are you sure bitmaps were used?"
23 return 1
24 fi &&
25 cut -d' ' -f1 "$1" | sort >"$1.normalized" &&
26 sort "$2" >"$2.normalized" &&
27 test_cmp "$1.normalized" "$2.normalized" &&
28 rm -f "$1.normalized" "$2.normalized"
31 # To ensure the logic for "maximal commits" is exercised, make
32 # the repository a bit more complicated.
34 # other second
35 # * *
36 # (99 commits) (99 commits)
37 # * *
38 # |\ /|
39 # | * octo-other octo-second * |
40 # |/|\_________ ____________/|\|
41 # | \ \/ __________/ |
42 # | | ________/\ / |
43 # * |/ * merge-right *
44 # | _|__________/ \____________ |
45 # |/ | \|
46 # (l1) * * merge-left * (r1)
47 # | / \________________________ |
48 # |/ \|
49 # (l2) * * (r2)
50 # \___________________________ |
51 # \|
52 # * (base)
54 # We only push bits down the first-parent history, which
55 # makes some of these commits unimportant!
57 # The important part for the maximal commit algorithm is how
58 # the bitmasks are extended. Assuming starting bit positions
59 # for second (bit 0) and other (bit 1), the bitmasks at the
60 # end should be:
62 # second: 1 (maximal, selected)
63 # other: 01 (maximal, selected)
64 # (base): 11 (maximal)
66 # This complicated history was important for a previous
67 # version of the walk that guarantees never walking a
68 # commit multiple times. That goal might be important
69 # again, so preserve this complicated case. For now, this
70 # test will guarantee that the bitmaps are computed
71 # correctly, even with the repeat calculations.
72 setup_bitmap_history() {
73 test_expect_success 'setup repo with moderate-sized history' '
74 test_commit_bulk --id=file 10 &&
75 git branch -M second &&
76 git checkout -b other HEAD~5 &&
77 test_commit_bulk --id=side 10 &&
79 # add complicated history setup, including merges and
80 # ambiguous merge-bases
82 git checkout -b merge-left other~2 &&
83 git merge second~2 -m "merge-left" &&
85 git checkout -b merge-right second~1 &&
86 git merge other~1 -m "merge-right" &&
88 git checkout -b octo-second second &&
89 git merge merge-left merge-right -m "octopus-second" &&
91 git checkout -b octo-other other &&
92 git merge merge-left merge-right -m "octopus-other" &&
94 git checkout other &&
95 git merge octo-other -m "pull octopus" &&
97 git checkout second &&
98 git merge octo-second -m "pull octopus" &&
100 # Remove these branches so they are not selected
101 # as bitmap tips
102 git branch -D merge-left &&
103 git branch -D merge-right &&
104 git branch -D octo-other &&
105 git branch -D octo-second &&
107 # add padding to make these merges less interesting
108 # and avoid having them selected for bitmaps
109 test_commit_bulk --id=file 100 &&
110 git checkout other &&
111 test_commit_bulk --id=side 100 &&
112 git checkout second &&
114 bitmaptip=$(git rev-parse second) &&
115 blob=$(echo tagged-blob | git hash-object -w --stdin) &&
116 git tag tagged-blob $blob
120 rev_list_tests_head () {
121 test_expect_success "counting commits via bitmap ($state, $branch)" '
122 git rev-list --count $branch >expect &&
123 git rev-list --use-bitmap-index --count $branch >actual &&
124 test_cmp expect actual
127 test_expect_success "counting partial commits via bitmap ($state, $branch)" '
128 git rev-list --count $branch~5..$branch >expect &&
129 git rev-list --use-bitmap-index --count $branch~5..$branch >actual &&
130 test_cmp expect actual
133 test_expect_success "counting commits with limit ($state, $branch)" '
134 git rev-list --count -n 1 $branch >expect &&
135 git rev-list --use-bitmap-index --count -n 1 $branch >actual &&
136 test_cmp expect actual
139 test_expect_success "counting non-linear history ($state, $branch)" '
140 git rev-list --count other...second >expect &&
141 git rev-list --use-bitmap-index --count other...second >actual &&
142 test_cmp expect actual
145 test_expect_success "counting commits with limiting ($state, $branch)" '
146 git rev-list --count $branch -- 1.t >expect &&
147 git rev-list --use-bitmap-index --count $branch -- 1.t >actual &&
148 test_cmp expect actual
151 test_expect_success "counting objects via bitmap ($state, $branch)" '
152 git rev-list --count --objects $branch >expect &&
153 git rev-list --use-bitmap-index --count --objects $branch >actual &&
154 test_cmp expect actual
157 test_expect_success "enumerate commits ($state, $branch)" '
158 git rev-list --use-bitmap-index $branch >actual &&
159 git rev-list $branch >expect &&
160 test_bitmap_traversal --no-confirm-bitmaps expect actual
163 test_expect_success "enumerate --objects ($state, $branch)" '
164 git rev-list --objects --use-bitmap-index $branch >actual &&
165 git rev-list --objects $branch >expect &&
166 test_bitmap_traversal expect actual
169 test_expect_success "bitmap --objects handles non-commit objects ($state, $branch)" '
170 git rev-list --objects --use-bitmap-index $branch tagged-blob >actual &&
171 grep $blob actual
175 rev_list_tests () {
176 state=$1
178 for branch in "second" "other"
180 rev_list_tests_head
181 done
184 basic_bitmap_tests () {
185 tip="$1"
186 test_expect_success 'rev-list --test-bitmap verifies bitmaps' "
187 git rev-list --test-bitmap "${tip:-HEAD}"
190 rev_list_tests 'full bitmap'
192 test_expect_success 'clone from bitmapped repository' '
193 rm -fr clone.git &&
194 git clone --no-local --bare . clone.git &&
195 git rev-parse HEAD >expect &&
196 git --git-dir=clone.git rev-parse HEAD >actual &&
197 test_cmp expect actual
200 test_expect_success 'partial clone from bitmapped repository' '
201 test_config uploadpack.allowfilter true &&
202 rm -fr partial-clone.git &&
203 git clone --no-local --bare --filter=blob:none . partial-clone.git &&
205 cd partial-clone.git &&
206 pack=$(echo objects/pack/*.pack) &&
207 git verify-pack -v "$pack" >have &&
208 awk "/blob/ { print \$1 }" <have >blobs &&
209 # we expect this single blob because of the direct ref
210 git rev-parse refs/tags/tagged-blob >expect &&
211 test_cmp expect blobs
215 test_expect_success 'setup further non-bitmapped commits' '
216 test_commit_bulk --id=further 10
219 rev_list_tests 'partial bitmap'
221 test_expect_success 'fetch (partial bitmap)' '
222 git --git-dir=clone.git fetch origin second:second &&
223 git rev-parse HEAD >expect &&
224 git --git-dir=clone.git rev-parse HEAD >actual &&
225 test_cmp expect actual
228 test_expect_success 'enumerating progress counts pack-reused objects' '
229 count=$(git rev-list --objects --all --count) &&
230 git repack -adb &&
232 # check first with only reused objects; confirm that our
233 # progress showed the right number, and also that we did
234 # pack-reuse as expected. Check only the final "done"
235 # line of the meter (there may be an arbitrary number of
236 # intermediate lines ending with CR).
237 GIT_PROGRESS_DELAY=0 \
238 git pack-objects --all --stdout --progress \
239 </dev/null >/dev/null 2>stderr &&
240 grep "Enumerating objects: $count, done" stderr &&
241 grep "pack-reused $count" stderr &&
243 # now the same but with one non-reused object
244 git commit --allow-empty -m "an extra commit object" &&
245 GIT_PROGRESS_DELAY=0 \
246 git pack-objects --all --stdout --progress \
247 </dev/null >/dev/null 2>stderr &&
248 grep "Enumerating objects: $((count+1)), done" stderr &&
249 grep "pack-reused $count" stderr
253 # have_delta <obj> <expected_base>
255 # Note that because this relies on cat-file, it might find _any_ copy of an
256 # object in the repository. The caller is responsible for making sure
257 # there's only one (e.g., via "repack -ad", or having just fetched a copy).
258 have_delta () {
259 echo $2 >expect &&
260 echo $1 | git cat-file --batch-check="%(deltabase)" >actual &&
261 test_cmp expect actual
264 midx_checksum () {
265 test-tool read-midx --checksum "$1"