{"thread":{"id":"4742","subject":"[PATCH] send-email: do not barf when Term::ReadLine does not like your terminal","startedAt":"2006-07-02T23:03:59Z","lastAt":"2006-07-04T01:44:44Z","messageCount":2,"participants":["Junio C Hamano","Ryan Anderson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"23063","messageId":"7vpsgn1ue8.fsf@assigned-by-dhcp.cox.net","threadId":"4742","inReplyTo":null,"subject":"[PATCH] send-email: do not barf when Term::ReadLine does not like your terminal","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-07-02T23:03:59Z","receivedAt":"2006-07-02T23:03:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"As long as we do not need to readline from the terminal, we\nshould not barf when starting up the program.  Without this\npatch, t9001 test on Cygwin occasionally died with the following\nerror message:\n\nUnable to get Terminal Size. The TIOCGWINSZ ioctl didn't work. The COLUMNS and LINES environment variables didn't work. The resize program didn't work. at /usr/lib/perl5/vendor_perl/5.8/cygwin/Term/ReadKey.pm line 362.\nCompilation failed in require at /usr/lib/perl5/vendor_perl/5.8/Term/ReadLine/Perl.pm line 58.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n * I do not use send-email myself that often so extra sets of\n   eyeballs are appreciated.\n\n git-send-email.perl   |   18 +++++++++++++++++-\n t/t9001-send-email.sh |   11 +++++++----\n 2 files changed, 24 insertions(+), 5 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex c5d9e73..b04b8f4 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -22,6 +22,17 @@ use Term::ReadLine;\n use Getopt::Long;\n use Data::Dumper;\n \n+package FakeTerm;\n+sub new {\n+\tmy ($class, $reason) = @_;\n+\treturn bless \\$reason, shift;\n+}\n+sub readline {\n+\tmy $self = shift;\n+\tdie \"Cannot use readline on FakeTerm: $$self\";\n+}\n+package main;\n+\n # most mail servers generate the Date: header, but not all...\n $ENV{LC_ALL} = 'C';\n use POSIX qw/strftime/;\n@@ -46,7 +57,12 @@ my $smtp_server;\n # Example reply to:\n #$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';\n \n-my $term = new Term::ReadLine 'git-send-email';\n+my $term = eval {\n+\tnew Term::ReadLine 'git-send-email';\n+};\n+if ($@) {\n+\t$term = new FakeTerm \"$@: going non-interactive\";\n+}\n \n # Begin by accumulating all the variables (defined above), that we will end up\n # needing, first, from the command line:\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex a61da1e..e9ea33c 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -25,10 +25,13 @@ test_expect_success \\\n      git add fake.sendmail\n      GIT_AUTHOR_NAME=\"A\" git commit -a -m \"Second.\"'\n \n-test_expect_success \\\n-    'Extract patches and send' \\\n-    'git format-patch -n HEAD^1\n-     git send-email -from=\"Example <nobody@example.com>\" --to=nobody@example.com --smtp-server=\"$(pwd)/fake.sendmail\" ./0001*txt'\n+test_expect_success 'Extract patches' '\n+    patches=`git format-patch -n HEAD^1`\n+'\n+\n+test_expect_success 'Send patches' '\n+     git send-email -from=\"Example <nobody@example.com>\" --to=nobody@example.com --smtp-server=\"$(pwd)/fake.sendmail\" $patches 2>errors\n+'\n \n cat >expected <<\\EOF\n !nobody@example.com!\n-- \n1.4.1.gc92a\n"},{"id":"23165","messageId":"44A9C80C.90407@michonline.com","threadId":"4742","inReplyTo":"7vpsgn1ue8.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] send-email: do not barf when Term::ReadLine does not like your terminal","fromName":"Ryan Anderson","fromEmail":"ryan@michonline.com","sentAt":"2006-07-04T01:44:44Z","receivedAt":"2006-07-04T01:44:44Z","isPatch":true,"sender":{"key":"ryan@michonline.com","avatar":null},"body":"Junio C Hamano wrote:\n> As long as we do not need to readline from the terminal, we\n> should not barf when starting up the program.  Without this\n> patch, t9001 test on Cygwin occasionally died with the following\n> error message:\n>\n> Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work. The COLUMNS and LINES environment variables didn't work. The resize program didn't work. at /usr/lib/perl5/vendor_perl/5.8/cygwin/Term/ReadKey.pm line 362.\n> Compilation failed in require at /usr/lib/perl5/vendor_perl/5.8/Term/ReadLine/Perl.pm line 58.\n>\n> Signed-off-by: Junio C Hamano <junkio@cox.net>\n> ---\n>\n>  * I do not use send-email myself that often so extra sets of\n>    eyeballs are appreciated.\n>   \nLooks fine to me.\n\nAcked-by: Ryan Anderson <ryan@michonline.com>\n\n(I personally would have put the package declaration at the end of the\nfile, but it's not significant enough for me to send a patch, heh.)\n\n\n>  git-send-email.perl   |   18 +++++++++++++++++-\n>  t/t9001-send-email.sh |   11 +++++++----\n>  2 files changed, 24 insertions(+), 5 deletions(-)\n>\n> diff --git a/git-send-email.perl b/git-send-email.perl\n> index c5d9e73..b04b8f4 100755\n> --- a/git-send-email.perl\n> +++ b/git-send-email.perl\n> @@ -22,6 +22,17 @@ use Term::ReadLine;\n>  use Getopt::Long;\n>  use Data::Dumper;\n>  \n> +package FakeTerm;\n> +sub new {\n> +\tmy ($class, $reason) = @_;\n> +\treturn bless \\$reason, shift;\n> +}\n> +sub readline {\n> +\tmy $self = shift;\n> +\tdie \"Cannot use readline on FakeTerm: $$self\";\n> +}\n> +package main;\n> +\n>  # most mail servers generate the Date: header, but not all...\n>  $ENV{LC_ALL} = 'C';\n>  use POSIX qw/strftime/;\n> @@ -46,7 +57,12 @@ my $smtp_server;\n>  # Example reply to:\n>  #$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';\n>  \n> -my $term = new Term::ReadLine 'git-send-email';\n> +my $term = eval {\n> +\tnew Term::ReadLine 'git-send-email';\n> +};\n> +if ($@) {\n> +\t$term = new FakeTerm \"$@: going non-interactive\";\n> +}\n>  \n>  # Begin by accumulating all the variables (defined above), that we will end up\n>  # needing, first, from the command line:\n> diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\n> index a61da1e..e9ea33c 100755\n> --- a/t/t9001-send-email.sh\n> +++ b/t/t9001-send-email.sh\n> @@ -25,10 +25,13 @@ test_expect_success \\\n>       git add fake.sendmail\n>       GIT_AUTHOR_NAME=\"A\" git commit -a -m \"Second.\"'\n>  \n> -test_expect_success \\\n> -    'Extract patches and send' \\\n> -    'git format-patch -n HEAD^1\n> -     git send-email -from=\"Example <nobody@example.com>\" --to=nobody@example.com --smtp-server=\"$(pwd)/fake.sendmail\" ./0001*txt'\n> +test_expect_success 'Extract patches' '\n> +    patches=`git format-patch -n HEAD^1`\n> +'\n> +\n> +test_expect_success 'Send patches' '\n> +     git send-email -from=\"Example <nobody@example.com>\" --to=nobody@example.com --smtp-server=\"$(pwd)/fake.sendmail\" $patches 2>errors\n> +'\n>  \n>  cat >expected <<\\EOF\n>  !nobody@example.com!\n>   \n\n\n-- \n\nRyan Anderson\n  sometimes Pug Majere\n\n\n"}]}