Skip to content

Commit

Permalink
more tr portability test script fixes
Browse files Browse the repository at this point in the history
Dealing with NULs is not always safe with tr. On Solaris,
incoming NULs are silently deleted by both the System V and
UCB versions of tr. When converting to NULs, the System V
version works fine, but the UCB version silently ignores the
request to convert the character.

This patch changes all instances of tr using NULs to use
"perl -pe 'y///'" instead.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
peff authored and gitster committed Mar 13, 2008
1 parent e8e29c7 commit e85fe4d
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions t/diff-lib.sh
Expand Up @@ -21,8 +21,8 @@ compare_diff_raw_z () {
# Also we do not check SHA1 hash generation in this test, which
# is a job for t0000-basic.sh

tr '\000' '\012' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1
tr '\000' '\012' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2
perl -pe 'y/\000/\012/' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1
perl -pe 'y/\000/\012/' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2
git diff .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
}

Expand Down
2 changes: 1 addition & 1 deletion t/t0020-crlf.sh
Expand Up @@ -5,7 +5,7 @@ test_description='CRLF conversion'
. ./test-lib.sh

q_to_nul () {
tr Q '\000'
perl -pe 'y/Q/\000/'
}

q_to_cr () {
Expand Down
4 changes: 2 additions & 2 deletions t/t1300-repo-config.sh
Expand Up @@ -657,12 +657,12 @@ Qsection.sub=section.val4
Qsection.sub=section.val5Q
EOF

git config --null --list | tr '\000' 'Q' > result
git config --null --list | perl -pe 'y/\000/Q/' > result
echo >>result

test_expect_success '--null --list' 'cmp result expect'

git config --null --get-regexp 'val[0-9]' | tr '\000' 'Q' > result
git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result
echo >>result

test_expect_success '--null --get-regexp' 'cmp result expect'
Expand Down
6 changes: 3 additions & 3 deletions t/t3300-funny-names.sh
Expand Up @@ -54,7 +54,7 @@ echo 'just space
no-funny
tabs ," (dq) and spaces' >expected
test_expect_success 'git ls-files -z with-funny' \
'git ls-files -z | tr \\000 \\012 >current &&
'git ls-files -z | perl -pe y/\\000/\\012/ >current &&
git diff expected current'

t1=`git write-tree`
Expand Down Expand Up @@ -83,11 +83,11 @@ test_expect_success 'git diff-tree with-funny' \
echo 'A
tabs ," (dq) and spaces' >expected
test_expect_success 'git diff-index -z with-funny' \
'git diff-index -z --name-status $t0 | tr \\000 \\012 >current &&
'git diff-index -z --name-status $t0 | perl -pe y/\\000/\\012/ >current &&
git diff expected current'

test_expect_success 'git diff-tree -z with-funny' \
'git diff-tree -z --name-status $t0 $t1 | tr \\000 \\012 >current &&
'git diff-tree -z --name-status $t0 $t1 | perl -pe y/\\000/\\012/ >current &&
git diff expected current'

cat > expected <<\EOF
Expand Down
2 changes: 1 addition & 1 deletion t/t4020-diff-external.sh
Expand Up @@ -99,7 +99,7 @@ test_expect_success 'no diff with -diff' '
git diff | grep Binary
'

echo NULZbetweenZwords | tr Z '\000' > file
echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file

test_expect_success 'force diff with "diff"' '
echo >.gitattributes "file diff" &&
Expand Down
4 changes: 2 additions & 2 deletions t/t4103-apply-binary.sh
Expand Up @@ -24,10 +24,10 @@ git update-index --add --remove file1 file2 file4
git-commit -m 'Initial Version' 2>/dev/null

git-checkout -b binary
tr 'x' '\000' <file1 >file3
perl -pe 'y/x/\000/' <file1 >file3
cat file3 >file4
git add file2
tr '\000' 'v' <file3 >file1
perl -pe 'y/\000/v/' <file3 >file1
rm -f file2
git update-index --add --remove file1 file2 file3 file4
git-commit -m 'Second Version'
Expand Down
4 changes: 2 additions & 2 deletions t/t4116-apply-reverse.sh
Expand Up @@ -12,14 +12,14 @@ test_description='git apply in reverse
test_expect_success setup '
for i in a b c d e f g h i j k l m n; do echo $i; done >file1 &&
tr "ijk" '\''\000\001\002'\'' <file1 >file2 &&
perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
git add file1 file2 &&
git commit -m initial &&
git tag initial &&
for i in a b c g h i J K L m o n p q; do echo $i; done >file1 &&
tr "mon" '\''\000\001\002'\'' <file1 >file2 &&
perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
git commit -a -m second &&
git tag second &&
Expand Down
2 changes: 1 addition & 1 deletion t/t4200-rerere.sh
Expand Up @@ -129,7 +129,7 @@ test_expect_success 'rerere kicked in' "! grep ======= a1"
test_expect_success 'rerere prefers first change' 'git diff a1 expect'

rm $rr/postimage
echo "$sha1 a1" | tr '\012' '\000' > .git/rr-cache/MERGE_RR
echo "$sha1 a1" | perl -pe 'y/\012/\000/' > .git/rr-cache/MERGE_RR

test_expect_success 'rerere clear' 'git rerere clear'

Expand Down
2 changes: 1 addition & 1 deletion t/t5300-pack-object.sh
Expand Up @@ -15,7 +15,7 @@ test_expect_success \
'rm -f .git/index*
for i in a b c
do
dd if=/dev/zero bs=4k count=1 | tr "\\000" $i >$i &&
dd if=/dev/zero bs=4k count=1 | perl -pe "y/\\000/$i/" >$i &&
git update-index --add $i || return 1
done &&
cat c >d && echo foo >>d && git update-index --add d &&
Expand Down
4 changes: 2 additions & 2 deletions test-sha1.sh
Expand Up @@ -10,7 +10,7 @@ do
{
test -z "$pfx" || echo "$pfx"
dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
tr '\000' 'g'
perl -pe 'y/\000/g/'
} | ./test-sha1 $cnt
`
if test "$expect" = "$actual"
Expand Down Expand Up @@ -55,7 +55,7 @@ do
{
test -z "$pfx" || echo "$pfx"
dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
tr '\000' 'g'
perl -pe 'y/\000/g/'
} | sha1sum |
sed -e 's/ .*//'
`
Expand Down

0 comments on commit e85fe4d

Please sign in to comment.