Skip to content

Commit

Permalink
git-svn: Support retrieving passwords with GIT_ASKPASS
Browse files Browse the repository at this point in the history
git-svn reads passwords from an interactive terminal.
This behavior cause GUIs to hang waiting for git-svn to
complete

Fix this problem by allowing a password-retrieving command
to be specified in GIT_ASKPASS. SSH_ASKPASS is supported
as a fallback when GIT_ASKPASS is not provided.

Signed-off-by: Frank Li <lznuaa@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Frank Li authored and Junio C Hamano committed Mar 2, 2010
1 parent 82cd835 commit 56a853b
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions git-svn.perl
Original file line number Diff line number Diff line change
Expand Up @@ -3970,18 +3970,25 @@ sub username {

sub _read_password {
my ($prompt, $realm) = @_;
print STDERR $prompt;
STDERR->flush;
require Term::ReadKey;
Term::ReadKey::ReadMode('noecho');
my $password = '';
while (defined(my $key = Term::ReadKey::ReadKey(0))) {
last if $key =~ /[\012\015]/; # \n\r
$password .= $key;
if (exists $ENV{GIT_ASKPASS}) {
open(PH, "-|", $ENV{GIT_ASKPASS}, $prompt);
$password = <PH>;
$password =~ s/[\012\015]//; # \n\r
close(PH);
} else {
print STDERR $prompt;
STDERR->flush;
require Term::ReadKey;
Term::ReadKey::ReadMode('noecho');
while (defined(my $key = Term::ReadKey::ReadKey(0))) {
last if $key =~ /[\012\015]/; # \n\r
$password .= $key;
}
Term::ReadKey::ReadMode('restore');
print STDERR "\n";
STDERR->flush;
}
Term::ReadKey::ReadMode('restore');
print STDERR "\n";
STDERR->flush;
$password;
}

Expand Down

0 comments on commit 56a853b

Please sign in to comment.