All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] send-email: refactor and ensure prompting doesn't loop forever
@ 2009-03-29  1:39 Jay Soffian
  2009-03-29  1:39 ` [PATCH 2/2] send-email: add tests for refactored prompting Jay Soffian
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Jay Soffian @ 2009-03-29  1:39 UTC (permalink / raw)
  To: git; +Cc: Jay Soffian, Matthieu Moy, Junio C Hamano

Several places in send-email prompt for input, and will do so forever
when the input is EOF. This is poor behavior when send-email is run
unattended (say from cron).

This patch refactors the prompting to an ask() function which takes a
prompt, an optional default, and an optional regex to validate the
input. The function returns on EOF, or if a default is provided and the
user simply types return, or if the input passes the validating regex
(which accepts all input by default). The ask() function gives up after
10 tries in case of invalid input.

There are three callers of the function:

1) "Who should the emails appear to be from?" which provides a default
sender. Previously the user would have to type ctrl-d to accept the
default. Now the user can just hit return, or type ctrl-d.

2) "Who should the emails be sent to?". Previously this prompt passed a
second argument ("") to $term->readline() which was ignored. I believe
the intent was to allow the user to just hit return. Now the user
can do so, or type ctrl-d.

3) "Send this email?". Previously this prompt would loop forever until
it got a valid reply. Now it stops prompting on EOF or a valid reply. In
the case where confirm = "inform", it now defaults to "y" on EOF or the
user hitting return, otherwise an invalid reply causes send-email to
terminate.

A followup patch adds tests for the new functionality.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
 git-send-email.perl |   66 ++++++++++++++++++++++++++------------------------
 1 files changed, 34 insertions(+), 32 deletions(-)

This and the next patch address the bug reported by Matthieu in
http://article.gmane.org/gmane.comp.version-control.git/114577

Of course, I've been wanting to refactor the prompting for a while, so I used
the bug fix as an excuse to do so.

j.

diff --git a/git-send-email.perl b/git-send-email.perl
index 546d2eb..f0405c8 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -606,32 +606,40 @@ EOT
 	do_edit(@files);
 }
 
+sub ask {
+	my ($prompt, %arg) = @_;
+	my $valid_re =$arg{valid_re} || ""; # "" matches anything
+	my $default = $arg{default};
+	my $resp;
+	my $i = 0;
+	while ($i++ < 10) {
+		$resp = $term->readline($prompt);
+		if (!defined $resp) { # EOF
+			print "\n";
+			return defined $default ? $default : undef;
+		}
+		if ($resp eq '' and defined $default) {
+			return $default;
+		}
+		if ($resp =~ /$valid_re/) {
+			return $resp;
+		}
+	}
+	return undef;
+}
+
 my $prompting = 0;
 if (!defined $sender) {
 	$sender = $repoauthor || $repocommitter || '';
-
-	while (1) {
-		$_ = $term->readline("Who should the emails appear to be from? [$sender] ");
-		last if defined $_;
-		print "\n";
-	}
-
-	$sender = $_ if ($_);
+	$sender = ask("Who should the emails appear to be from? [$sender] ",
+	              default => $sender);
 	print "Emails will be sent from: ", $sender, "\n";
 	$prompting++;
 }
 
 if (!@to) {
-
-
-	while (1) {
-		$_ = $term->readline("Who should the emails be sent to? ", "");
-		last if defined $_;
-		print "\n";
-	}
-
-	my $to = $_;
-	push @to, parse_address_line($to);
+	my $to = ask("Who should the emails be sent to? ");
+	push @to, parse_address_line($to) if defined $to; # sanitized/validated later
 	$prompting++;
 }
 
@@ -651,13 +659,8 @@ sub expand_aliases {
 @bcclist = expand_aliases(@bcclist);
 
 if ($thread && !defined $initial_reply_to && $prompting) {
-	while (1) {
-		$_= $term->readline("Message-ID to be used as In-Reply-To for the first email? ", $initial_reply_to);
-		last if defined $_;
-		print "\n";
-	}
-
-	$initial_reply_to = $_;
+	$initial_reply_to = ask(
+		"Message-ID to be used as In-Reply-To for the first email? ");
 }
 if (defined $initial_reply_to) {
 	$initial_reply_to =~ s/^\s*<?//;
@@ -839,8 +842,10 @@ X-Mailer: git-send-email $gitversion
 
 	if ($needs_confirm && !$dry_run) {
 		print "\n$header\n";
+		my $ask_default;
 		if ($needs_confirm eq "inform") {
 			$confirm_unconfigured = 0; # squelch this message for the rest of this run
+			$ask_default = "y"; # assume yes on EOF since user hasn't explicitly asked for confirmation
 			print "    The Cc list above has been expanded by additional\n";
 			print "    addresses found in the patch commit message. By default\n";
 			print "    send-email prompts before sending whenever this occurs.\n";
@@ -851,13 +856,10 @@ X-Mailer: git-send-email $gitversion
 			print "    To retain the current behavior, but squelch this message,\n";
 			print "    run 'git config --global sendemail.confirm auto'.\n\n";
 		}
-		while (1) {
-			chomp ($_ = $term->readline(
-				"Send this email? ([y]es|[n]o|[q]uit|[a]ll): "
-			));
-			last if /^(?:yes|y|no|n|quit|q|all|a)/i;
-			print "\n";
-		}
+		$_ = ask("Send this email? ([y]es|[n]o|[q]uit|[a]ll): ",
+		         valid_re => qr/^(?:yes|y|no|n|quit|q|all|a)/i,
+		         default => $ask_default);
+		die "Send this email reply required" unless defined $_;
 		if (/^n/i) {
 			return;
 		} elsif (/^q/i) {
-- 
1.6.2.313.g33352

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

* [PATCH 2/2] send-email: add tests for refactored prompting
  2009-03-29  1:39 [PATCH 1/2] send-email: refactor and ensure prompting doesn't loop forever Jay Soffian
@ 2009-03-29  1:39 ` Jay Soffian
  2009-03-31 10:33   ` Björn Steinbrink
  2009-03-29  1:48 ` [PATCH 1/2] send-email: refactor and ensure prompting doesn't loop forever Jay Soffian
  2009-03-30 11:29 ` Matthieu Moy
  2 siblings, 1 reply; 17+ messages in thread
From: Jay Soffian @ 2009-03-29  1:39 UTC (permalink / raw)
  To: git; +Cc: Jay Soffian, Matthieu Moy, Junio C Hamano


Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
 t/t9001-send-email.sh |   52 +++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index e426c96..b4de98c 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -421,8 +421,8 @@ test_confirm () {
 		--from="Example <nobody@example.com>" \
 		--to=nobody@example.com \
 		--smtp-server="$(pwd)/fake.sendmail" \
-		$@ \
-		$patches | grep "Send this email"
+		$@ $patches > stdout &&
+	grep "Send this email" stdout
 }
 
 test_expect_success '--confirm=always' '
@@ -444,8 +444,10 @@ test_expect_success '--confirm=compose' '
 test_expect_success 'confirm by default (due to cc)' '
 	CONFIRM=$(git config --get sendemail.confirm) &&
 	git config --unset sendemail.confirm &&
-	test_confirm &&
-	git config sendemail.confirm $CONFIRM
+	test_confirm
+	ret="$?"
+	git config sendemail.confirm ${CONFIRM:-never}
+	test $ret = "0"
 '
 
 test_expect_success 'confirm by default (due to --compose)' '
@@ -457,6 +459,48 @@ test_expect_success 'confirm by default (due to --compose)' '
 	test $ret = "0"
 '
 
+test_expect_success 'confirm detects EOF (inform assumes y)' '
+	CONFIRM=$(git config --get sendemail.confirm) &&
+	git config --unset sendemail.confirm &&
+	GIT_SEND_EMAIL_NOTTY=1 \
+		git send-email \
+			--from="Example <nobody@example.com>" \
+			--to=nobody@example.com \
+			--smtp-server="$(pwd)/fake.sendmail" \
+			$patches < /dev/null
+	ret="$?"
+	git config sendemail.confirm ${CONFIRM:-never}
+	test $ret = "0"
+'
+
+test_expect_success 'confirm detects EOF (auto causes failure)' '
+	CONFIRM=$(git config --get sendemail.confirm) &&
+	git config sendemail.confirm auto &&
+	GIT_SEND_EMAIL_NOTTY=1 \
+		test_must_fail git send-email \
+			--from="Example <nobody@example.com>" \
+			--to=nobody@example.com \
+			--smtp-server="$(pwd)/fake.sendmail" \
+			$patches < /dev/null
+	ret="$?"
+	git config sendemail.confirm ${CONFIRM:-never}
+	test $ret = "0"
+'
+
+test_expect_success 'confirm doesnt loop forever' '
+	CONFIRM=$(git config --get sendemail.confirm) &&
+	git config sendemail.confirm auto &&
+	yes "bogus" | GIT_SEND_EMAIL_NOTTY=1 \
+		test_must_fail git send-email \
+			--from="Example <nobody@example.com>" \
+			--to=nobody@example.com \
+			--smtp-server="$(pwd)/fake.sendmail" \
+			$patches
+	ret="$?"
+	git config sendemail.confirm ${CONFIRM:-never}
+	test $ret = "0"
+'
+
 test_expect_success '--compose adds MIME for utf8 body' '
 	clean_fake_sendmail &&
 	(echo "#!$SHELL_PATH" &&
-- 
1.6.2.313.g33352

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

* Re: [PATCH 1/2] send-email: refactor and ensure prompting doesn't  loop forever
  2009-03-29  1:39 [PATCH 1/2] send-email: refactor and ensure prompting doesn't loop forever Jay Soffian
  2009-03-29  1:39 ` [PATCH 2/2] send-email: add tests for refactored prompting Jay Soffian
@ 2009-03-29  1:48 ` Jay Soffian
  2009-03-30  6:50   ` Junio C Hamano
  2009-03-30 11:29 ` Matthieu Moy
  2 siblings, 1 reply; 17+ messages in thread
From: Jay Soffian @ 2009-03-29  1:48 UTC (permalink / raw)
  To: git; +Cc: Jay Soffian, Matthieu Moy, Junio C Hamano

On Sat, Mar 28, 2009 at 9:39 PM, Jay Soffian <jaysoffian@gmail.com> wrote:
> There are three callers of the function:

Where by "three" I mean "four". Please use this commit message instead:

---snip---
Several places in send-email prompt for input, and will do so forever
when the input is EOF. This is poor behavior when send-email is run
unattended (say from cron).

This patch refactors the prompting to an ask() function which takes a
prompt, an optional default, and an optional regex to validate the
input. The function returns on EOF, or if a default is provided and the
user simply types return, or if the input passes the validating regex
(which accepts all input by default). The ask() function gives up after
10 tries in case of invalid input.

There are four callers of the function:

1) "Who should the emails appear to be from?" which provides a default
sender. Previously the user would have to type ctrl-d to accept the
default. Now the user can just hit return, or type ctrl-d.

2) "Who should the emails be sent to?". Previously this prompt passed a
second argument ("") to $term->readline() which was ignored. I believe
the intent was to allow the user to just hit return. Now the user
can do so, or type ctrl-d.

3) "Message-ID to be used as In-Reply-To for the first email?".
Previously this prompt passed a second argument (effectively undef) to
$term->readline() which was ignored. I believe the intent was the same
as for (2), to allow the user to just hit return. Now the user can do
so, or type ctrl-d.

4) "Send this email?". Previously this prompt would loop forever until
it got a valid reply. Now it stops prompting on EOF or a valid reply. In
the case where confirm = "inform", it now defaults to "y" on EOF or the
user hitting return, otherwise an invalid reply causes send-email to
terminate.

A followup patch adds tests for the new functionality.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---snip---

Thanks,

j.

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

* Re: [PATCH 1/2] send-email: refactor and ensure prompting doesn't  loop forever
  2009-03-29  1:48 ` [PATCH 1/2] send-email: refactor and ensure prompting doesn't loop forever Jay Soffian
@ 2009-03-30  6:50   ` Junio C Hamano
  0 siblings, 0 replies; 17+ messages in thread
From: Junio C Hamano @ 2009-03-30  6:50 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, Matthieu Moy

Jay Soffian <jaysoffian@gmail.com> writes:

> On Sat, Mar 28, 2009 at 9:39 PM, Jay Soffian <jaysoffian@gmail.com> wrote:
>> There are three callers of the function:
>
> Where by "three" I mean "four". Please use this commit message instead:

Thanks.

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

* Re: [PATCH 1/2] send-email: refactor and ensure prompting doesn't loop forever
  2009-03-29  1:39 [PATCH 1/2] send-email: refactor and ensure prompting doesn't loop forever Jay Soffian
  2009-03-29  1:39 ` [PATCH 2/2] send-email: add tests for refactored prompting Jay Soffian
  2009-03-29  1:48 ` [PATCH 1/2] send-email: refactor and ensure prompting doesn't loop forever Jay Soffian
@ 2009-03-30 11:29 ` Matthieu Moy
  2009-03-30 14:17   ` Jay Soffian
  2 siblings, 1 reply; 17+ messages in thread
From: Matthieu Moy @ 2009-03-30 11:29 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, Junio C Hamano

Jay Soffian <jaysoffian@gmail.com> writes:

> Several places in send-email prompt for input, and will do so forever
> when the input is EOF. This is poor behavior when send-email is run
> unattended (say from cron).

Thanks a lot for the patch, it does fix the problem I reported in
http://article.gmane.org/gmane.comp.version-control.git/114577 .

Minor problem: I still (harmless) get error messages in my log:

  print() on closed filehandle FOUT at /usr/share/perl/5.8/Term/ReadLine.pm line 193.
  readline() on closed filehandle FIN at /usr/share/perl/5.8/Term/ReadLine.pm line 395.
  print() on closed filehandle FOUT at /usr/share/perl/5.8/Term/ReadLine.pm line 203.
  
But I can very well live with them!

-- 
Matthieu

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

* Re: [PATCH 1/2] send-email: refactor and ensure prompting doesn't  loop forever
  2009-03-30 11:29 ` Matthieu Moy
@ 2009-03-30 14:17   ` Jay Soffian
  2009-03-30 14:18     ` Jay Soffian
  2009-03-30 14:40     ` Matthieu Moy
  0 siblings, 2 replies; 17+ messages in thread
From: Jay Soffian @ 2009-03-30 14:17 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git, Junio C Hamano

On Mon, Mar 30, 2009 at 7:29 AM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
> Minor problem: I still (harmless) get error messages in my log:
>
>  print() on closed filehandle FOUT at /usr/share/perl/5.8/Term/ReadLine.pm line 193.
>  readline() on closed filehandle FIN at /usr/share/perl/5.8/Term/ReadLine.pm line 395.
>  print() on closed filehandle FOUT at /usr/share/perl/5.8/Term/ReadLine.pm line 203.
>
> But I can very well live with them!

perl send-email ... 2>/dev/null :-)

Seriously though, I am unable to reproduce the messages you are
getting from Term::ReadLine, and I tried really hard.

What does:

$ perl -e 'use Term::ReadLine; print "$Term::ReadLine::VERSION\n"'

tell you?

Also, thank you for confirming the fix.

j.

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

* Re: [PATCH 1/2] send-email: refactor and ensure prompting doesn't  loop forever
  2009-03-30 14:17   ` Jay Soffian
@ 2009-03-30 14:18     ` Jay Soffian
  2009-03-30 14:40     ` Matthieu Moy
  1 sibling, 0 replies; 17+ messages in thread
From: Jay Soffian @ 2009-03-30 14:18 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git, Junio C Hamano

On Mon, Mar 30, 2009 at 10:17 AM, Jay Soffian <jaysoffian@gmail.com> wrote:
> perl send-email ... 2>/dev/null :-)

Hmfph, perl on the mind. That should of course be "git send-email ...
2>/dev/null" but it was only a half-serious suggestion anyway.

j.

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

* Re: [PATCH 1/2] send-email: refactor and ensure prompting doesn't  loop forever
  2009-03-30 14:17   ` Jay Soffian
  2009-03-30 14:18     ` Jay Soffian
@ 2009-03-30 14:40     ` Matthieu Moy
  2009-03-30 15:45       ` Jay Soffian
  1 sibling, 1 reply; 17+ messages in thread
From: Matthieu Moy @ 2009-03-30 14:40 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, Junio C Hamano

Jay Soffian <jaysoffian@gmail.com> writes:

> On Mon, Mar 30, 2009 at 7:29 AM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
>
> perl send-email ... 2>/dev/null :-)
>
> Seriously though, I am unable to reproduce the messages you are
> getting from Term::ReadLine, and I tried really hard.

Anyway, as I said, the warnings do not harm. They just appear messy in
my log files, but it's really a matter of polishing the UI.

> What does:
>
> $ perl -e 'use Term::ReadLine; print "$Term::ReadLine::VERSION\n"'

$ perl -e 'use Term::ReadLine; print "$Term::ReadLine::VERSION\n"'
1.02
$

That's Debian oldstable (etch), so perhaps newer versions fixed the
problem.

Thanks again,

-- 
Matthieu

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

* Re: [PATCH 1/2] send-email: refactor and ensure prompting doesn't  loop forever
  2009-03-30 14:40     ` Matthieu Moy
@ 2009-03-30 15:45       ` Jay Soffian
  2009-03-30 16:04         ` Jay Soffian
  0 siblings, 1 reply; 17+ messages in thread
From: Jay Soffian @ 2009-03-30 15:45 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git, Junio C Hamano

On Mon, Mar 30, 2009 at 10:40 AM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
> Jay Soffian <jaysoffian@gmail.com> writes:
>> Seriously though, I am unable to reproduce the messages you are
>> getting from Term::ReadLine, and I tried really hard.
>
> Anyway, as I said, the warnings do not harm. They just appear messy in
> my log files, but it's really a matter of polishing the UI.

Okay, well, I figured out how to work the polish. Term::ReadLine is
attempting to use /dev/tty for input/output, which is closed. And
because send-email enables warnings, its attempt to do so emits the
messages you are seeing. Can you confirm that this patch squelches the
warnings?

diff --git a/git-send-email.perl b/git-send-email.perl
index f0405c8..1b17728 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -612,6 +612,8 @@ sub ask {
        my $default = $arg{default};
        my $resp;
        my $i = 0;
+       return undef unless defined fileno($term->IN) and
+                           defined fileno($term->OUT);
        while ($i++ < 10) {
                $resp = $term->readline($prompt);
                if (!defined $resp) { # EOF


Thanks,

j.

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

* Re: [PATCH 1/2] send-email: refactor and ensure prompting doesn't  loop forever
  2009-03-30 15:45       ` Jay Soffian
@ 2009-03-30 16:04         ` Jay Soffian
  2009-03-31  9:32           ` Matthieu Moy
  0 siblings, 1 reply; 17+ messages in thread
From: Jay Soffian @ 2009-03-30 16:04 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git, Junio C Hamano

On Mon, Mar 30, 2009 at 11:45 AM, Jay Soffian <jaysoffian@gmail.com> wrote:
> Okay, well, I figured out how to work the polish. Term::ReadLine is
> attempting to use /dev/tty for input/output, which is closed. And
> because send-email enables warnings, its attempt to do so emits the
> messages you are seeing. Can you confirm that this patch squelches the
> warnings?

Ugh, not that. This:

diff --git a/git-send-email.perl b/git-send-email.perl
index f0405c8..81240ef 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -612,6 +612,9 @@ sub ask {
        my $default = $arg{default};
        my $resp;
        my $i = 0;
+       return defined $default ? $default : undef
+               unless defined $term->IN and defined fileno($term->IN) and
+                      defined $term->OUT and defined fileno($term->OUT);
        while ($i++ < 10) {
                $resp = $term->readline($prompt);
                if (!defined $resp) { # EOF

j.

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

* Re: [PATCH 1/2] send-email: refactor and ensure prompting doesn't  loop forever
  2009-03-30 16:04         ` Jay Soffian
@ 2009-03-31  9:32           ` Matthieu Moy
  2009-03-31 14:12             ` Jay Soffian
  0 siblings, 1 reply; 17+ messages in thread
From: Matthieu Moy @ 2009-03-31  9:32 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, Junio C Hamano

Jay Soffian <jaysoffian@gmail.com> writes:

> On Mon, Mar 30, 2009 at 11:45 AM, Jay Soffian <jaysoffian@gmail.com> wrote:
>> Okay, well, I figured out how to work the polish. Term::ReadLine is
>> attempting to use /dev/tty for input/output, which is closed. And
>> because send-email enables warnings, its attempt to do so emits the
>> messages you are seeing. Can you confirm that this patch squelches the
>> warnings?
>
> Ugh, not that. This:
>
> diff --git a/git-send-email.perl b/git-send-email.perl
> index f0405c8..81240ef 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -612,6 +612,9 @@ sub ask {
>         my $default = $arg{default};
>         my $resp;
>         my $i = 0;
> +       return defined $default ? $default : undef
> +               unless defined $term->IN and defined fileno($term->IN) and
> +                      defined $term->OUT and defined fileno($term->OUT);
>         while ($i++ < 10) {
>                 $resp = $term->readline($prompt);
>                 if (!defined $resp) { # EOF

Surprising. I did the test with 3 commits to send (titled "hello",
"hello-again" and "hello-oncemore"). the log says this
  
Send this email reply required at /home/moy/local/usr/libexec/git-core//git-send-email line 866.
OK. Log says:
Sendmail: /usr/sbin/sendmail -i Matthieu.Moy@imag.fr
From: Matthieu.Moy@imag.fr
To: Matthieu.Moy@imag.fr
Subject: [PATCH 1/3] hello
Date: Tue, 31 Mar 2009 10:47:59 +0200
Message-Id: <1238489281-5518-1-git-send-email-Matthieu.Moy@imag.fr>
X-Mailer: git-send-email 1.6.2.1.413.gf2ad.dirty

Result: OK
(mbox) Adding cc: moy <moy@973704de-e02c-4a59-87bb-087b52aa604b> from line 'From: moy <moy@973704de-e02c-4a59-87bb-087b52aa604b>'

From: Matthieu.Moy@imag.fr
To: Matthieu.Moy@imag.fr
Subject: [PATCH 2/3] hello-again
Date: Tue, 31 Mar 2009 10:48:00 +0200
Message-Id: <1238489281-5518-2-git-send-email-Matthieu.Moy@imag.fr>
X-Mailer: git-send-email 1.6.2.1.413.gf2ad.dirty
In-Reply-To: <1238489281-5518-1-git-send-email-Matthieu.Moy@imag.fr>
References: <1238489281-5518-1-git-send-email-Matthieu.Moy@imag.fr>

(line 866 is this: die "Send this email reply required" unless defined $_;)

And I received only patch 1/3.

Actually, this seems to be a totally separate issue. What happens is
that for the first email, the script executes :

		if ($needs_confirm eq "inform") {
			$confirm_unconfigured = 0; # squelch this message for the rest of this run
			$ask_default = "y"; # assume yes on EOF since user hasn't explicitly asked for confirmation
			... (show message, ...)
		}
		$_ = ask("Send this email? ([y]es|[n]o|[q]uit|[a]ll): ",
		         valid_re => qr/^(?:yes|y|no|n|quit|q|all|a)/i,
		         default => $ask_default);

and the second time, since $confirm_unconfigured = 0 has been set, the
message is not shown again, _and_ $ask_default not set (since
$needs_confirm is set according to $confirm_unconfigured). I think the
solution is to use a variable different from $confirm_unconfigured to
say whether the message has already been displayed, along the lines
of:

diff --git a/git-send-email.perl b/git-send-email.perl
index 5916c86..9e36c35 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -357,6 +357,7 @@ if ($confirm_unconfigured) {
 };
 die "Unknown --confirm setting: '$confirm'\n"
        unless $confirm =~ /^(?:auto|cc|compose|always|never)/;
+my $confirm_msg_shown = undef;
 
 # Debugging, print out the suppressions.
 if (0) {
@@ -844,17 +849,21 @@ X-Mailer: git-send-email $gitversion
                print "\n$header\n";
                my $ask_default;
                if ($needs_confirm eq "inform") {
-                       $confirm_unconfigured = 0; # squelch this message for the rest of this run
                        $ask_default = "y"; # assume yes on EOF since user hasn't explicitly asked for confirmation
-                       print "    The Cc list above has been expanded by additional\n";
-                       print "    addresses found in the patch commit message. By default\n";
-                       print "    send-email prompts before sending whenever this occurs.\n";
-                       print "    This behavior is controlled by the sendemail.confirm\n";
-                       print "    configuration setting.\n";
-                       print "\n";
-                       print "    For additional information, run 'git send-email --help'.\n";
-                       print "    To retain the current behavior, but squelch this message,\n";
-                       print "    run 'git config --global sendemail.confirm auto'.\n\n";
+                       if (!defined $confirm_msg_shown) {
+                               $confirm_msg_shown = 0; # squelch this message for the rest of this run
+                               print "    The Cc list above has been expanded by additional\n";
+                               print "    addresses found in the patch commit message. By default\n";
+                               print "    send-email prompts before sending whenever this occurs.\n";
+                               print "    This behavior is controlled by the sendemail.confirm\n";
+                               print "    configuration setting.\n";
+                               print "\n";
+                               print "    For additional information, run 'git send-email --help'.\n";
+                               print "    To retain the current behavior, but squelch this message,\n";
+                               print "    run 'git config --global sendemail.confirm auto'.\n\n";
+                       }
                }
                $_ = ask("Send this email? ([y]es|[n]o|[q]uit|[a]ll): ",
                         valid_re => qr/^(?:yes|y|no|n|quit|q|all|a)/i,


(worksforme at least)

-- 
Matthieu

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

* Re: [PATCH 2/2] send-email: add tests for refactored prompting
  2009-03-29  1:39 ` [PATCH 2/2] send-email: add tests for refactored prompting Jay Soffian
@ 2009-03-31 10:33   ` Björn Steinbrink
  2009-03-31 13:58     ` Jay Soffian
  2009-03-31 14:07     ` Jay Soffian
  0 siblings, 2 replies; 17+ messages in thread
From: Björn Steinbrink @ 2009-03-31 10:33 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, Matthieu Moy, Junio C Hamano

On 2009.03.28 21:39:11 -0400, Jay Soffian wrote:
> +test_expect_success 'confirm detects EOF (auto causes failure)' '
> +	CONFIRM=$(git config --get sendemail.confirm) &&
> +	git config sendemail.confirm auto &&
> +	GIT_SEND_EMAIL_NOTTY=1 \
> +		test_must_fail git send-email \
> +			--from="Example <nobody@example.com>" \
> +			--to=nobody@example.com \
> +			--smtp-server="$(pwd)/fake.sendmail" \
> +			$patches < /dev/null
> +	ret="$?"
> +	git config sendemail.confirm ${CONFIRM:-never}
> +	test $ret = "0"
> +'
> +
> +test_expect_success 'confirm doesnt loop forever' '
> +	CONFIRM=$(git config --get sendemail.confirm) &&
> +	git config sendemail.confirm auto &&
> +	yes "bogus" | GIT_SEND_EMAIL_NOTTY=1 \
> +		test_must_fail git send-email \
> +			--from="Example <nobody@example.com>" \
> +			--to=nobody@example.com \
> +			--smtp-server="$(pwd)/fake.sendmail" \
> +			$patches
> +	ret="$?"
> +	git config sendemail.confirm ${CONFIRM:-never}
> +	test $ret = "0"

These two cause interactive prompts for me.

Björn

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

* Re: [PATCH 2/2] send-email: add tests for refactored prompting
  2009-03-31 10:33   ` Björn Steinbrink
@ 2009-03-31 13:58     ` Jay Soffian
  2009-03-31 14:07     ` Jay Soffian
  1 sibling, 0 replies; 17+ messages in thread
From: Jay Soffian @ 2009-03-31 13:58 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: git, Matthieu Moy, Junio C Hamano

2009/3/31 Björn Steinbrink <B.Steinbrink@gmx.de>:
>> +     GIT_SEND_EMAIL_NOTTY=1 \
>> +             test_must_fail git send-email \
>> [...]
>> +     yes "bogus" | GIT_SEND_EMAIL_NOTTY=1 \
>> +             test_must_fail git send-email \
>
> These two cause interactive prompts for me.

Hmpfh. I think the only way that's possible is if GIT_SEND_EMAIL_NOTTY
isn't being set by the shell. But I'm not sure why that's unique to
these tests.

Thanks for the report.

j.

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

* Re: [PATCH 2/2] send-email: add tests for refactored prompting
  2009-03-31 10:33   ` Björn Steinbrink
  2009-03-31 13:58     ` Jay Soffian
@ 2009-03-31 14:07     ` Jay Soffian
  2009-03-31 14:19       ` Björn Steinbrink
  1 sibling, 1 reply; 17+ messages in thread
From: Jay Soffian @ 2009-03-31 14:07 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: git, Matthieu Moy, Junio C Hamano

2009/3/31 Björn Steinbrink <B.Steinbrink@gmx.de>:
> These two cause interactive prompts for me.

Ah, it's because of going through test_must_fail. Grrr, a test farm
for git would be nice. :-)

This should fix it up:

diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index b4de98c..cd34525 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -476,7 +476,8 @@ test_expect_success 'confirm detects EOF (inform
assumes y)' '
 test_expect_success 'confirm detects EOF (auto causes failure)' '
        CONFIRM=$(git config --get sendemail.confirm) &&
        git config sendemail.confirm auto &&
-       GIT_SEND_EMAIL_NOTTY=1 \
+       GIT_SEND_EMAIL_NOTTY=1 &&
+       export GIT_SEND_EMAIL_NOTTY &&
                test_must_fail git send-email \
                        --from="Example <nobody@example.com>" \
                        --to=nobody@example.com \
@@ -490,8 +491,9 @@ test_expect_success 'confirm detects EOF (auto
causes failure)' '
 test_expect_success 'confirm doesnt loop forever' '
        CONFIRM=$(git config --get sendemail.confirm) &&
        git config sendemail.confirm auto &&
-       yes "bogus" | GIT_SEND_EMAIL_NOTTY=1 \
-               test_must_fail git send-email \
+       GIT_SEND_EMAIL_NOTTY=1 &&
+       export GIT_SEND_EMAIL_NOTTY &&
+               yes "bogus" | test_must_fail git send-email \
                        --from="Example <nobody@example.com>" \
                        --to=nobody@example.com \
                        --smtp-server="$(pwd)/fake.sendmail" \

What's your OS and test shell btw?

j.

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

* Re: [PATCH 1/2] send-email: refactor and ensure prompting doesn't  loop forever
  2009-03-31  9:32           ` Matthieu Moy
@ 2009-03-31 14:12             ` Jay Soffian
  0 siblings, 0 replies; 17+ messages in thread
From: Jay Soffian @ 2009-03-31 14:12 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git, Junio C Hamano

On Tue, Mar 31, 2009 at 5:32 AM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
> Actually, this seems to be a totally separate issue.

Argh, I need more sleep these days.

j.

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

* Re: [PATCH 2/2] send-email: add tests for refactored prompting
  2009-03-31 14:07     ` Jay Soffian
@ 2009-03-31 14:19       ` Björn Steinbrink
  2009-03-31 14:36         ` Jay Soffian
  0 siblings, 1 reply; 17+ messages in thread
From: Björn Steinbrink @ 2009-03-31 14:19 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, Matthieu Moy, Junio C Hamano

On 2009.03.31 10:07:25 -0400, Jay Soffian wrote:
> 2009/3/31 Björn Steinbrink <B.Steinbrink@gmx.de>:
> > These two cause interactive prompts for me.
> 
> Ah, it's because of going through test_must_fail. Grrr, a test farm
> for git would be nice. :-)
> 
> This should fix it up:
> 
> diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
> index b4de98c..cd34525 100755
> --- a/t/t9001-send-email.sh
> +++ b/t/t9001-send-email.sh
> @@ -476,7 +476,8 @@ test_expect_success 'confirm detects EOF (inform
> assumes y)' '
>  test_expect_success 'confirm detects EOF (auto causes failure)' '
>         CONFIRM=$(git config --get sendemail.confirm) &&
>         git config sendemail.confirm auto &&
> -       GIT_SEND_EMAIL_NOTTY=1 \
> +       GIT_SEND_EMAIL_NOTTY=1 &&
> +       export GIT_SEND_EMAIL_NOTTY &&
>                 test_must_fail git send-email \
>                         --from="Example <nobody@example.com>" \
>                         --to=nobody@example.com \
> @@ -490,8 +491,9 @@ test_expect_success 'confirm detects EOF (auto
> causes failure)' '
>  test_expect_success 'confirm doesnt loop forever' '
>         CONFIRM=$(git config --get sendemail.confirm) &&
>         git config sendemail.confirm auto &&
> -       yes "bogus" | GIT_SEND_EMAIL_NOTTY=1 \
> -               test_must_fail git send-email \
> +       GIT_SEND_EMAIL_NOTTY=1 &&
> +       export GIT_SEND_EMAIL_NOTTY &&
> +               yes "bogus" | test_must_fail git send-email \
>                         --from="Example <nobody@example.com>" \
>                         --to=nobody@example.com \
>                         --smtp-server="$(pwd)/fake.sendmail" \

Yep, after fixing the linewrapping and restoring the tabs, this works.

> What's your OS and test shell btw?

Debian sid, kernel 2.6.29, dash as /bin/sh

Thanks,
Björn

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

* Re: [PATCH 2/2] send-email: add tests for refactored prompting
  2009-03-31 14:19       ` Björn Steinbrink
@ 2009-03-31 14:36         ` Jay Soffian
  0 siblings, 0 replies; 17+ messages in thread
From: Jay Soffian @ 2009-03-31 14:36 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: git, Matthieu Moy, Junio C Hamano

2009/3/31 Björn Steinbrink <B.Steinbrink@gmx.de>:
> Yep, after fixing the linewrapping and restoring the tabs, this works.

Thanks (sorry about the formatting, gmail...).

> Debian sid, kernel 2.6.29, dash as /bin/sh

dash seems to be a good lowest common denominator. I'll try testing
with it from now on.

j.

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

end of thread, other threads:[~2009-03-31 14:38 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-29  1:39 [PATCH 1/2] send-email: refactor and ensure prompting doesn't loop forever Jay Soffian
2009-03-29  1:39 ` [PATCH 2/2] send-email: add tests for refactored prompting Jay Soffian
2009-03-31 10:33   ` Björn Steinbrink
2009-03-31 13:58     ` Jay Soffian
2009-03-31 14:07     ` Jay Soffian
2009-03-31 14:19       ` Björn Steinbrink
2009-03-31 14:36         ` Jay Soffian
2009-03-29  1:48 ` [PATCH 1/2] send-email: refactor and ensure prompting doesn't loop forever Jay Soffian
2009-03-30  6:50   ` Junio C Hamano
2009-03-30 11:29 ` Matthieu Moy
2009-03-30 14:17   ` Jay Soffian
2009-03-30 14:18     ` Jay Soffian
2009-03-30 14:40     ` Matthieu Moy
2009-03-30 15:45       ` Jay Soffian
2009-03-30 16:04         ` Jay Soffian
2009-03-31  9:32           ` Matthieu Moy
2009-03-31 14:12             ` Jay Soffian

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.