Skip to content

Commit 3b40c7e

Browse files
derrickstoleeKevin Willford
authored andcommitted
midx: responding to PR feedback
Signed-off-by: Derrick Stolee <[email protected]>
1 parent 336f98f commit 3b40c7e

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

midx.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static struct midxed_git *load_midxed_git_one(const char *midx_file, const char
135135

136136
hdr = midx_map;
137137
if (ntohl(hdr->midx_signature) != MIDX_SIGNATURE) {
138-
uint32_t signature = hdr->midx_signature;
138+
uint32_t signature = ntohl(hdr->midx_signature);
139139
munmap(midx_map, midx_size);
140140
close(fd);
141141
die("midx signature %X does not match signature %X",
@@ -195,6 +195,10 @@ static struct midxed_git *load_midxed_git_one(const char *midx_file, const char
195195
case MIDX_CHUNKID_LARGEOFFSETS:
196196
midx->chunk_large_offsets = data + chunk_offset;
197197
break;
198+
199+
default:
200+
/* We allow optional MIDX chunks, so ignore unrecognized chunk ids */
201+
break;
198202
}
199203
}
200204

@@ -864,7 +868,12 @@ const char *write_midx_file(const char *pack_dir,
864868
sorted_by_sha, nr_objects);
865869
break;
866870

867-
/* We allow optional MIDX chunks, so ignore unrecognized chunk ids */
871+
case 0:
872+
break;
873+
874+
default:
875+
BUG("midx tried to write an invalid chunk ID %08X", chunk_ids[chunk]);
876+
break;
868877
}
869878
}
870879

t/t5319-midx.sh

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ test_expect_success 'Verify normal git operations succeed' '
218218
test_line_count = 90 rev-list-out-8
219219
'
220220

221-
# The 'verify' commands below expect a midx-head file pointint
221+
# The 'verify' commands below expect a midx-head file pointing
222222
# to an existing MIDX file.
223223
test_expect_success 'recompute valid midx' '
224224
git midx --write --update-head --pack-dir .
@@ -269,19 +269,19 @@ test_expect_success 'midx --verify succeeds' '
269269
git midx --verify --pack-dir .
270270
'
271271

272-
# usage: corrupt_midx_and_verify <pos> <data> <string>
272+
# usage: corrupt_midx_and_verify <pos> <data> <string> [<packdir>]
273273
corrupt_midx_and_verify() {
274274
pos=$1
275275
data="${2:-\0}"
276276
grepstr=$3
277-
packdir=$5
278-
midxid=$(cat midx-head) &&
279-
file=midx-$midxid.midx &&
280-
chmod a+w $file &&
281-
test_when_finished mv midx-backup $file &&
282-
cp $file midx-backup &&
277+
packdir=$4
278+
midxid=$(cat ./$packdir/midx-head) &&
279+
file=./$packdir/midx-$midxid.midx &&
280+
chmod a+w "$file" &&
281+
test_when_finished mv midx-backup "$file" &&
282+
cp "$file" midx-backup &&
283283
printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc &&
284-
test_must_fail git midx --verify --pack-dir ./$packdir 2>test_err &&
284+
test_must_fail git midx --verify --pack-dir "./$packdir" 2>test_err &&
285285
grep -v "^+" test_err >err &&
286286
grep "$grepstr" err
287287
}
@@ -401,16 +401,15 @@ test_expect_success 'force some 64-bit offsets with pack-objects' '
401401
echo "pack_names:" >>midx-read-expect-64 &&
402402
echo test-64-$pack64.pack >>midx-read-expect-64 &&
403403
echo "pack_dir: packs-64" >>midx-read-expect-64 &&
404-
test_cmp midx-read-out-64 midx-read-expect-64 &&
405-
rm -rf packs-64
404+
test_cmp midx-read-out-64 midx-read-expect-64
406405
'
407406

408407
HASH_LEN=20
409408
MIDX_OFFSET_CHUNK_LOOKUP=16
410409
MIDX_WIDTH_CHUNK_LOOKUP=12
411410
MIDX_NUM_CHUNKS=7
412411
MIDX_NUM_PACKS=1
413-
MIDX_NUM_OBJECTS=55
412+
MIDX_NUM_OBJECTS=65
414413
MIDX_OFFSET_PACKLOOKUP=`expr $MIDX_OFFSET_CHUNK_LOOKUP + \
415414
$MIDX_NUM_CHUNKS \* $MIDX_WIDTH_CHUNK_LOOKUP`
416415
MIDX_OFFSET_OID_FANOUT=`expr $MIDX_OFFSET_PACKLOOKUP + \
@@ -421,9 +420,7 @@ MIDX_OFFSET_OBJECT_OFFSETS=`expr $MIDX_OFFSET_OID_LOOKUP + \
421420
MIDX_WIDTH_OBJECT_OFFSETS=8
422421
MIDX_OFFSET_LARGE_OFFSETS=`expr $MIDX_OFFSET_OBJECT_OFFSETS + \
423422
$MIDX_WIDTH_OBJECT_OFFSETS \* $MIDX_NUM_OBJECTS`
424-
MIDX_WIDTH_LARGE_OFFSETS=8
425-
MIDX_BYTE_LARGE_OFFSETS=`expr $MIDX_OFFSET_LARGE_OFFSETS + \
426-
$MIDX_WIDTH_LARGE_OFFSETS \* 5 + 3`
423+
MIDX_BYTE_LARGE_OFFSETS=`expr $MIDX_OFFSET_LARGE_OFFSETS + 3`
427424

428425
test_expect_success 'verify bad 64-bit offset' '
429426
corrupt_midx_and_verify $MIDX_BYTE_LARGE_OFFSETS "\01" \

0 commit comments

Comments
 (0)