git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix bug when more than one readline instance is used

From
Wesley Schwengle <wesleys@opperschaap.net>
Date
Aug 10, 2023, 00:39 UTC
Message-ID
<20230810003939.1420306-1-wesleys@opperschaap.net>
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
Next: Jeff King
Message 1 of 14 in “Fix bug when more than one readline instance is used”
  1. Fix bug when more than one readline instance is usedWesley Schwengle, Aug 10, 2023
  2. Jeff KingAug 10, 2023
  3. ] Fix bug when more than one readline instance is usedWesley Schwengle, Aug 10, 2023
  4. Junio C HamanoAug 10, 2023
  5. WesleyAug 10, 2023
  6. Junio C HamanoAug 11, 2023
  7. WesleyAug 11, 2023
  8. Junio C HamanoAug 11, 2023
  9. Jeff KingAug 11, 2023
  10. Junio C HamanoAug 11, 2023
  11. git-svn: drop FakeTerm hackJunio C Hamano, Aug 30, 2023
  12. Jeff KingAug 31, 2023
  13. Junio C HamanoAug 31, 2023
  14. Junio C HamanoAug 10, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.