]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t1006: ensure cat-file info isn't buffered by default
authorEric Wong <e@80x24.org>
Tue, 18 Jun 2024 21:30:41 +0000 (21:30 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 Jun 2024 17:28:46 +0000 (10:28 -0700)
While working on buffering changes to `git cat-file' in a
separate patch, I inadvertently made the output of --batch-check
and the `info' command of --batch-command buffered as if
opt->buffer_output is turned on by default.

Buffering by default breaks some 3rd-party Perl scripts using
cat-file, but this breakage was not detected anywhere in our
test suite.  Add a small Perl snippet to test this problem since
(AFAIK) other equivalent ways to test this behavior from Bourne
shell and/or awk would require racy sleeps, non-portable FIFOs
or tedious C code.

Signed-off-by: Eric Wong <e@80x24.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t1006-cat-file.sh

index e12b2219721c4e9e1f29dd5eeb2e9b787d9b78db..ff9bf213aa2c73e42ab82d9b227fbbb7049c1e43 100755 (executable)
@@ -1294,4 +1294,34 @@ test_expect_success 'batch-command flush without --buffer' '
        grep "^fatal:.*flush is only for --buffer mode.*" err
 '
 
+script='
+use warnings;
+use strict;
+use IPC::Open2;
+my ($opt, $oid, $expect, @pfx) = @ARGV;
+my @cmd = (qw(git cat-file), $opt);
+my $pid = open2(my $out, my $in, @cmd) or die "open2: @cmd";
+print $in @pfx, $oid, "\n" or die "print $!";
+my $rvec = "";
+vec($rvec, fileno($out), 1) = 1;
+select($rvec, undef, undef, 30) or die "no response to `@pfx $oid` from @cmd";
+my $info = <$out>;
+chop($info) eq "\n" or die "no LF";
+$info eq $expect or die "`$info` != `$expect`";
+close $in or die "close in $!";
+close $out or die "close out $!";
+waitpid $pid, 0;
+$? == 0 or die "\$?=$?";
+'
+
+expect="$hello_oid blob $hello_size"
+
+test_expect_success PERL '--batch-check is unbuffered by default' '
+       perl -e "$script" -- --batch-check $hello_oid "$expect"
+'
+
+test_expect_success PERL '--batch-command info is unbuffered by default' '
+       perl -e "$script" -- --batch-command $hello_oid "$expect" "info "
+'
+
 test_done