git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] send-email: do not barf when Term::ReadLine does not like your terminal
@ 2006-07-02 23:03 Junio C Hamano
  2006-07-04  1:44 ` Ryan Anderson
  0 siblings, 1 reply; 2+ messages in thread
From: Junio C Hamano @ 2006-07-02 23:03 UTC (permalink / raw)
  To: Ryan Anderson; +Cc: git

As long as we do not need to readline from the terminal, we
should not barf when starting up the program.  Without this
patch, t9001 test on Cygwin occasionally died with the following
error message:

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.
Compilation failed in require at /usr/lib/perl5/vendor_perl/5.8/Term/ReadLine/Perl.pm line 58.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

 * I do not use send-email myself that often so extra sets of
   eyeballs are appreciated.

 git-send-email.perl   |   18 +++++++++++++++++-
 t/t9001-send-email.sh |   11 +++++++----
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index c5d9e73..b04b8f4 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -22,6 +22,17 @@ use Term::ReadLine;
 use Getopt::Long;
 use Data::Dumper;
 
+package FakeTerm;
+sub new {
+	my ($class, $reason) = @_;
+	return bless \$reason, shift;
+}
+sub readline {
+	my $self = shift;
+	die "Cannot use readline on FakeTerm: $$self";
+}
+package main;
+
 # most mail servers generate the Date: header, but not all...
 $ENV{LC_ALL} = 'C';
 use POSIX qw/strftime/;
@@ -46,7 +57,12 @@ my $smtp_server;
 # Example reply to:
 #$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';
 
-my $term = new Term::ReadLine 'git-send-email';
+my $term = eval {
+	new Term::ReadLine 'git-send-email';
+};
+if ($@) {
+	$term = new FakeTerm "$@: going non-interactive";
+}
 
 # Begin by accumulating all the variables (defined above), that we will end up
 # needing, first, from the command line:
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index a61da1e..e9ea33c 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -25,10 +25,13 @@ test_expect_success \
      git add fake.sendmail
      GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
 
-test_expect_success \
-    'Extract patches and send' \
-    'git format-patch -n HEAD^1
-     git send-email -from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" ./0001*txt'
+test_expect_success 'Extract patches' '
+    patches=`git format-patch -n HEAD^1`
+'
+
+test_expect_success 'Send patches' '
+     git send-email -from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
+'
 
 cat >expected <<\EOF
 !nobody@example.com!
-- 
1.4.1.gc92a

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] send-email: do not barf when Term::ReadLine does not like your terminal
  2006-07-02 23:03 [PATCH] send-email: do not barf when Term::ReadLine does not like your terminal Junio C Hamano
@ 2006-07-04  1:44 ` Ryan Anderson
  0 siblings, 0 replies; 2+ messages in thread
From: Ryan Anderson @ 2006-07-04  1:44 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 3080 bytes --]

Junio C Hamano wrote:
> As long as we do not need to readline from the terminal, we
> should not barf when starting up the program.  Without this
> patch, t9001 test on Cygwin occasionally died with the following
> error message:
>
> 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.
> Compilation failed in require at /usr/lib/perl5/vendor_perl/5.8/Term/ReadLine/Perl.pm line 58.
>
> Signed-off-by: Junio C Hamano <junkio@cox.net>
> ---
>
>  * I do not use send-email myself that often so extra sets of
>    eyeballs are appreciated.
>   
Looks fine to me.

Acked-by: Ryan Anderson <ryan@michonline.com>

(I personally would have put the package declaration at the end of the
file, but it's not significant enough for me to send a patch, heh.)


>  git-send-email.perl   |   18 +++++++++++++++++-
>  t/t9001-send-email.sh |   11 +++++++----
>  2 files changed, 24 insertions(+), 5 deletions(-)
>
> diff --git a/git-send-email.perl b/git-send-email.perl
> index c5d9e73..b04b8f4 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -22,6 +22,17 @@ use Term::ReadLine;
>  use Getopt::Long;
>  use Data::Dumper;
>  
> +package FakeTerm;
> +sub new {
> +	my ($class, $reason) = @_;
> +	return bless \$reason, shift;
> +}
> +sub readline {
> +	my $self = shift;
> +	die "Cannot use readline on FakeTerm: $$self";
> +}
> +package main;
> +
>  # most mail servers generate the Date: header, but not all...
>  $ENV{LC_ALL} = 'C';
>  use POSIX qw/strftime/;
> @@ -46,7 +57,12 @@ my $smtp_server;
>  # Example reply to:
>  #$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';
>  
> -my $term = new Term::ReadLine 'git-send-email';
> +my $term = eval {
> +	new Term::ReadLine 'git-send-email';
> +};
> +if ($@) {
> +	$term = new FakeTerm "$@: going non-interactive";
> +}
>  
>  # Begin by accumulating all the variables (defined above), that we will end up
>  # needing, first, from the command line:
> diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
> index a61da1e..e9ea33c 100755
> --- a/t/t9001-send-email.sh
> +++ b/t/t9001-send-email.sh
> @@ -25,10 +25,13 @@ test_expect_success \
>       git add fake.sendmail
>       GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
>  
> -test_expect_success \
> -    'Extract patches and send' \
> -    'git format-patch -n HEAD^1
> -     git send-email -from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" ./0001*txt'
> +test_expect_success 'Extract patches' '
> +    patches=`git format-patch -n HEAD^1`
> +'
> +
> +test_expect_success 'Send patches' '
> +     git send-email -from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
> +'
>  
>  cat >expected <<\EOF
>  !nobody@example.com!
>   


-- 

Ryan Anderson
  sometimes Pug Majere



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-07-04  1:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-02 23:03 [PATCH] send-email: do not barf when Term::ReadLine does not like your terminal Junio C Hamano
2006-07-04  1:44 ` Ryan Anderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).