git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: "Randal L. Schwartz" <merlyn@stonehenge.com>,
	Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: Re: git-svn - username/password
Date: Mon, 15 Jan 2007 20:20:08 -0800	[thread overview]
Message-ID: <20070116042008.GA19873@localdomain> (raw)
In-Reply-To: <86sleb23vs.fsf@blue.stonehenge.com>

"Randal L. Schwartz" <merlyn@stonehenge.com> wrote:
> >>>>> "Eric" == Eric Wong <normalperson@yhbt.net> writes:
> 
> Eric> git-svn fetch --username <username> should work with recent-ish git-svn
> Eric> (since around Thanksgiving); and eventually prompt you for the password
> Eric> (just like svn does).
> 
> The prompts are broken... they're not being flushed properly.
> Once I knew it was talking to me, and not just stalled, I could
> type in the password at the right time.

That's odd.  I have $| = 1; at the beginning of git-svn.  Maybe
some module somewhere is unsetting $|...

Anyways, I think STDERR is more correct for prompts.

From: Eric Wong <normalperson@yhbt.net>
Date: Mon, 15 Jan 2007 20:15:55 -0800
Subject: [PATCH] git-svn: print and flush authentication prompts to STDERR

People that redirect STDOUT output should always see STDERR
prompts interactively.

STDERR should always be flushed without buffering, so
they should always show up.  If that is unset, we still
explicitly flush by calling STDERR->flush.

The svn command-line client prompts to STDERR, too.

Signed-off-by: Eric Wong <normalperson@yhbt.net>

diff --git a/git-svn.perl b/git-svn.perl
index 9986a0c..b8ede9c 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -1918,7 +1918,8 @@ sub _simple_prompt {
 	$default_username = $_username if defined $_username;
 	if (defined $default_username && length $default_username) {
 		if (defined $realm && length $realm) {
-			print "Authentication realm: $realm\n";
+			print STDERR "Authentication realm: $realm\n";
+			STDERR->flush;
 		}
 		$cred->username($default_username);
 	} else {
@@ -1933,36 +1934,38 @@ sub _simple_prompt {
 sub _ssl_server_trust_prompt {
 	my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_;
 	$may_save = undef if $_no_auth_cache;
-	print "Error validating server certificate for '$realm':\n";
+	print STDERR "Error validating server certificate for '$realm':\n";
 	if ($failures & $SVN::Auth::SSL::UNKNOWNCA) {
-		print " - The certificate is not issued by a trusted ",
+		print STDERR " - The certificate is not issued by a trusted ",
 		      "authority. Use the\n",
 	              "   fingerprint to validate the certificate manually!\n";
 	}
 	if ($failures & $SVN::Auth::SSL::CNMISMATCH) {
-		print " - The certificate hostname does not match.\n";
+		print STDERR " - The certificate hostname does not match.\n";
 	}
 	if ($failures & $SVN::Auth::SSL::NOTYETVALID) {
-		print " - The certificate is not yet valid.\n";
+		print STDERR " - The certificate is not yet valid.\n";
 	}
 	if ($failures & $SVN::Auth::SSL::EXPIRED) {
-		print " - The certificate has expired.\n";
+		print STDERR " - The certificate has expired.\n";
 	}
 	if ($failures & $SVN::Auth::SSL::OTHER) {
-		print " - The certificate has an unknown error.\n";
+		print STDERR " - The certificate has an unknown error.\n";
 	}
-	printf( "Certificate information:\n".
+	printf STDERR
+	        "Certificate information:\n".
 	        " - Hostname: %s\n".
 	        " - Valid: from %s until %s\n".
 	        " - Issuer: %s\n".
 	        " - Fingerprint: %s\n",
 	        map $cert_info->$_, qw(hostname valid_from valid_until
-	                               issuer_dname fingerprint) );
+	                               issuer_dname fingerprint);
 	my $choice;
 prompt:
-	print $may_save ?
+	print STDERR $may_save ?
 	      "(R)eject, accept (t)emporarily or accept (p)ermanently? " :
 	      "(R)eject or accept (t)emporarily? ";
+	STDERR->flush;
 	$choice = lc(substr(<STDIN> || 'R', 0, 1));
 	if ($choice =~ /^t$/i) {
 		$cred->may_save(undef);
@@ -1980,7 +1983,8 @@ prompt:
 sub _ssl_client_cert_prompt {
 	my ($cred, $realm, $may_save, $pool) = @_;
 	$may_save = undef if $_no_auth_cache;
-	print "Client certificate filename: ";
+	print STDERR "Client certificate filename: ";
+	STDERR->flush;
 	chomp(my $filename = <STDIN>);
 	$cred->cert_file($filename);
 	$cred->may_save($may_save);
@@ -1999,13 +2003,14 @@ sub _username_prompt {
 	my ($cred, $realm, $may_save, $pool) = @_;
 	$may_save = undef if $_no_auth_cache;
 	if (defined $realm && length $realm) {
-		print "Authentication realm: $realm\n";
+		print STDERR "Authentication realm: $realm\n";
 	}
 	my $username;
 	if (defined $_username) {
 		$username = $_username;
 	} else {
-		print "Username: ";
+		print STDERR "Username: ";
+		STDERR->flush;
 		chomp($username = <STDIN>);
 	}
 	$cred->username($username);
@@ -2015,7 +2020,8 @@ sub _username_prompt {
 
 sub _read_password {
 	my ($prompt, $realm) = @_;
-	print $prompt;
+	print STDERR $prompt;
+	STDERR->flush;
 	require Term::ReadKey;
 	Term::ReadKey::ReadMode('noecho');
 	my $password = '';
@@ -2024,7 +2030,8 @@ sub _read_password {
 		$password .= $key;
 	}
 	Term::ReadKey::ReadMode('restore');
-	print "\n";
+	print STDERR "\n";
+	STDERR->flush;
 	$password;
 }
 
-- 
Eric Wong

      reply	other threads:[~2007-01-16  4:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-15 23:25 git-svn - username/password Randal L. Schwartz
2007-01-16  0:41 ` Eric Wong
2007-01-16  0:48   ` Randal L. Schwartz
2007-01-16  4:20     ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070116042008.GA19873@localdomain \
    --to=normalperson@yhbt.net \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=merlyn@stonehenge.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).