Skip to content

Commit 4de0bbd

Browse files
jrngitster
authored andcommitted
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>
1 parent 834d9eb commit 4de0bbd

File tree

1 file changed

+49
-35
lines changed

1 file changed

+49
-35
lines changed

t/t9300-fast-import.sh

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ test_description='test git fast-import utility'
77
. ./test-lib.sh
88
. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
99

10+
# Print $1 bytes from stdin to stdout.
11+
#
12+
# This could be written as "head -c $1", but IRIX "head" does not
13+
# support the -c option.
14+
head_c () {
15+
perl -e '
16+
my $len = $ARGV[1];
17+
while ($len > 0) {
18+
my $s;
19+
my $nread = sysread(STDIN, $s, $len);
20+
die "cannot read: $!" unless defined($nread);
21+
print $s;
22+
$len -= $nread;
23+
}
24+
' - "$1"
25+
}
26+
1027
file2_data='file2
1128
second line of EOF'
1229

@@ -1888,44 +1905,41 @@ test_expect_success PIPE 'R: copy using cat-file' '
18881905
rm -f blobs &&
18891906
cat >frontend <<-\FRONTEND_END &&
18901907
#!/bin/sh
1891-
cat <<EOF &&
1892-
feature cat-blob
1893-
blob
1894-
mark :1
1895-
data <<BLOB
1896-
EOF
1897-
cat big
1898-
cat <<EOF
1899-
BLOB
1900-
cat-blob :1
1901-
EOF
1902-
1903-
read blob_id type size <&3 &&
1904-
echo "$blob_id $type $size" >response &&
1905-
dd of=blob bs=1 count=$size <&3 &&
1906-
read newline <&3 &&
1907-
1908-
cat <<EOF &&
1909-
commit refs/heads/copied
1910-
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1911-
data <<COMMIT
1912-
copy big file as file3
1913-
COMMIT
1914-
M 644 inline file3
1915-
data <<BLOB
1916-
EOF
1917-
cat blob &&
1918-
cat <<EOF
1919-
BLOB
1920-
EOF
19211908
FRONTEND_END
19221909
19231910
mkfifo blobs &&
19241911
(
19251912
export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
1926-
sh frontend 3<blobs |
1927-
git fast-import --cat-blob-fd=3 3>blobs
1928-
) &&
1913+
cat <<-\EOF &&
1914+
feature cat-blob
1915+
blob
1916+
mark :1
1917+
data <<BLOB
1918+
EOF
1919+
cat big &&
1920+
cat <<-\EOF &&
1921+
BLOB
1922+
cat-blob :1
1923+
EOF
1924+
1925+
read blob_id type size <&3 &&
1926+
echo "$blob_id $type $size" >response &&
1927+
head_c $size >blob <&3 &&
1928+
read newline <&3 &&
1929+
1930+
cat <<-EOF &&
1931+
commit refs/heads/copied
1932+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1933+
data <<COMMIT
1934+
copy big file as file3
1935+
COMMIT
1936+
M 644 inline file3
1937+
data <<BLOB
1938+
EOF
1939+
cat blob &&
1940+
echo BLOB
1941+
) 3<blobs |
1942+
git fast-import --cat-blob-fd=3 3>blobs &&
19291943
git show copied:file3 >actual &&
19301944
test_cmp expect.response response &&
19311945
test_cmp big actual
@@ -1953,7 +1967,7 @@ test_expect_success PIPE 'R: print blob mid-commit' '
19531967
EOF
19541968
19551969
read blob_id type size <&3 &&
1956-
dd of=actual bs=1 count=$size <&3 &&
1970+
head_c $size >actual <&3 &&
19571971
read newline <&3 &&
19581972
19591973
echo
@@ -1988,7 +2002,7 @@ test_expect_success PIPE 'R: print staged blob within commit' '
19882002
echo "cat-blob $to_get" &&
19892003
19902004
read blob_id type size <&3 &&
1991-
dd of=actual bs=1 count=$size <&3 &&
2005+
head_c $size >actual <&3 &&
19922006
read newline <&3 &&
19932007
19942008
echo deleteall

0 commit comments

Comments
 (0)