t9300: use perl "head -c" clone in place of "dd bs=1 count=16000" kluge
It is unfortunate to have to issue thousands of one-byte read calls to work around dd's refusal to buffer input that would fill a block after a short read (a3a6f4, 2010-12-13). We could do better by using "head -c", if it were available on all platforms we cared about. Replace it with some simple perl. While doing so, restructure 9300.114 to use a subshell instead of a script. Subshells can inherit functions (like the new head_c) from the parent shell while external scripts cannot. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
834d9eb6b7
commit
4de0bbd898
@ -7,6 +7,23 @@ test_description='test git fast-import utility'
|
|||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
|
. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
|
||||||
|
|
||||||
|
# Print $1 bytes from stdin to stdout.
|
||||||
|
#
|
||||||
|
# This could be written as "head -c $1", but IRIX "head" does not
|
||||||
|
# support the -c option.
|
||||||
|
head_c () {
|
||||||
|
perl -e '
|
||||||
|
my $len = $ARGV[1];
|
||||||
|
while ($len > 0) {
|
||||||
|
my $s;
|
||||||
|
my $nread = sysread(STDIN, $s, $len);
|
||||||
|
die "cannot read: $!" unless defined($nread);
|
||||||
|
print $s;
|
||||||
|
$len -= $nread;
|
||||||
|
}
|
||||||
|
' - "$1"
|
||||||
|
}
|
||||||
|
|
||||||
file2_data='file2
|
file2_data='file2
|
||||||
second line of EOF'
|
second line of EOF'
|
||||||
|
|
||||||
@ -1888,24 +1905,29 @@ test_expect_success PIPE 'R: copy using cat-file' '
|
|||||||
rm -f blobs &&
|
rm -f blobs &&
|
||||||
cat >frontend <<-\FRONTEND_END &&
|
cat >frontend <<-\FRONTEND_END &&
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
cat <<EOF &&
|
FRONTEND_END
|
||||||
|
|
||||||
|
mkfifo blobs &&
|
||||||
|
(
|
||||||
|
export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
|
||||||
|
cat <<-\EOF &&
|
||||||
feature cat-blob
|
feature cat-blob
|
||||||
blob
|
blob
|
||||||
mark :1
|
mark :1
|
||||||
data <<BLOB
|
data <<BLOB
|
||||||
EOF
|
EOF
|
||||||
cat big
|
cat big &&
|
||||||
cat <<EOF
|
cat <<-\EOF &&
|
||||||
BLOB
|
BLOB
|
||||||
cat-blob :1
|
cat-blob :1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
read blob_id type size <&3 &&
|
read blob_id type size <&3 &&
|
||||||
echo "$blob_id $type $size" >response &&
|
echo "$blob_id $type $size" >response &&
|
||||||
dd of=blob bs=1 count=$size <&3 &&
|
head_c $size >blob <&3 &&
|
||||||
read newline <&3 &&
|
read newline <&3 &&
|
||||||
|
|
||||||
cat <<EOF &&
|
cat <<-EOF &&
|
||||||
commit refs/heads/copied
|
commit refs/heads/copied
|
||||||
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
|
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
|
||||||
data <<COMMIT
|
data <<COMMIT
|
||||||
@ -1915,17 +1937,9 @@ test_expect_success PIPE 'R: copy using cat-file' '
|
|||||||
data <<BLOB
|
data <<BLOB
|
||||||
EOF
|
EOF
|
||||||
cat blob &&
|
cat blob &&
|
||||||
cat <<EOF
|
echo BLOB
|
||||||
BLOB
|
) 3<blobs |
|
||||||
EOF
|
git fast-import --cat-blob-fd=3 3>blobs &&
|
||||||
FRONTEND_END
|
|
||||||
|
|
||||||
mkfifo blobs &&
|
|
||||||
(
|
|
||||||
export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
|
|
||||||
sh frontend 3<blobs |
|
|
||||||
git fast-import --cat-blob-fd=3 3>blobs
|
|
||||||
) &&
|
|
||||||
git show copied:file3 >actual &&
|
git show copied:file3 >actual &&
|
||||||
test_cmp expect.response response &&
|
test_cmp expect.response response &&
|
||||||
test_cmp big actual
|
test_cmp big actual
|
||||||
@ -1953,7 +1967,7 @@ test_expect_success PIPE 'R: print blob mid-commit' '
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
read blob_id type size <&3 &&
|
read blob_id type size <&3 &&
|
||||||
dd of=actual bs=1 count=$size <&3 &&
|
head_c $size >actual <&3 &&
|
||||||
read newline <&3 &&
|
read newline <&3 &&
|
||||||
|
|
||||||
echo
|
echo
|
||||||
@ -1988,7 +2002,7 @@ test_expect_success PIPE 'R: print staged blob within commit' '
|
|||||||
echo "cat-blob $to_get" &&
|
echo "cat-blob $to_get" &&
|
||||||
|
|
||||||
read blob_id type size <&3 &&
|
read blob_id type size <&3 &&
|
||||||
dd of=actual bs=1 count=$size <&3 &&
|
head_c $size >actual <&3 &&
|
||||||
read newline <&3 &&
|
read newline <&3 &&
|
||||||
|
|
||||||
echo deleteall
|
echo deleteall
|
||||||
|
Loading…
Reference in New Issue
Block a user