All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Nazarewicz <mina86@mina86.com>
To: Junio C Hamano <gitster@pobox.com>,
	Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Cc: peff@peff.net, git@vger.kernel.org
Subject: Re: [PATCHv4 6/6] git-send-email: use git credential to obtain password
Date: Wed, 27 Feb 2013 17:09:55 +0100	[thread overview]
Message-ID: <xa1tobf5viuk.fsf@mina86.com> (raw)
In-Reply-To: <7vehg1kb09.fsf@alter.siamese.dyndns.org>

[-- Attachment #1: Type: text/plain, Size: 3715 bytes --]

On Wed, Feb 27 2013, Junio C Hamano <gitster@pobox.com> wrote:
> 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. ;)

> 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--

[-- Attachment #2.1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2.2: Type: application/pgp-signature, Size: 835 bytes --]

  reply	other threads:[~2013-02-27 16:10 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-12 14:02 [PATCHv4 0/6] git-credential support in git-send-email Michal Nazarewicz
2013-02-12 14:02 ` [PATCHv4 1/6] Git.pm: allow command_close_bidi_pipe to be called as method Michal Nazarewicz
2013-02-12 14:02 ` [PATCHv4 2/6] Git.pm: fix example in command_close_bidi_pipe documentation Michal Nazarewicz
2013-02-12 14:02 ` [PATCHv4 3/6] Git.pm: refactor command_close_bidi_pipe to use _cmd_close Michal Nazarewicz
2013-02-12 18:55   ` Junio C Hamano
2013-02-12 20:48     ` Jeff King
2013-02-12 21:12       ` Michal Nazarewicz
2013-02-12 21:17         ` Junio C Hamano
2013-02-12 14:02 ` [PATCHv4 4/6] Git.pm: allow pipes to be closed prior to calling command_close_bidi_pipe Michal Nazarewicz
2013-02-12 20:51   ` Jeff King
2013-02-12 21:13     ` Michal Nazarewicz
2013-02-12 21:14     ` Junio C Hamano
2013-02-12 21:17       ` Jeff King
2013-02-12 22:50       ` Michal Nazarewicz
2013-02-12 14:02 ` [PATCHv4 5/6] Git.pm: add interface for git credential command Michal Nazarewicz
2013-02-27 14:18   ` Matthieu Moy
2013-02-12 14:02 ` [PATCHv4 6/6] git-send-email: use git credential to obtain password Michal Nazarewicz
2013-02-27 14:20   ` Matthieu Moy
2013-02-27 15:54     ` Junio C Hamano
2013-02-27 16:09       ` Michal Nazarewicz [this message]
2013-02-27 16:13       ` Matthieu Moy
2013-02-27 16:29         ` Junio C Hamano

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=xa1tobf5viuk.fsf@mina86.com \
    --to=mina86@mina86.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.