# [PATCH 1/1] Use GIT_ASKPASS environment to launch thirdpart UI app to get password

8 messages from 2010-02-23 to 2010-02-26. Participants: Frank Li, Laszlo Papp, David Aguilar, Junio C Hamano.
Thread: https://gitlist.dev/t/22764

## Frank Li, 2010-02-23 11:11

Subject: [PATCH 1/1] Use GIT_ASKPASS environment to launch thirdpart UI app to get password
Message-ID: <1266923463-2828-1-git-send-email-lznuaa@gmail.com>
URL: https://gitlist.dev/e/1266923463-2828-1-git-send-email-lznuaa%40gmail.com

```
Default git-svn read charactor from terminal to get password. GUI will
wait forever because don't know password need input.

Signed-off-by: Frank Li <lznuaa@gmail.com>
---
 git-svn.perl |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 265852f..f9f104e 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -3966,18 +3966,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;
 }
 
-- 
1.7.0.83.g241b9.dirty

```

## Laszlo Papp, 2010-02-23 23:31

Subject: Re: [PATCH 1/1] Use GIT_ASKPASS environment to launch thirdpart UI app to get password
Message-ID: <a362e8011002231531k17725788sb45e70428c33848b@mail.gmail.com>
URL: https://gitlist.dev/e/a362e8011002231531k17725788sb45e70428c33848b%40mail.gmail.com
In-Reply-To: <1266923463-2828-1-git-send-email-lznuaa@gmail.com>

```
Nice to see someone who are interested in the solution to hack it :-)

On 2/23/10, Frank Li <lznuaa@gmail.com> wrote:
> Default git-svn read charactor from terminal to get password. GUI will
> wait forever because don't know password need input.
>
> Signed-off-by: Frank Li <lznuaa@gmail.com>
> ---
>  git-svn.perl |   27 +++++++++++++++++----------
>  1 files changed, 17 insertions(+), 10 deletions(-)
>
> diff --git a/git-svn.perl b/git-svn.perl
> index 265852f..f9f104e 100755
> --- a/git-svn.perl
> +++ b/git-svn.perl
> @@ -3966,18 +3966,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;
>  }
>
> --
> 1.7.0.83.g241b9.dirty
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

```

## David Aguilar, 2010-02-24 05:13

Subject: Re: [PATCH 1/1] Use GIT_ASKPASS environment to launch thirdpart UI app to get password
Message-ID: <20100224051307.GA3232@gmail.com>
URL: https://gitlist.dev/e/20100224051307.GA3232%40gmail.com
In-Reply-To: <1266923463-2828-1-git-send-email-lznuaa@gmail.com>

```
On Tue, Feb 23, 2010 at 07:11:03PM +0800, Frank Li wrote:
> Default git-svn read charactor from terminal to get password. GUI will
> wait forever because don't know password need input.

What do you think about this message instead?

-- >8 --
Subject: [PATCH] git-svn: Support retrieving passwords with GIT_ASKPASS

git-svn reads passwords from an interactive terminal.
This behavior causes 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.

(see note below)


> diff --git a/git-svn.perl b/git-svn.perl
> index 265852f..f9f104e 100755
> --- a/git-svn.perl
> +++ b/git-svn.perl
> @@ -3966,18 +3966,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);

I think Junio mentioned this in passing but I'll repeat it.

Many users already have SSH_ASKPASS defined.  It would be very
nice if we supported SSH_ASKPASS as a fallback when GIT_ASKPASS
is not provided.


-- 
		David

```

## Junio C Hamano, 2010-02-24 05:31

Subject: Re: [PATCH 1/1] Use GIT_ASKPASS environment to launch thirdpart UI app to get password
Message-ID: <7vtyt7gpwz.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vtyt7gpwz.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20100224051307.GA3232@gmail.com>

```
David Aguilar <davvid@gmail.com> writes:

> I think Junio mentioned this in passing but I'll repeat it.
>
> Many users already have SSH_ASKPASS defined.  It would be very
> nice if we supported SSH_ASKPASS as a fallback when GIT_ASKPASS
> is not provided.

Thanks; I think git-gui does something similar.

```

## Frank Li, 2010-02-24 08:13

Subject: Re: [PATCH 1/1] Use GIT_ASKPASS environment to launch thirdpart UI app to get password
Message-ID: <1976ea661002240013j164fc875o469c0dcdf74afe0c@mail.gmail.com>
URL: https://gitlist.dev/e/1976ea661002240013j164fc875o469c0dcdf74afe0c%40mail.gmail.com
In-Reply-To: <20100224051307.GA3232@gmail.com>

```
> -- >8 --
> Subject: [PATCH] git-svn: Support retrieving passwords with GIT_ASKPASS
>
> git-svn reads passwords from an interactive terminal.
> This behavior causes 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.
>

Okay, I will change it.

>
> I think Junio mentioned this in passing but I'll repeat it.
>
> Many users already have SSH_ASKPASS defined.  It would be very
> nice if we supported SSH_ASKPASS as a fallback when GIT_ASKPASS
> is not provided.
>

I consider add such fallback at git.c.  when user use git svn,  git
main program will be called firstly.
git main entry will check if GIT_ASKPASS and SSH_ASKPASS, if
SSH_ASKPASS set but GIT_ASKPASS not set,
GIT_ASKPASS will be set as SSH_ASKPASS.

Do you think we needs add such check at git-svn.perl ?

best regards
Frank Li

```

## David Aguilar, 2010-02-25 09:15

Subject: Re: [PATCH 1/1] Use GIT_ASKPASS environment to launch thirdpart UI app to get password
Message-ID: <20100225091500.GB2903@gmail.com>
URL: https://gitlist.dev/e/20100225091500.GB2903%40gmail.com
In-Reply-To: <1976ea661002240013j164fc875o469c0dcdf74afe0c@mail.gmail.com>

```
On Wed, Feb 24, 2010 at 04:13:01PM +0800, Frank Li wrote:
> 
> > Many users already have SSH_ASKPASS defined.  It would be very
> > nice if we supported SSH_ASKPASS as a fallback when GIT_ASKPASS
> > is not provided.
> >
> 
> I consider add such fallback at git.c.  when user use git svn,  git
> main program will be called firstly.
> git main entry will check if GIT_ASKPASS and SSH_ASKPASS, if
> SSH_ASKPASS set but GIT_ASKPASS not set,
> GIT_ASKPASS will be set as SSH_ASKPASS.
> 
> Do you think we needs add such check at git-svn.perl ?
> 
> best regards
> Frank Li

Interesting question.  I had never thought of moving the
fallback to git.

I would have done it in the script as a localized fix but
I definately see the value in aiding scripts from
all having to implement this same fallback, though:

	$ENV{GIT_ASKPASS} ||= $ENV{SSH_ASKPASS};

If Junio, Eric, and the git list think that this should
live in git instead then by all means.

-- 
		David

```

## Laszlo Papp, 2010-02-25 17:15

Subject: Re: [PATCH 1/1] Use GIT_ASKPASS environment to launch thirdpart UI app to get password
Message-ID: <a362e8011002250915l7e42beel316878b60899c440@mail.gmail.com>
URL: https://gitlist.dev/e/a362e8011002250915l7e42beel316878b60899c440%40mail.gmail.com
In-Reply-To: <20100225091500.GB2903@gmail.com>

```
On Thu, Feb 25, 2010 at 10:15 AM, David Aguilar <davvid@gmail.com> wrote:
> On Wed, Feb 24, 2010 at 04:13:01PM +0800, Frank Li wrote:
>>
>> > Many users already have SSH_ASKPASS defined.  It would be very
>> > nice if we supported SSH_ASKPASS as a fallback when GIT_ASKPASS
>> > is not provided.
>> >
>>
>> I consider add such fallback at git.c.  when user use git svn,  git
>> main program will be called firstly.
>> git main entry will check if GIT_ASKPASS and SSH_ASKPASS, if
>> SSH_ASKPASS set but GIT_ASKPASS not set,
>> GIT_ASKPASS will be set as SSH_ASKPASS.
>>
>> Do you think we needs add such check at git-svn.perl ?
>>
>> best regards
>> Frank Li
>
> Interesting question.  I had never thought of moving the
> fallback to git.
>
> I would have done it in the script as a localized fix but
> I definately see the value in aiding scripts from
> all having to implement this same fallback, though:
>
>        $ENV{GIT_ASKPASS} ||= $ENV{SSH_ASKPASS};
>
> If Junio, Eric, and the git list think that this should
> live in git instead then by all means.
>
> --
>                David
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

I don't think localized fix in every scripts, third party application
is the good and the trivial solution for this issue. I'm just a simple
TortoiseGIT user, but I guess other GUIs, frontends suffer from this
problem too.

Best Regards,
Laszlo Papp

```

## Frank Li, 2010-02-26 00:15

Subject: Re: [PATCH 1/1] Use GIT_ASKPASS environment to launch thirdpart UI app to get password
Message-ID: <1976ea661002251615o2373c527y613c2e9c7b90d98e@mail.gmail.com>
URL: https://gitlist.dev/e/1976ea661002251615o2373c527y613c2e9c7b90d98e%40mail.gmail.com
In-Reply-To: <20100225091500.GB2903@gmail.com>

```
>
> I would have done it in the script as a localized fix but
> I definately see the value in aiding scripts from
> all having to implement this same fallback, though:
>
>        $ENV{GIT_ASKPASS} ||= $ENV{SSH_ASKPASS};
>

Add it at [PATCH v2 1/3] git-svn: Support retrieving passwords with GIT_ASKPASS

```
