Skip to content

Commit dfd46ba

Browse files
peffgitster
authored andcommitted
send-email: drop FakeTerm hack
Back in 280242d (send-email: do not barf when Term::ReadLine does not like your terminal, 2006-07-02), we added a fallback for when Term::ReadLine's constructor failed: we'd have a FakeTerm object instead, which would then die if anybody actually tried to call readline() on it. Since we instantiated the $term variable at program startup, we needed this workaround to let the program run in modes when we did not prompt the user. But later, in f4dc943 (send-email: lazily load modules for a big speedup, 2021-05-28), we started loading Term::ReadLine lazily only when ask() is called. So at that point we know we're trying to prompt the user, and we can just die if ReadLine instantiation fails, rather than making this fake object to lazily delay showing the error. This should be OK even if there is no tty (e.g., we're in a cron job), because Term::ReadLine will return a stub object in that case whose "IN" and "OUT" functions return undef. And since 5906f54 (send-email: don't attempt to prompt if tty is closed, 2009-03-31), we check for that case and skip prompting. And we can be sure that FakeTerm was not kicking in for such a situation, because it has actually been broken since that commit! It does not define "IN" or "OUT" methods, so perl would barf with an error. If FakeTerm was in use, we were neither honoring what 5906f54 tried to do, nor producing the readable message that 280242d intended. So we're better off just dropping FakeTerm entirely, and letting the error reported by constructing Term::ReadLine through. Signed-off-by: Jeff King <[email protected]> Acked-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb7d80e commit dfd46ba

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

git-send-email.perl

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,6 @@
2626

2727
Getopt::Long::Configure qw/ pass_through /;
2828

29-
package FakeTerm;
30-
sub new {
31-
my ($class, $reason) = @_;
32-
return bless \$reason, shift;
33-
}
34-
sub readline {
35-
my $self = shift;
36-
die "Cannot use readline on FakeTerm: $$self";
37-
}
38-
package main;
39-
40-
4129
sub usage {
4230
print <<EOT;
4331
git send-email' [<options>] <file|directory>
@@ -972,16 +960,10 @@ sub get_patch_subject {
972960
}
973961
974962
sub term {
975-
my $term = eval {
976-
require Term::ReadLine;
977-
$ENV{"GIT_SEND_EMAIL_NOTTY"}
963+
require Term::ReadLine;
964+
return $ENV{"GIT_SEND_EMAIL_NOTTY"}
978965
? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT)
979966
: Term::ReadLine->new('git-send-email');
980-
};
981-
if ($@) {
982-
$term = FakeTerm->new("$@: going non-interactive");
983-
}
984-
return $term;
985967
}
986968
987969
sub ask {

0 commit comments

Comments
 (0)