setup: allow for prefix to be passed to git commands
[alt-git.git] / t / t5310-pack-bitmaps.sh
blob424bec7d77c2b3761669230bf30030883ce4c230
1 #!/bin/sh
3 test_description='exercise basic bitmap functionality'
4 . ./test-lib.sh
6 objpath () {
7 echo ".git/objects/$(echo "$1" | sed -e 's|\(..\)|\1/|')"
10 # show objects present in pack ($1 should be associated *.idx)
11 list_packed_objects () {
12 git show-index <"$1" | cut -d' ' -f2
15 # has_any pattern-file content-file
16 # tests whether content-file has any entry from pattern-file with entries being
17 # whole lines.
18 has_any () {
19 grep -Ff "$1" "$2"
22 test_expect_success 'setup repo with moderate-sized history' '
23 for i in $(test_seq 1 10); do
24 test_commit $i
25 done &&
26 git checkout -b other HEAD~5 &&
27 for i in $(test_seq 1 10); do
28 test_commit side-$i
29 done &&
30 git checkout master &&
31 bitmaptip=$(git rev-parse master) &&
32 blob=$(echo tagged-blob | git hash-object -w --stdin) &&
33 git tag tagged-blob $blob &&
34 git config repack.writebitmaps true &&
35 git config pack.writebitmaphashcache true
38 test_expect_success 'full repack creates bitmaps' '
39 git repack -ad &&
40 ls .git/objects/pack/ | grep bitmap >output &&
41 test_line_count = 1 output
44 test_expect_success 'rev-list --test-bitmap verifies bitmaps' '
45 git rev-list --test-bitmap HEAD
48 rev_list_tests() {
49 state=$1
51 test_expect_success "counting commits via bitmap ($state)" '
52 git rev-list --count HEAD >expect &&
53 git rev-list --use-bitmap-index --count HEAD >actual &&
54 test_cmp expect actual
57 test_expect_success "counting partial commits via bitmap ($state)" '
58 git rev-list --count HEAD~5..HEAD >expect &&
59 git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual &&
60 test_cmp expect actual
63 test_expect_success "counting commits with limit ($state)" '
64 git rev-list --count -n 1 HEAD >expect &&
65 git rev-list --use-bitmap-index --count -n 1 HEAD >actual &&
66 test_cmp expect actual
69 test_expect_success "counting non-linear history ($state)" '
70 git rev-list --count other...master >expect &&
71 git rev-list --use-bitmap-index --count other...master >actual &&
72 test_cmp expect actual
75 test_expect_success "counting commits with limiting ($state)" '
76 git rev-list --count HEAD -- 1.t >expect &&
77 git rev-list --use-bitmap-index --count HEAD -- 1.t >actual &&
78 test_cmp expect actual
81 test_expect_success "enumerate --objects ($state)" '
82 git rev-list --objects --use-bitmap-index HEAD >tmp &&
83 cut -d" " -f1 <tmp >tmp2 &&
84 sort <tmp2 >actual &&
85 git rev-list --objects HEAD >tmp &&
86 cut -d" " -f1 <tmp >tmp2 &&
87 sort <tmp2 >expect &&
88 test_cmp expect actual
91 test_expect_success "bitmap --objects handles non-commit objects ($state)" '
92 git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual &&
93 grep $blob actual
97 rev_list_tests 'full bitmap'
99 test_expect_success 'clone from bitmapped repository' '
100 git clone --no-local --bare . clone.git &&
101 git rev-parse HEAD >expect &&
102 git --git-dir=clone.git rev-parse HEAD >actual &&
103 test_cmp expect actual
106 test_expect_success 'setup further non-bitmapped commits' '
107 for i in $(test_seq 1 10); do
108 test_commit further-$i
109 done
112 rev_list_tests 'partial bitmap'
114 test_expect_success 'fetch (partial bitmap)' '
115 git --git-dir=clone.git fetch origin master:master &&
116 git rev-parse HEAD >expect &&
117 git --git-dir=clone.git rev-parse HEAD >actual &&
118 test_cmp expect actual
121 test_expect_success 'incremental repack fails when bitmaps are requested' '
122 test_commit more-1 &&
123 test_must_fail git repack -d 2>err &&
124 test_i18ngrep "Incremental repacks are incompatible with bitmap" err
127 test_expect_success 'incremental repack can disable bitmaps' '
128 test_commit more-2 &&
129 git repack -d --no-write-bitmap-index
132 test_expect_success 'pack-objects respects --local (non-local loose)' '
133 git init --bare alt.git &&
134 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
135 echo content1 >file1 &&
136 # non-local loose object which is not present in bitmapped pack
137 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
138 # non-local loose object which is also present in bitmapped pack
139 git cat-file blob $blob | GIT_DIR=alt.git git hash-object -w --stdin &&
140 git add file1 &&
141 test_tick &&
142 git commit -m commit_file1 &&
143 echo HEAD | git pack-objects --local --stdout --revs >1.pack &&
144 git index-pack 1.pack &&
145 list_packed_objects 1.idx >1.objects &&
146 printf "%s\n" "$altblob" "$blob" >nonlocal-loose &&
147 ! has_any nonlocal-loose 1.objects
150 test_expect_success 'pack-objects respects --honor-pack-keep (local non-bitmapped pack)' '
151 echo content2 >file2 &&
152 blob2=$(git hash-object -w file2) &&
153 git add file2 &&
154 test_tick &&
155 git commit -m commit_file2 &&
156 printf "%s\n" "$blob2" "$bitmaptip" >keepobjects &&
157 pack2=$(git pack-objects pack2 <keepobjects) &&
158 mv pack2-$pack2.* .git/objects/pack/ &&
159 >.git/objects/pack/pack2-$pack2.keep &&
160 rm $(objpath $blob2) &&
161 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >2a.pack &&
162 git index-pack 2a.pack &&
163 list_packed_objects 2a.idx >2a.objects &&
164 ! has_any keepobjects 2a.objects
167 test_expect_success 'pack-objects respects --local (non-local pack)' '
168 mv .git/objects/pack/pack2-$pack2.* alt.git/objects/pack/ &&
169 echo HEAD | git pack-objects --local --stdout --revs >2b.pack &&
170 git index-pack 2b.pack &&
171 list_packed_objects 2b.idx >2b.objects &&
172 ! has_any keepobjects 2b.objects
175 test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pack)' '
176 ls .git/objects/pack/ | grep bitmap >output &&
177 test_line_count = 1 output &&
178 packbitmap=$(basename $(cat output) .bitmap) &&
179 list_packed_objects .git/objects/pack/$packbitmap.idx >packbitmap.objects &&
180 test_when_finished "rm -f .git/objects/pack/$packbitmap.keep" &&
181 >.git/objects/pack/$packbitmap.keep &&
182 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >3a.pack &&
183 git index-pack 3a.pack &&
184 list_packed_objects 3a.idx >3a.objects &&
185 ! has_any packbitmap.objects 3a.objects
188 test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
189 mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
190 test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
191 echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
192 git index-pack 3b.pack &&
193 list_packed_objects 3b.idx >3b.objects &&
194 ! has_any packbitmap.objects 3b.objects
197 test_expect_success 'pack-objects to file can use bitmap' '
198 # make sure we still have 1 bitmap index from previous tests
199 ls .git/objects/pack/ | grep bitmap >output &&
200 test_line_count = 1 output &&
201 # verify equivalent packs are generated with/without using bitmap index
202 packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
203 packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
204 list_packed_objects <packa-$packasha1.idx >packa.objects &&
205 list_packed_objects <packb-$packbsha1.idx >packb.objects &&
206 test_cmp packa.objects packb.objects
209 test_expect_success 'full repack, reusing previous bitmaps' '
210 git repack -ad &&
211 ls .git/objects/pack/ | grep bitmap >output &&
212 test_line_count = 1 output
215 test_expect_success 'fetch (full bitmap)' '
216 git --git-dir=clone.git fetch origin master:master &&
217 git rev-parse HEAD >expect &&
218 git --git-dir=clone.git rev-parse HEAD >actual &&
219 test_cmp expect actual
222 test_expect_success 'create objects for missing-HAVE tests' '
223 blob=$(echo "missing have" | git hash-object -w --stdin) &&
224 tree=$(printf "100644 blob $blob\tfile\n" | git mktree) &&
225 parent=$(echo parent | git commit-tree $tree) &&
226 commit=$(echo commit | git commit-tree $tree -p $parent) &&
227 cat >revs <<-EOF
228 HEAD
229 ^HEAD^
230 ^$commit
234 test_expect_success 'pack-objects respects --incremental' '
235 cat >revs2 <<-EOF &&
236 HEAD
237 $commit
239 git pack-objects --incremental --stdout --revs <revs2 >4.pack &&
240 git index-pack 4.pack &&
241 list_packed_objects 4.idx >4.objects &&
242 test_line_count = 4 4.objects &&
243 git rev-list --objects $commit >revlist &&
244 cut -d" " -f1 revlist |sort >objects &&
245 test_cmp 4.objects objects
248 test_expect_success 'pack with missing blob' '
249 rm $(objpath $blob) &&
250 git pack-objects --stdout --revs <revs >/dev/null
253 test_expect_success 'pack with missing tree' '
254 rm $(objpath $tree) &&
255 git pack-objects --stdout --revs <revs >/dev/null
258 test_expect_success 'pack with missing parent' '
259 rm $(objpath $parent) &&
260 git pack-objects --stdout --revs <revs >/dev/null
263 test_expect_success JGIT 'we can read jgit bitmaps' '
264 git clone . compat-jgit &&
266 cd compat-jgit &&
267 rm -f .git/objects/pack/*.bitmap &&
268 jgit gc &&
269 git rev-list --test-bitmap HEAD
273 test_expect_success JGIT 'jgit can read our bitmaps' '
274 git clone . compat-us &&
276 cd compat-us &&
277 git repack -adb &&
278 # jgit gc will barf if it does not like our bitmaps
279 jgit gc
283 test_expect_success 'splitting packs does not generate bogus bitmaps' '
284 test-genrandom foo $((1024 * 1024)) >rand &&
285 git add rand &&
286 git commit -m "commit with big file" &&
287 git -c pack.packSizeLimit=500k repack -adb &&
288 git init --bare no-bitmaps.git &&
289 git -C no-bitmaps.git fetch .. HEAD
292 test_done