Skip to content

Commit 7e7db5e

Browse files
harinathgitster
authored andcommitted
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 <[email protected]> Acked-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5536934 commit 7e7db5e

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

fast-import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ static void dump_marks_helper(FILE *f,
16661666
if (m->shift) {
16671667
for (k = 0; k < 1024; k++) {
16681668
if (m->data.sets[k])
1669-
dump_marks_helper(f, (base + k) << m->shift,
1669+
dump_marks_helper(f, base + (k << m->shift),
16701670
m->data.sets[k]);
16711671
}
16721672
} else {

t/t9300-fast-import.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,63 @@ test_expect_success \
166166
test `git rev-parse --verify master:file2` \
167167
= `git rev-parse --verify verify--import-marks:copy-of-file2`'
168168

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+
169226
###
170227
### series B
171228
###

0 commit comments

Comments
 (0)