add-interactive: plug a leak in get_untracked_files
[git.git] / t / t5332-multi-pack-reuse.sh
blob3c20738bcebd82c2f9f8fa0d728c39bfe6ac525e
1 #!/bin/sh
3 test_description='pack-objects multi-pack reuse'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-bitmap.sh
9 objdir=.git/objects
10 packdir=$objdir/pack
12 test_pack_reused () {
13 test_trace2_data pack-objects pack-reused "$1"
16 test_packs_reused () {
17 test_trace2_data pack-objects packs-reused "$1"
21 # pack_position <object> </path/to/pack.idx
22 pack_position () {
23 git show-index >objects &&
24 grep "$1" objects | cut -d" " -f1
27 # test_pack_objects_reused_all <pack-reused> <packs-reused>
28 test_pack_objects_reused_all () {
29 : >trace2.txt &&
30 GIT_TRACE2_EVENT="$PWD/trace2.txt" \
31 git pack-objects --stdout --revs --all --delta-base-offset \
32 >/dev/null &&
34 test_pack_reused "$1" <trace2.txt &&
35 test_packs_reused "$2" <trace2.txt
38 # test_pack_objects_reused <pack-reused> <packs-reused>
39 test_pack_objects_reused () {
40 : >trace2.txt &&
41 GIT_TRACE2_EVENT="$PWD/trace2.txt" \
42 git pack-objects --stdout --revs >/dev/null &&
44 test_pack_reused "$1" <trace2.txt &&
45 test_packs_reused "$2" <trace2.txt
48 test_expect_success 'preferred pack is reused for single-pack reuse' '
49 test_config pack.allowPackReuse single &&
51 for i in A B
53 test_commit "$i" &&
54 git repack -d || return 1
55 done &&
57 git multi-pack-index write --bitmap &&
59 test_pack_objects_reused_all 3 1
62 test_expect_success 'multi-pack reuse is disabled by default' '
63 test_pack_objects_reused_all 3 1
66 test_expect_success 'feature.experimental implies multi-pack reuse' '
67 test_config feature.experimental true &&
69 test_pack_objects_reused_all 6 2
72 test_expect_success 'multi-pack reuse can be disabled with feature.experimental' '
73 test_config feature.experimental true &&
74 test_config pack.allowPackReuse single &&
76 test_pack_objects_reused_all 3 1
79 test_expect_success 'enable multi-pack reuse' '
80 git config pack.allowPackReuse multi
83 test_expect_success 'reuse all objects from subset of bitmapped packs' '
84 test_commit C &&
85 git repack -d &&
87 git multi-pack-index write --bitmap &&
89 cat >in <<-EOF &&
90 $(git rev-parse C)
91 ^$(git rev-parse A)
92 EOF
94 test_pack_objects_reused 6 2 <in
97 test_expect_success 'reuse all objects from all packs' '
98 test_pack_objects_reused_all 9 3
101 test_expect_success 'reuse objects from first pack with middle gap' '
102 for i in D E F
104 test_commit "$i" || return 1
105 done &&
107 # Set "pack.window" to zero to ensure that we do not create any
108 # deltas, which could alter the amount of pack reuse we perform
109 # (if, for e.g., we are not sending one or more bases).
110 D="$(git -c pack.window=0 pack-objects --all --unpacked $packdir/pack)" &&
112 d_pos="$(pack_position $(git rev-parse D) <$packdir/pack-$D.idx)" &&
113 e_pos="$(pack_position $(git rev-parse E) <$packdir/pack-$D.idx)" &&
114 f_pos="$(pack_position $(git rev-parse F) <$packdir/pack-$D.idx)" &&
116 # commits F, E, and D, should appear in that order at the
117 # beginning of the pack
118 test $f_pos -lt $e_pos &&
119 test $e_pos -lt $d_pos &&
121 # Ensure that the pack we are constructing sorts ahead of any
122 # other packs in lexical/bitmap order by choosing it as the
123 # preferred pack.
124 git multi-pack-index write --bitmap --preferred-pack="pack-$D.idx" &&
126 cat >in <<-EOF &&
127 $(git rev-parse E)
128 ^$(git rev-parse D)
131 test_pack_objects_reused 3 1 <in
134 test_expect_success 'reuse objects from middle pack with middle gap' '
135 rm -fr $packdir/multi-pack-index* &&
137 # Ensure that the pack we are constructing sort into any
138 # position *but* the first one, by choosing a different pack as
139 # the preferred one.
140 git multi-pack-index write --bitmap --preferred-pack="pack-$A.idx" &&
142 cat >in <<-EOF &&
143 $(git rev-parse E)
144 ^$(git rev-parse D)
147 test_pack_objects_reused 3 1 <in
150 test_expect_success 'omit delta with uninteresting base (same pack)' '
151 git repack -adk &&
153 test_seq 32 >f &&
154 git add f &&
155 test_tick &&
156 git commit -m "delta" &&
157 delta="$(git rev-parse HEAD)" &&
159 test_seq 64 >f &&
160 test_tick &&
161 git commit -a -m "base" &&
162 base="$(git rev-parse HEAD)" &&
164 test_commit other &&
166 git repack -d &&
168 have_delta "$(git rev-parse $delta:f)" "$(git rev-parse $base:f)" &&
170 git multi-pack-index write --bitmap &&
172 cat >in <<-EOF &&
173 $(git rev-parse other)
174 ^$base
177 # We can only reuse the 3 objects corresponding to "other" from
178 # the latest pack.
180 # This is because even though we want "delta", we do not want
181 # "base", meaning that we have to inflate the delta/base-pair
182 # corresponding to the blob in commit "delta", which bypasses
183 # the pack-reuse mechanism.
185 # The remaining objects from the other pack are similarly not
186 # reused because their objects are on the uninteresting side of
187 # the query.
188 test_pack_objects_reused 3 1 <in
191 test_expect_success 'omit delta from uninteresting base (cross pack)' '
192 cat >in <<-EOF &&
193 $(git rev-parse $base)
194 ^$(git rev-parse $delta)
197 P="$(git pack-objects --revs $packdir/pack <in)" &&
199 git multi-pack-index write --bitmap --preferred-pack="pack-$P.idx" &&
201 packs_nr="$(find $packdir -type f -name "pack-*.pack" | wc -l)" &&
202 objects_nr="$(git rev-list --count --all --objects)" &&
204 test_pack_objects_reused_all $(($objects_nr - 1)) $packs_nr
207 test_done