@matheusbsbs / matheus-bagliano / commits / 4de0bbd898
Fork 0

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>

Jonathan Nieder committed Dec 13, 2010 at 03:28 UTC 4de0bbd8985ea057050994c5b254c9ef3d845c1e
1 file changed +49 -35
t/t9300-fast-import.sh
+49 -35
@@ -7,6 +7,23 @@ test_description='test git fast-import utility'
7 . ./test-lib.sh
8 . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
9
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 +
27 file2_data='file2
28 second line of EOF'
29
@@ -1888,44 +1905,41 @@ test_expect_success PIPE 'R: copy using cat-file' '
1905 rm -f blobs &&
1906 cat >frontend <<-\FRONTEND_END &&
1907 #!/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
1908 FRONTEND_END
1909
1910 mkfifo blobs &&
1911 (
1912 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 &&
1943 git show copied:file3 >actual &&
1944 test_cmp expect.response response &&
1945 test_cmp big actual
@@ -1953,7 +1967,7 @@ test_expect_success PIPE 'R: print blob mid-commit' '
1967 EOF
1968
1969 read blob_id type size <&3 &&
1956 - dd of=actual bs=1 count=$size <&3 &&
1970 + head_c $size >actual <&3 &&
1971 read newline <&3 &&
1972
1973 echo
@@ -1988,7 +2002,7 @@ test_expect_success PIPE 'R: print staged blob within commit' '
2002 echo "cat-blob $to_get" &&
2003
2004 read blob_id type size <&3 &&
1991 - dd of=actual bs=1 count=$size <&3 &&
2005 + head_c $size >actual <&3 &&
2006 read newline <&3 &&
2007
2008 echo deleteall