git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix bug when more than one readline instance is used
@ 2023-08-10  0:39 Wesley Schwengle
  2023-08-10  0:49 ` Jeff King
  2023-08-10  1:05 ` [PATCH] Fix bug when more than one readline instance is used Junio C Hamano
  0 siblings, 2 replies; 14+ messages in thread
From: Wesley Schwengle @ 2023-08-10  0:39 UTC (permalink / raw)
  To: git

The following error was emitted if one issued the command

    git send-email --compose 0001-my.patch

Can't locate object method "IN" via package "FakeTerm" at
/home/wesleys/libexec/git-core/git-send-email line 997.

After added a warn in the relevant function that created the term it was
obvious what happened:

Only one Term::ReadLine::Gnu instance is allowed. at
/home/wesleys/libexec/git-core/git-send-email line 981.

When you supply no --to send-email asks you to whom you want to send the
email to. This starts a term, the first Term::ReadLine::Gnu instance.
The second time it wants to ask the user 'Send this email?
([y]es|[n]o|[e]dit|[q]uit|[a]ll):' and this causes FakeTerm to be
loaded, but it doesn't have IN/OUT methods and thus fails.

The fix is to make $term global. If git chooses to drop perl 5.8 support
and allows Perl 5.10, we could also use the state feature. Which would
solve the problem without making $term global.

More or less the same logic happens in git-svn.perl so I fixed it there
as well.

Signed-off-by: Wesley Schwengle <wesleys@opperschaap.net>
---
 git-send-email.perl | 4 +++-
 git-svn.perl        | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index affbb88509..7fdcf9084a 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -971,8 +971,10 @@ sub get_patch_subject {
 	do_edit(@files);
 }
 
+my $term;
 sub term {
-	my $term = eval {
+	return $term if $term;
+	$term = eval {
 		require Term::ReadLine;
 		$ENV{"GIT_SEND_EMAIL_NOTTY"}
 			? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT)
diff --git a/git-svn.perl b/git-svn.perl
index be987e316f..2813551e06 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -306,10 +306,12 @@ sub readline {
 	my $self = shift;
 	die "Cannot use readline on FakeTerm: $$self";
 }
+
 package main;
 
 my $term;
 sub term_init {
+	return $term if $term;
 	$term = eval {
 		require Term::ReadLine;
 		$ENV{"GIT_SVN_NOTTY"}
-- 
2.42.0.rc0.26.ga73c38ecaa


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

end of thread, other threads:[~2023-08-31  0:28 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-10  0:39 [PATCH] Fix bug when more than one readline instance is used Wesley Schwengle
2023-08-10  0:49 ` Jeff King
2023-08-10  1:18   ` [[PATCH v2]] " Wesley Schwengle
2023-08-10 14:31     ` Junio C Hamano
2023-08-10 15:14       ` Wesley
2023-08-11  1:01     ` Junio C Hamano
2023-08-11  1:09       ` Wesley
2023-08-11  5:30         ` Junio C Hamano
2023-08-11 14:51           ` Jeff King
2023-08-11 16:05             ` Junio C Hamano
2023-08-30 22:32               ` [PATCH] git-svn: drop FakeTerm hack Junio C Hamano
2023-08-31  0:13                 ` Jeff King
2023-08-31  0:28                   ` Junio C Hamano
2023-08-10  1:05 ` [PATCH] Fix bug when more than one readline instance is used Junio C Hamano

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).