Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2023-08-08 21:15:31 +0300
committerJunio C Hamano <gitster@pobox.com>2023-08-09 02:48:17 +0300
commitc016726c2deb84bcc6a7418efad92ef0562a8af3 (patch)
treea1395b7cc3ea3d74e57ba0f620c964b7ae98c552 /git-send-email.perl
parentdfd46bae92ec25d71e7c8a2887e9508aaf211ee8 (diff)
send-email: avoid creating more than one Term::ReadLine object
Every time git-send-email calls its ask() function to prompt the user, we call term(), which instantiates a new Term::ReadLine object. But in v1.46 of Term::ReadLine::Gnu (which provides the Term::ReadLine interface on some platforms), its constructor refuses to create a second instance[1]. So on systems with that version of the module, most git-send-email instances will fail (as we usually prompt for both "to" and "in-reply-to" unless the user provided them on the command line). We can fix this by keeping a single instance variable and returning it for each call to term(). In perl 5.10 and up, we could do that with a "state" variable. But since we only require 5.008, we'll do it the old-fashioned way, with a lexical "my" in its own scope. Note that the tests in t9001 detect this problem as-is, since the failure mode is for the program to die. But let's also beef up the "Prompting works" test to check that it correctly handles multiple inputs (if we had chosen to keep our FakeTerm hack in the previous commit, then the failure mode would be incorrectly ignoring prompts after the first). [1] For discussion of why multiple instances are forbidden, see: https://github.com/hirooih/perl-trg/issues/16 Signed-off-by: Jeff King <peff@peff.net> Acked-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-xgit-send-email.perl18
1 files changed, 13 insertions, 5 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index 4cb6ee9327..897cea6564 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -959,11 +959,19 @@ EOT3
do_edit(@files);
}
-sub term {
- require Term::ReadLine;
- return $ENV{"GIT_SEND_EMAIL_NOTTY"}
- ? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT)
- : Term::ReadLine->new('git-send-email');
+{
+ # Only instantiate one $term per program run, since some
+ # Term::ReadLine providers refuse to create a second instance.
+ my $term;
+ sub term {
+ require Term::ReadLine;
+ if (!defined $term) {
+ $term = $ENV{"GIT_SEND_EMAIL_NOTTY"}
+ ? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT)
+ : Term::ReadLine->new('git-send-email');
+ }
+ return $term;
+ }
}
sub ask {