Skip to content

Commit e9263e4

Browse files
Sven Strickrothgitster
authored andcommitted
git-svn, perl/Git.pm: extend and use Git->prompt method for querying users
git-svn reads usernames and other user queries from an interactive terminal. This cause GUIs (w/o STDIN connected) to hang waiting forever for git-svn to complete (http://code.google.com/p/tortoisegit/issues/detail?id=967). This change extends the Git::prompt helper, so that it can also be used for non password queries, and makes use of it instead of using hand-rolled prompt-response code that only works with the interactive terminal. Signed-off-by: Sven Strickroth <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f3cab2 commit e9263e4

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

perl/Git.pm

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -511,18 +511,19 @@ C<git --html-path>). Useful mostly only internally.
511511

512512
sub html_path { command_oneline('--html-path') }
513513

514-
=item prompt ( PROMPT )
514+
=item prompt ( PROMPT , ISPASSWORD )
515515
516516
Query user C<PROMPT> and return answer from user.
517517
518518
Honours GIT_ASKPASS and SSH_ASKPASS environment variables for querying
519519
the user. If no *_ASKPASS variable is set or an error occoured,
520520
the terminal is tried as a fallback.
521+
If C<ISPASSWORD> is set and true, the terminal disables echo.
521522
522523
=cut
523524

524525
sub prompt {
525-
my ($prompt) = @_;
526+
my ($prompt, $isPassword) = @_;
526527
my $ret;
527528
if (exists $ENV{'GIT_ASKPASS'}) {
528529
$ret = _prompt($ENV{'GIT_ASKPASS'}, $prompt);
@@ -533,23 +534,28 @@ sub prompt {
533534
if (!defined $ret) {
534535
print STDERR $prompt;
535536
STDERR->flush;
536-
require Term::ReadKey;
537-
Term::ReadKey::ReadMode('noecho');
538-
$ret = '';
539-
while (defined(my $key = Term::ReadKey::ReadKey(0))) {
540-
last if $key =~ /[\012\015]/; # \n\r
541-
$ret .= $key;
537+
if (defined $isPassword && $isPassword) {
538+
require Term::ReadKey;
539+
Term::ReadKey::ReadMode('noecho');
540+
$ret = '';
541+
while (defined(my $key = Term::ReadKey::ReadKey(0))) {
542+
last if $key =~ /[\012\015]/; # \n\r
543+
$ret .= $key;
544+
}
545+
Term::ReadKey::ReadMode('restore');
546+
print STDERR "\n";
547+
STDERR->flush;
548+
} else {
549+
chomp($ret = <STDIN>);
542550
}
543-
Term::ReadKey::ReadMode('restore');
544-
print STDERR "\n";
545-
STDERR->flush;
546551
}
547552
return $ret;
548553
}
549554

550555
sub _prompt {
551556
my ($askpass, $prompt) = @_;
552557
return unless length $askpass;
558+
$prompt =~ s/\n/ /g;
553559
my $ret;
554560
open my $fh, "-|", $askpass, $prompt or return;
555561
$ret = <$fh>;

perl/Git/SVN/Prompt.pm

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ sub ssl_server_trust {
6262
issuer_dname fingerprint);
6363
my $choice;
6464
prompt:
65-
print STDERR $may_save ?
65+
my $options = $may_save ?
6666
"(R)eject, accept (t)emporarily or accept (p)ermanently? " :
6767
"(R)eject or accept (t)emporarily? ";
6868
STDERR->flush;
69-
$choice = lc(substr(<STDIN> || 'R', 0, 1));
70-
if ($choice =~ /^t$/i) {
69+
$choice = lc(substr(Git::prompt("Certificate problem.\n" . $options) || 'R', 0, 1));
70+
if ($choice eq 't') {
7171
$cred->may_save(undef);
72-
} elsif ($choice =~ /^r$/i) {
72+
} elsif ($choice eq 'r') {
7373
return -1;
74-
} elsif ($may_save && $choice =~ /^p$/i) {
74+
} elsif ($may_save && $choice eq 'p') {
7575
$cred->may_save($may_save);
7676
} else {
7777
goto prompt;
@@ -109,9 +109,7 @@ sub username {
109109
if (defined $_username) {
110110
$username = $_username;
111111
} else {
112-
print STDERR "Username: ";
113-
STDERR->flush;
114-
chomp($username = <STDIN>);
112+
$username = Git::prompt("Username: ");
115113
}
116114
$cred->username($username);
117115
$cred->may_save($may_save);
@@ -120,7 +118,7 @@ sub username {
120118

121119
sub _read_password {
122120
my ($prompt, $realm) = @_;
123-
my $password = Git::prompt($prompt);
121+
my $password = Git::prompt($prompt, 1);
124122
$password;
125123
}
126124

0 commit comments

Comments
 (0)