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 cannot create bitmaps' '
122 test_commit more-1 &&
123 find .git/objects/pack -name "*.bitmap" >expect &&
125 find .git/objects/pack -name "*.bitmap" >actual &&
126 test_cmp expect actual
129 test_expect_success 'incremental repack can disable bitmaps' '
130 test_commit more-2 &&
131 git repack -d --no-write-bitmap-index
134 test_expect_success 'pack-objects respects --local (non-local loose)' '
135 git init --bare alt.git &&
136 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
137 echo content1 >file1 &&
138 # non-local loose object which is not present in bitmapped pack
139 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
140 # non-local loose object which is also present in bitmapped pack
141 git cat-file blob $blob | GIT_DIR=alt.git git hash-object -w --stdin &&
144 git commit -m commit_file1 &&
145 echo HEAD | git pack-objects --local --stdout --revs >1.pack &&
146 git index-pack 1.pack &&
147 list_packed_objects 1.idx >1.objects &&
148 printf "%s\n" "$altblob" "$blob" >nonlocal-loose &&
149 ! has_any nonlocal-loose 1.objects
152 test_expect_success 'pack-objects respects --honor-pack-keep (local non-bitmapped pack)' '
153 echo content2 >file2 &&
154 blob2=$(git hash-object -w file2) &&
157 git commit -m commit_file2 &&
158 printf "%s\n" "$blob2" "$bitmaptip" >keepobjects &&
159 pack2=$(git pack-objects pack2 <keepobjects) &&
160 mv pack2-$pack2.* .git/objects/pack/ &&
161 >.git/objects/pack/pack2-$pack2.keep &&
162 rm $(objpath $blob2) &&
163 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >2a.pack &&
164 git index-pack 2a.pack &&
165 list_packed_objects 2a.idx >2a.objects &&
166 ! has_any keepobjects 2a.objects
169 test_expect_success 'pack-objects respects --local (non-local pack)' '
170 mv .git/objects/pack/pack2-$pack2.* alt.git/objects/pack/ &&
171 echo HEAD | git pack-objects --local --stdout --revs >2b.pack &&
172 git index-pack 2b.pack &&
173 list_packed_objects 2b.idx >2b.objects &&
174 ! has_any keepobjects 2b.objects
177 test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pack)' '
178 ls .git/objects/pack/ | grep bitmap >output &&
179 test_line_count = 1 output &&
180 packbitmap=$(basename $(cat output) .bitmap) &&
181 list_packed_objects .git/objects/pack/$packbitmap.idx >packbitmap.objects &&
182 test_when_finished "rm -f .git/objects/pack/$packbitmap.keep" &&
183 >.git/objects/pack/$packbitmap.keep &&
184 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >3a.pack &&
185 git index-pack 3a.pack &&
186 list_packed_objects 3a.idx >3a.objects &&
187 ! has_any packbitmap.objects 3a.objects
190 test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
191 mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
192 test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
193 echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
194 git index-pack 3b.pack &&
195 list_packed_objects 3b.idx >3b.objects &&
196 ! has_any packbitmap.objects 3b.objects
199 test_expect_success 'pack-objects to file can use bitmap' '
200 # make sure we still have 1 bitmap index from previous tests
201 ls .git/objects/pack/ | grep bitmap >output &&
202 test_line_count = 1 output &&
203 # verify equivalent packs are generated with/without using bitmap index
204 packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
205 packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
206 list_packed_objects <packa-$packasha1.idx >packa.objects &&
207 list_packed_objects <packb-$packbsha1.idx >packb.objects &&
208 test_cmp packa.objects packb.objects
211 test_expect_success 'full repack, reusing previous bitmaps' '
213 ls .git/objects/pack/ | grep bitmap >output &&
214 test_line_count = 1 output
217 test_expect_success 'fetch (full bitmap)' '
218 git --git-dir=clone.git fetch origin master:master &&
219 git rev-parse HEAD >expect &&
220 git --git-dir=clone.git rev-parse HEAD >actual &&
221 test_cmp expect actual
224 test_expect_success 'create objects for missing-HAVE tests' '
225 blob=$(echo "missing have" | git hash-object -w --stdin) &&
226 tree=$(printf "100644 blob $blob\tfile\n" | git mktree) &&
227 parent=$(echo parent | git commit-tree $tree) &&
228 commit=$(echo commit | git commit-tree $tree -p $parent) &&
236 test_expect_success 'pack-objects respects --incremental' '
241 git pack-objects --incremental --stdout --revs <revs2 >4.pack &&
242 git index-pack 4.pack &&
243 list_packed_objects 4.idx >4.objects &&
244 test_line_count = 4 4.objects &&
245 git rev-list --objects $commit >revlist &&
246 cut -d" " -f1 revlist |sort >objects &&
247 test_cmp 4.objects objects
250 test_expect_success 'pack with missing blob' '
251 rm $(objpath $blob) &&
252 git pack-objects --stdout --revs <revs >/dev/null
255 test_expect_success 'pack with missing tree' '
256 rm $(objpath $tree) &&
257 git pack-objects --stdout --revs <revs >/dev/null
260 test_expect_success 'pack with missing parent' '
261 rm $(objpath $parent) &&
262 git pack-objects --stdout --revs <revs >/dev/null
265 test_expect_success JGIT 'we can read jgit bitmaps' '
266 git clone . compat-jgit &&
269 rm -f .git/objects/pack/*.bitmap &&
271 git rev-list --test-bitmap HEAD
275 test_expect_success JGIT 'jgit can read our bitmaps' '
276 git clone . compat-us &&
280 # jgit gc will barf if it does not like our bitmaps
285 test_expect_success 'splitting packs does not generate bogus bitmaps' '
286 test-genrandom foo $((1024 * 1024)) >rand &&
288 git commit -m "commit with big file" &&
289 git -c pack.packSizeLimit=500k repack -adb &&
290 git init --bare no-bitmaps.git &&
291 git -C no-bitmaps.git fetch .. HEAD