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

[PATCH] add -p: import Term::ReadKey with 'require'

From
Thomas Rast <trast@student.ethz.ch>
Date
Feb 6, 2009, 19:30 UTC
Message-ID
<1233948601-4828-1-git-send-email-trast@student.ethz.ch>
In-Reply-To
<20090206140126.GA18364@coredump.intra.peff.net>

eval{use...} is no good because the 'use' is evaluated at compile time, so manually 'require' it. We need to forward declare the functions we use, otherwise Perl raises a compilation error.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
Jeff King wrote:
Show 12 quoted lines
> Sorry, I am way behind on git mails, so I didn't catch this sooner. But
> it should be "require Term::ReadKey", as "use" statements are done at
> compile time:
> 
>   $ perl -e 'eval { use Bogosity } or print "not found\n"'
>   Can't locate Bogosity.pm in @INC ...
> 
>   $ perl -e 'eval { require Bogosity } or print "not found\n"'
>   not found
> 
> So add--interactive in 'next' is currently broken on non-readkey
> platforms.
Damn, sorry.

The code below _seems_ to work. I have to say that beyond the 'require', it's all voodoo to me, so I'd appreciate an extra-careful check.

 git-add--interactive.perl |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index be8ca8e..ec47888 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -40,9 +40,12 @@ my ($diff_new_color) =
 my $normal_color = $repo->get_color("", "reset");
 
 my $use_readkey = 0;
+sub ReadMode;
+sub ReadKey;
 if ($repo->config_bool("interactive.singlekey")) {
 	eval {
-		use Term::ReadKey;
+		require Term::ReadKey;
+		Term::ReadKey->import;
 		$use_readkey = 1;
 	};
 }
-- 
1.6.1.2.605.ge4655
Previous: Jeff KingNext: Jeff King
Message 4 of 8 in “add -p: prompt for single characters”
  1. 3/4 add -p: prompt for single charactersThomas Rast, Feb 5, 2009
  2. 4/4 add -p: print errors in separate colorThomas Rast, Feb 5, 2009
  3. Jeff KingFeb 6, 2009
  4. add -p: import Term::ReadKey with 'require'Thomas Rast, Feb 6, 2009
  5. Jeff KingFeb 6, 2009
  6. Thomas RastFeb 6, 2009
  7. Jeff KingFeb 7, 2009
  8. Junio C HamanoFeb 7, 2009

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.