Skip to content

Commit f546151

Browse files
peffgitster
authored andcommitted
t1006: add tests for %(objectsize:disk)
Back when we added this placeholder in a4ac106 (cat-file: add %(objectsize:disk) format atom, 2013-07-10), there were no tests, claiming "[...]the exact numbers returned are volatile and subject to zlib and packing decisions". But we can use a little shell hackery to get the expected numbers ourselves. To a certain degree this is just re-implementing what Git is doing under the hood, but it is still worth doing. It makes sure we exercise the %(objectsize:disk) code at all, and having the two implementations agree gives us more confidence. Note that our shell code assumes that no object appears twice (either in two packs, or as both loose and packed), as then the results really are undefined. That's OK for our purposes, and the test will notice if that assumption is violated (the shell version would produce duplicate lines that Git's output does not have). Helped-by: René Scharfe <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 564d025 commit f546151

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

t/t1006-cat-file.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,40 @@ test_expect_success 'cat-file --batch="batman" with --batch-all-objects will wor
11001100
cmp expect actual
11011101
'
11021102

1103+
test_expect_success 'cat-file %(objectsize:disk) with --batch-all-objects' '
1104+
# our state has both loose and packed objects,
1105+
# so find both for our expected output
1106+
{
1107+
find .git/objects/?? -type f |
1108+
awk -F/ "{ print \$0, \$3\$4 }" |
1109+
while read path oid
1110+
do
1111+
size=$(test_file_size "$path") &&
1112+
echo "$oid $size" ||
1113+
return 1
1114+
done &&
1115+
rawsz=$(test_oid rawsz) &&
1116+
find .git/objects/pack -name "*.idx" |
1117+
while read idx
1118+
do
1119+
git show-index <"$idx" >idx.raw &&
1120+
sort -n <idx.raw >idx.sorted &&
1121+
packsz=$(test_file_size "${idx%.idx}.pack") &&
1122+
end=$((packsz - rawsz)) &&
1123+
awk -v end="$end" "
1124+
NR > 1 { print oid, \$1 - start }
1125+
{ start = \$1; oid = \$2 }
1126+
END { print oid, end - start }
1127+
" idx.sorted ||
1128+
return 1
1129+
done
1130+
} >expect.raw &&
1131+
sort <expect.raw >expect &&
1132+
git cat-file --batch-all-objects \
1133+
--batch-check="%(objectname) %(objectsize:disk)" >actual &&
1134+
test_cmp expect actual
1135+
'
1136+
11031137
test_expect_success 'set up replacement object' '
11041138
orig=$(git rev-parse HEAD) &&
11051139
git cat-file commit $orig >orig &&

0 commit comments

Comments
 (0)