@matheusbsbs / matheus-bagliano / commits / 56a853b62c
Fork 0

git-svn: Support retrieving passwords with GIT_ASKPASS

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>

Frank Li committed Mar 2, 2010 at 19:47 UTC 56a853b62c0ae7ebaad0a7a0a704f5ef561eb795
1 file changed +17 -10
git-svn.perl
+17 -10
@@ -3970,18 +3970,25 @@ sub username {
3970
3971 sub _read_password {
3972 my ($prompt, $realm) = @_;
3973 - print STDERR $prompt;
3974 - STDERR->flush;
3975 - require Term::ReadKey;
3976 - Term::ReadKey::ReadMode('noecho');
3973 my $password = '';
3978 - while (defined(my $key = Term::ReadKey::ReadKey(0))) {
3979 - last if $key =~ /[\012\015]/; # \n\r
3980 - $password .= $key;
3974 + if (exists $ENV{GIT_ASKPASS}) {
3975 + open(PH, "-|", $ENV{GIT_ASKPASS}, $prompt);
3976 + $password = <PH>;
3977 + $password =~ s/[\012\015]//; # \n\r
3978 + close(PH);
3979 + } else {
3980 + print STDERR $prompt;
3981 + STDERR->flush;
3982 + require Term::ReadKey;
3983 + Term::ReadKey::ReadMode('noecho');
3984 + while (defined(my $key = Term::ReadKey::ReadKey(0))) {
3985 + last if $key =~ /[\012\015]/; # \n\r
3986 + $password .= $key;
3987 + }
3988 + Term::ReadKey::ReadMode('restore');
3989 + print STDERR "\n";
3990 + STDERR->flush;
3991 }
3982 - Term::ReadKey::ReadMode('restore');
3983 - print STDERR "\n";
3984 - STDERR->flush;
3992 $password;
3993 }
3994