Re: [PATCH v6 8/8] update-ref: add --batch-updates flag for stdin mode
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Apr 10, 2025, 11:23 UTC
- Message-ID
- <CAOLa=ZQ2eTWbj18+QPp=pTAovPVAQVYwJC6_ZTuMvCU-oQOToA@mail.gmail.com>
- In-Reply-To
- <xmqq7c3uy2ps.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 28 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes: > >> Junio C Hamano <gitster@pobox.com> writes: >> >>> Karthik Nayak <karthik.188@gmail.com> writes: >>> >>>> Content-Type: text/plain; charset=y >>> >>> Please don't ;-). >>> >>> More practically, is there something we can do to avoid this >>> happening in send-email? It may be a not-so-uncommon end user >>> mistake that we would rather help our users avoid. >>> >> >> This seems like this was in response to the following question: >> Which 8bit encoding should I declare [UTF-8]? >> >> Which I should have just clicked 'Enter' on, but typed 'y' as 'yes >> please pick UTF-8'. Which again confirms the encoding, which I >> presumably didn't read. So I guess the problem Exists Between Keyboard >> and Chair. > > OK, we have seen enough people got burned by 'y', and made 852a15d7 > (send-email: ask confirmation if given encoding name is very short, > 2015-02-13) as a response exactly for that problem, but it is not > effective as we wished X-<. >
I see.
Show 13 quoted lines
> If there were a better validation method than "4 bytes or longer" we > currently use for valid values for "charset=$auto_8bit_encoding", we > could lose confirm_only from the call to ask() that asks the > question, but I do not know if that is feasible. > > Another more obvious alternative is to do something ugly like this > patch, I suppose? Just like <ENTER> is taken as "I take the default > value presented", this makes yes<ENTER> mean the same thing. > > There is one question that asks yes/no question with default set to > 'n', which would be broken by the patch below, so it needs a bit > more thought, though. >
Yes, this would be an issue. I think what would be nice is perhaps an option like $yes_default.
Show 17 quoted lines
> git-send-email.perl | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git c/git-send-email.perl w/git-send-email.perl
> index 798d59b84f..8b942e5bcf 100755
> --- c/git-send-email.perl
> +++ w/git-send-email.perl
> @@ -986,7 +986,8 @@ sub ask {
> print "\n";
> return defined $default ? $default : undef;
> }
> - if ($resp eq '' and defined $default) {
> + if (defined $default &&
> + ($resp eq '' || $resp =~ /^y(?:es)$/i)) {
> return $default;
> }
> if (!defined $valid_re or $resp =~ /$valid_re/) {Going on top of your patch, something like:
-->8--
diff --git a/git-send-email.perl b/git-send-email.perl index 798d59b84f..318699d26c 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -974,6 +974,7 @@ sub ask { my $valid_re = $arg{valid_re}; my $default = $arg{default}; my $confirm_only = $arg{confirm_only}; + my $yes_is_default = $arg{yes_is_default}; my $resp; my $i = 0; my $term = term(); @@ -989,6 +990,10 @@ sub ask { if ($resp eq '' and defined $default) { return $default; } + if (defined $default and defined $yes_is_default + and $resp =~ /^y(?:es)$/i) { + return $default; + } if (!defined $valid_re or $resp =~ /$valid_re/) { return $resp; } @@ -1031,7 +1036,7 @@ sub file_declares_8bit_cte { } $auto_8bit_encoding = ask(__("Which 8bit encoding should I declare [UTF-8]? "), valid_re => qr/.{4}/, confirm_only => 1, - default => "UTF-8"); + default => "UTF-8", yes_is_default => true); } if (!$force) {