git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH squash] Simplify test-terminal.perl

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Feb 20, 2010, 09:48 UTC
Message-ID
<20100220094820.GA32456@progeny.tock>
In-Reply-To
<20100220085025.GA26788@progeny.tock>

The File::Copy module is included with perl (since version 5.002, 1995), so this simplification comes for free. It does not make the test noticeably faster or slower.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Jonathan Nieder wrote:
> it is much slower than the C version.

I take that back. The perl version takes roughly 3.7 s and the C version 3.4 s here (both with hot cache). Noticeable alone, but a tiny blip in the context of a full test run.

Sorry to mislead.
 t/t7006/test-terminal.perl |   26 +++++++-------------------
 1 files changed, 7 insertions(+), 19 deletions(-)
diff --git a/t/t7006/test-terminal.perl b/t/t7006/test-terminal.perl
index b51cfc6..73ff809 100755
--- a/t/t7006/test-terminal.perl
+++ b/t/t7006/test-terminal.perl
@@ -2,8 +2,9 @@
 use strict;
 use warnings;
 use IO::Pty;
+use File::Copy;
 
-# Fork and execute @$argv with stdout redirected to $out.
+# Run @$argv in the background with stdout redirected to $out.
 sub start_child {
 	my ($argv, $out) = @_;
 	my $pid = fork;
@@ -37,26 +38,13 @@ sub finish_child {
 sub xsendfile {
 	my ($out, $in) = @_;
 
-	my $buf;
-
 	# Note: the real sendfile() cannot read from a terminal.
-	for (;;) {
-		my $n = sysread $in, $buf, 4096;
 
-		# It is unspecified by POSIX whether reads
-		# from a disconnected terminal will return
-		# EIO (as in AIX 4.x, IRIX, and Linux) or
-		# end-of-file.  Either is fine.
-		if (!defined($n) && $!{EIO}) {
-			return;
-		} elsif (!defined($n)) {
-			die "cannot read from child: $!";
-		} elsif ($n == 0) {
-			return;
-		} else {
-			print $out $buf or die "write error: $!";
-		}
-	}
+	# It is unspecified by POSIX whether reads
+	# from a disconnected terminal will return
+	# EIO (as in AIX 4.x, IRIX, and Linux) or
+	# end-of-file.  Either is fine.
+	copy($in, $out, 4096) or $!{EIO} or die "cannot copy from child: $!";
 }
 
 if ($#ARGV < 1) {
-- 
1.7.0
Previous: Jonathan Nieder
Message 26 of 26 in “Re: 'git svn log' no longer uses the pager”
  1. 0/7 Re: 'git svn log' no longer uses the pagerJonathan Nieder, Feb 19, 2010
  2. 1/7 Fix 'git var' usage synopsisJonathan Nieder, Feb 19, 2010
  3. 2/7 Make 'git var GIT_PAGER' always print the configured pagerJonathan Nieder, Feb 19, 2010
  4. 3/7 git.1: Clarify the behavior of the --paginate optionJonathan Nieder, Feb 19, 2010
  5. 4/7 git svn: Fix launching of pagerJonathan Nieder, Feb 19, 2010
  6. 5/7 am: Fix launching of pagerJonathan Nieder, Feb 19, 2010
  7. 6/7 tests: Add tests for automatic use of pagerJonathan Nieder, Feb 19, 2010
  8. Junio C HamanoFeb 20, 2010
  9. 6/7 tests: Add tests for automatic use of pagerJonathan Nieder, Feb 21, 2010
  10. 7/7 t7006-pager: if stdout is not a terminal, make a new oneJonathan Nieder, Feb 21, 2010
  11. Jeff KingFeb 21, 2010
  12. Johannes SixtFeb 22, 2010
  13. 8/7 tests: Fix race condition in t7006-pagerJonathan Nieder, Feb 22, 2010
  14. Jonathan NiederFeb 22, 2010
  15. 7/7 t7006-pager: if stdout is not a terminal, make a new oneJonathan Nieder, Feb 19, 2010
  16. Jeff KingFeb 19, 2010
  17. Jonathan NiederFeb 19, 2010
  18. Jeff KingFeb 19, 2010
  19. Brandon CaseyFeb 19, 2010
  20. Brandon CaseyFeb 20, 2010
  21. Jonathan NiederFeb 20, 2010
  22. Brandon CaseyFeb 20, 2010
  23. 7/7 t7006-pager: if stdout is not a terminal, make a new oneJonathan Nieder, Feb 20, 2010
  24. Junio C HamanoFeb 20, 2010
  25. 7/7 t7006-pager: if stdout is not a terminal, make a new oneJonathan Nieder, Feb 20, 2010
  26. Simplify test-terminal.perlJonathan Nieder, Feb 20, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.