Merge branch 'fl/askpass'

* fl/askpass:
  git-core: Support retrieving passwords with GIT_ASKPASS
  git-svn: Support retrieving passwords with GIT_ASKPASS
This commit is contained in:
Junio C Hamano
2010-03-20 11:29:35 -07:00
5 changed files with 58 additions and 13 deletions

View File

@ -3971,18 +3971,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;
}