@matheusbsbs / matheus-bagliano / commits / 7e7db5e452
Fork 0

fast-import: export correctly marks larger than 2^20-1

dump_marks_helper() has a bug when dumping marks larger than 2^20-1, i.e., when the sparse array has more than two levels. The bug was that the 'base' counter was being shifted by 20 bits at level 3, and then again by 10 bits at level 2, rather than a total shift of 20 bits in this argument to the recursive call: (base + k) << m->shift There are two ways to fix this correctly, the elegant: (base + k) << 10 and the one I chose due to edit distance: base + (k << m->shift) Signed-off-by: Raja R Harinath <harinath@hurrynot.org> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Raja R Harinath committed Jul 13, 2010 at 17:21 UTC 7e7db5e4520388d3a6f1efbe2f7a29d43bd06a2b
2 files changed +58 -1
fast-import.c
+1 -1
@@ -1666,7 +1666,7 @@ static void dump_marks_helper(FILE *f,
1666 if (m->shift) {
1667 for (k = 0; k < 1024; k++) {
1668 if (m->data.sets[k])
1669 - dump_marks_helper(f, (base + k) << m->shift,
1669 + dump_marks_helper(f, base + (k << m->shift),
1670 m->data.sets[k]);
1671 }
1672 } else {
t/t9300-fast-import.sh
+57
@@ -166,6 +166,63 @@ test_expect_success \
166 test `git rev-parse --verify master:file2` \
167 = `git rev-parse --verify verify--import-marks:copy-of-file2`'
168
169 +test_tick
170 +mt=$(git hash-object --stdin < /dev/null)
171 +: >input.blob
172 +: >marks.exp
173 +: >tree.exp
174 +
175 +cat >input.commit <<EOF
176 +commit refs/heads/verify--dump-marks
177 +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
178 +data <<COMMIT
179 +test the sparse array dumping routines with exponentially growing marks
180 +COMMIT
181 +EOF
182 +
183 +i=0
184 +l=4
185 +m=6
186 +n=7
187 +while test "$i" -lt 27; do
188 + cat >>input.blob <<EOF
189 +blob
190 +mark :$l
191 +data 0
192 +blob
193 +mark :$m
194 +data 0
195 +blob
196 +mark :$n
197 +data 0
198 +EOF
199 + echo "M 100644 :$l l$i" >>input.commit
200 + echo "M 100644 :$m m$i" >>input.commit
201 + echo "M 100644 :$n n$i" >>input.commit
202 +
203 + echo ":$l $mt" >>marks.exp
204 + echo ":$m $mt" >>marks.exp
205 + echo ":$n $mt" >>marks.exp
206 +
207 + printf "100644 blob $mt\tl$i\n" >>tree.exp
208 + printf "100644 blob $mt\tm$i\n" >>tree.exp
209 + printf "100644 blob $mt\tn$i\n" >>tree.exp
210 +
211 + l=$(($l + $l))
212 + m=$(($m + $m))
213 + n=$(($l + $n))
214 +
215 + i=$((1 + $i))
216 +done
217 +
218 +sort tree.exp > tree.exp_s
219 +
220 +test_expect_success 'A: export marks with large values' '
221 + cat input.blob input.commit | git fast-import --export-marks=marks.large &&
222 + git ls-tree refs/heads/verify--dump-marks >tree.out &&
223 + test_cmp tree.exp_s tree.out &&
224 + test_cmp marks.exp marks.large'
225 +
226 ###
227 ### series B
228 ###