git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCHv4 6/6] git-send-email: use git credential to obtain password

From
Michal Nazarewicz <mina86@mina86.com>
Date
Feb 27, 2013, 16:09 UTC
Message-ID
<xa1tobf5viuk.fsf@mina86.com>
In-Reply-To
<7vehg1kb09.fsf@alter.siamese.dyndns.org>
On Wed, Feb 27 2013, Junio C Hamano <gitster@pobox.com> wrote:
Show 19 quoted lines
> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
>
>> Michal Nazarewicz <mpn@google.com> writes:
>>
>>> +	$auth = Git::credential({
>>> +		'protocol' => 'smtp',
>>> +		'host' => join(':', $smtp_server, $smtp_server_port),
>>
>> At this point, $smtp_server_port is not always defined. I just tested
>> and got
>>
>> Use of uninitialized value $smtp_server_port in join or string at
>> git-send-email line 1077.
>>
>> Other than that, the whole series looks good.
>
> Given that there is another place that conditionally append ":$port"
> to the host string, I think we should follow suit here.  Perhaps
> like the attached diff?
Damn meetings, you beat me to it…  I was just about to send a patch. ;)
Show 45 quoted lines
> Thanks for a review.
>
>
>  git-send-email.perl | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/git-send-email.perl b/git-send-email.perl
> index 76bbfc3..c3501d9 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -1045,6 +1045,14 @@ sub maildomain {
>  	return maildomain_net() || maildomain_mta() || 'localhost.localdomain';
>  }
>  
> +sub smtp_host_string {
> +	if (defined $smtp_server_port) {
> +		return "$smtp_server:$smtp_server_port";
> +	} else {
> +		return $smtp_server;
> +	}
> +}
> +
>  # Returns 1 if authentication succeeded or was not necessary
>  # (smtp_user was not specified), and 0 otherwise.
>  
> @@ -1065,7 +1073,7 @@ sub smtp_auth_maybe {
>  	# reject credentials.
>  	$auth = Git::credential({
>  		'protocol' => 'smtp',
> -		'host' => join(':', $smtp_server, $smtp_server_port),
> +		'host' => smtp_host_string(),
>  		'username' => $smtp_authuser,
>  		# if there's no password, "git credential fill" will
>  		# give us one, otherwise it'll just pass this one.
> @@ -1188,9 +1196,7 @@ sub send_message {
>  		else {
>  			require Net::SMTP;
>  			$smtp_domain ||= maildomain();
> -			$smtp ||= Net::SMTP->new((defined $smtp_server_port)
> -						 ? "$smtp_server:$smtp_server_port"
> -						 : $smtp_server,
> +			$smtp ||= Net::SMTP->new(smtp_host_string(),
>  						 Hello => $smtp_domain,
>  						 Debug => $debug_net_smtp);
>  			if ($smtp_encryption eq 'tls' && $smtp) {
>From reading of SMTP.pm, it seems that this could be changed to:

- $smtp ||= Net::SMTP->new((defined $smtp_server_port) - ? "$smtp_server:$smtp_server_port" - : $smtp_server, + $smtp ||= Net::SMTP->new($smtp_server, + Port => $smtp_server_port,

and than the other part would become:
@@ -1060,12 +1060,17 @@ sub smtp_auth_maybe {
                Authen::SASL->import(qw(Perl));
        };
 
+       my $host = $smtp_server;
+       if (defined $smtp_server_port) {
+               $host .= ':' . $smtp_server_port;
+       }
+
        # TODO: Authentication may fail not because credentials were
        # invalid but due to other reasons, in which we should not
        # reject credentials.
        $auth = Git::credential({
                'protocol' => 'smtp',
-               'host' => join(':', $smtp_server, $smtp_server_port),
+               'host' => $host,
                'username' => $smtp_authuser,
                # if there's no password, "git credential fill" will
                # give us one, otherwise it'll just pass this one.

Either way, looks good to me.
-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo--
Previous: Junio C HamanoNext: Matthieu Moy
Message 20 of 22 in “[PATCHv4 0/6] git-credential support in git-send-email”
  1. Michal NazarewiczFeb 12, 2013
  2. 1/6 Git.pm: allow command_close_bidi_pipe to be called as methodMichal Nazarewicz, Feb 12, 2013
  3. 2/6 Git.pm: fix example in command_close_bidi_pipe documentationMichal Nazarewicz, Feb 12, 2013
  4. 3/6 Git.pm: refactor command_close_bidi_pipe to use _cmd_closeMichal Nazarewicz, Feb 12, 2013
  5. Junio C HamanoFeb 12, 2013
  6. Jeff KingFeb 12, 2013
  7. Michal NazarewiczFeb 12, 2013
  8. Junio C HamanoFeb 12, 2013
  9. 4/6 Git.pm: allow pipes to be closed prior to calling command_close_bidi_pipeMichal Nazarewicz, Feb 12, 2013
  10. Jeff KingFeb 12, 2013
  11. Michal NazarewiczFeb 12, 2013
  12. Junio C HamanoFeb 12, 2013
  13. Jeff KingFeb 12, 2013
  14. Michal NazarewiczFeb 12, 2013
  15. 5/6 Git.pm: add interface for git credential commandMichal Nazarewicz, Feb 12, 2013
  16. Matthieu MoyFeb 27, 2013
  17. 6/6 git-send-email: use git credential to obtain passwordMichal Nazarewicz, Feb 12, 2013
  18. Matthieu MoyFeb 27, 2013
  19. Junio C HamanoFeb 27, 2013
  20. Michal NazarewiczFeb 27, 2013
  21. Matthieu MoyFeb 27, 2013
  22. Junio C HamanoFeb 27, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.