Skip to content

Commit 54d8a25

Browse files
rscharfegitster
authored andcommitted
t1006: prefer shell loop to awk for packed object sizes
To compute the expected on-disk size of packed objects, we sort the output of show-index by pack offset and then compute the difference between adjacent entries using awk. This works but has a few readability problems: 1. Reading the index in pack order means don't find out the size of an oid's entry until we see the _next_ entry. So we have to save it to print later. We can instead iterate in reverse order, so we compute each oid's size as we see it. 2. Since the awk invocation is inside a text_expect block, we can't easily use single-quotes to hold the script. So we use double-quotes, but then have to escape the dollar signs in the awk script. We can swap this out for a shell loop instead (which is made much easier by the first change). Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f546151 commit 54d8a25

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

t/t1006-cat-file.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,14 +1117,16 @@ test_expect_success 'cat-file %(objectsize:disk) with --batch-all-objects' '
11171117
while read idx
11181118
do
11191119
git show-index <"$idx" >idx.raw &&
1120-
sort -n <idx.raw >idx.sorted &&
1120+
sort -nr <idx.raw >idx.sorted &&
11211121
packsz=$(test_file_size "${idx%.idx}.pack") &&
11221122
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 ||
1123+
while read start oid rest
1124+
do
1125+
size=$((end - start)) &&
1126+
end=$start &&
1127+
echo "$oid $size" ||
1128+
return 1
1129+
done <idx.sorted ||
11281130
return 1
11291131
done
11301132
} >expect.raw &&

0 commit comments

Comments
 (0)