3 test_description
='exercise basic bitmap functionality'
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
22 test_expect_success
'setup repo with moderate-sized history' '
23 for i in $(test_seq 1 10); do
26 git checkout -b other HEAD~5 &&
27 for i in $(test_seq 1 10); do
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' '
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
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 &&
85 git rev-list --objects HEAD >tmp &&
86 cut -d" " -f1 <tmp >tmp2 &&
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 &&
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
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 &&
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) &&
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' '
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) &&
234 test_expect_success
'pack-objects respects --incremental' '
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 &&
267 rm -f .git/objects/pack/*.bitmap &&
269 git rev-list --test-bitmap HEAD
273 test_expect_success JGIT
'jgit can read our bitmaps' '
274 git clone . compat-us &&
278 # jgit gc will barf if it does not like our bitmaps
283 test_expect_success
'splitting packs does not generate bogus bitmaps' '
284 test-genrandom foo $((1024 * 1024)) >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