Re: [PATCH] send-email: validate & reconfirm interactive responses
- From
Stephen Boyd <bebarino@gmail.com>
- Date
- Sep 6, 2012, 18:31 UTC
- Message-ID
- <CALaEz9W_RR70KEzxk7GxjOu1_yv4UudckcsKAP2C_39Nc2yLbw@mail.gmail.com>
- In-Reply-To
- <7vsjav6d85.fsf@alter.siamese.dyndns.org>
(Sorry sending this from web interface)
On Wed, Sep 5, 2012 at 8:29 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 31 quoted lines
> Stephen Boyd <bebarino@gmail.com> writes:
>> This is now bugging me if I just hit enter and don't want to specify
>> anything for
>> these headers (I want the defaults or what's in the files already).
>> Can we allow
>> the empty string to be valid as well so I don't have to go through
>> these prompts?
>
> That indeed was the intention, and if it is not behaving, you found
> a bug.
>
> The relevant code in "sub ask" does this:
>
> ...
> $resp = $term->readline($prompt);
> if (!defined $resp) { # EOF
> print "\n";
> return defined $default ? $default : undef;
> }
> if ($resp eq '' and defined $default) {
> return $default;
> }
> if (!defined $valid_re or $resp =~ /$valid_re/) {
> return $resp;
> }
>
> I am scratching my head wondering why your "just hit enter" does not
> trigger the "if response is empty and we have default, just return it"
> codepath we can see above. It shouldn't even trigger the regexp
> based validation codepath in the first place.
>It works fine for "Who should the emails appear to be from?" but beyond that we have "Who should the emails be sent to?" and "Message-ID to be used as In-Reply-To for the first email?" which I typically just hit enter to. It seems that they have no "default" argument so that second if fails. I suppose we can add a default => "" to these two asks?
----8<-----
diff --git a/git-send-email.perl b/git-send-email.perl index 607137b..13d813e 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -760,6 +760,7 @@ if (!defined $sender) { if (!@initial_to && !defined $to_cmd) { my $to = ask("Who should the emails be sent to? ", + default => "", valid_re => qr/\@.*\./, confirm_only => 1); push @initial_to, parse_address_line($to) if defined $to; # sanitized/validated later $prompting++; @@ -787,6 +788,7 @@ sub expand_one_alias { if ($thread && !defined $initial_reply_to && $prompting) { $initial_reply_to = ask( "Message-ID to be used as In-Reply-To for the first email? ", + default => "", valid_re => qr/\@.*\./, confirm_only => 1); } if (defined $initial_reply_to) {