git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim@guixotic.coop>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2 3/3] contrib: better support symbolic port names in git-credential-netrc
Date: Tue, 24 Jun 2025 10:51:31 +0900	[thread overview]
Message-ID: <87o6ud52l8.fsf@terra.mail-host-address-is-not-set> (raw)
In-Reply-To: <xmqqh6065o9f.fsf@gitster.g> (Junio C. Hamano's message of "Mon, 23 Jun 2025 11:03:24 -0700")

Hi!

tl;dr: I've submitted a v3 with most of your suggestions implemented.

Junio C Hamano <gitster@pobox.com> writes:

[...]

>> diff --git a/contrib/credential/netrc/test.pl b/contrib/credential/netrc/test.pl
>> index 67a0ede564..8a7fc2588a 100755
>> --- a/contrib/credential/netrc/test.pl
>> +++ b/contrib/credential/netrc/test.pl
>> @@ -45,7 +45,7 @@ BEGIN
>>  diag "Testing with invalid data\n";
>>  $cred = run_credential(['-f', $netrc, 'get'],
>>  		       "bad data");
>> -ok(scalar keys %$cred == 4, "Got first found keys with bad data");
>> +ok(scalar keys %$cred == 3, "Got first found keys with bad data");
>>  
>>  diag "Testing netrc file for a missing corovamilkbar entry\n";
>>  $cred = run_credential(['-f', $netrc, 'get'],
>> @@ -64,12 +64,12 @@ BEGIN
>>  
>>  diag "Testing netrc file for a username-specific entry\n";
>>  $cred = run_credential(['-f', $netrc, 'get'],
>> -		       { host => 'imap', username => 'bob' });
>> +		       { host => 'imap:993', username => 'bob' });
>
> Is this rewriting an existing test, instead of adding a new test to
> trigger a feature that didn't have a test coverage, while keeping
> the old test?  I am wondering if we want to ensure that both
> ":port"-less case and "host:port" case keep working even after the
> change to -netrc credential helper in this patch.

That specific test *is* using a port, but a symbolic one (imaps), which
used to be captured as the 'protocol' in the Git credential hash/array.
Now it's captured properly as a port, which is represented in Git
credential by joining it with the host name. The test needed adjusting
for that.

[...]

> Hmph.  It _can_ be used to validate a random end-user supplied
> string names a port, either by being a port number in the valid
> range or by being a valid service name.  But another use case in the
> code after this patch applied that is equally if not more important
> is to ensure that a valid port specified by the end-user is turned
> into a port number.  We should not name such a sub as if its primary
> functionality is to serve as a Boolean "is_foo".  Perhaps call it
> port_num or something?

Naming is hard :-). I like your suggestion. Done.

>> +sub is_port {
>> +    my ($port) = @_;
>> +
>> +    # Port can be either a positive integer within the 16-bit range...
>> +    if ($port =~ /^\d+$/ && $port > 0 && $port <= (2**16 - 1)) {
>> +        return $port;
>> +    }
>> +
>> +    # ... or a symbolic port (service name).
>> +    my $num = getservbyname($port, '');
>> +    return defined $num ? $num : undef;
>
> Wouldn't "return $num" work here?  getservbyname() would return
> "undef" when the given $port is not a valid service name anyway, no?
>
> Or even "return scalar getservbyname($port, 'tcp')" without an
> intermediate variable $num?

I've re-read the doc (perldoc -f getservbyname) and you are right, in a
scalar context it would return an undef value when the service name was
not found in the local database. Done!

-- 
Thanks,
Maxim


  reply	other threads:[~2025-06-24  1:52 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-20  4:12 [PATCH] contrib: Honor symbolic port in git-credential-netrc Maxim Cournoyer
2025-06-20 13:48 ` Junio C Hamano
2025-06-20 14:22   ` Andreas Schwab
2025-06-20 16:39     ` Junio C Hamano
2025-06-21 13:57     ` Maxim Cournoyer
2025-06-23  3:28   ` Maxim Cournoyer
2025-06-23  3:34   ` Maxim Cournoyer
2025-06-20 19:03 ` brian m. carlson
2025-06-21 13:29   ` Maxim Cournoyer
2025-06-21 15:52     ` brian m. carlson
2025-06-22 15:25 ` [PATCH v2 0/3] git-credential-netrc: better symbolic port names support Maxim Cournoyer
2025-06-22 15:25 ` [PATCH v2 1/3] contrib: use a more portable shebang for git-credential-netrc Maxim Cournoyer
2025-06-22 15:25 ` [PATCH v2 2/3] contrib: warn for invalid netrc file ports in git-credential-netrc Maxim Cournoyer
2025-06-22 15:25 ` [PATCH v2 3/3] contrib: better support symbolic port names " Maxim Cournoyer
2025-06-23 18:03   ` Junio C Hamano
2025-06-24  1:51     ` Maxim Cournoyer [this message]
2025-06-24  1:48 ` [PATCH v3 0/3] git-credential-netrc: better symbolic port names support Maxim Cournoyer
2025-06-24 16:04   ` Junio C Hamano
2025-06-24 23:55     ` Maxim Cournoyer
2025-06-25  0:24       ` Junio C Hamano
2025-06-25  1:03         ` Maxim Cournoyer
2025-06-25 14:25           ` [PATCH v4 " Maxim Cournoyer
2025-06-25 14:25             ` [PATCH v4 1/3] contrib: use a more portable shebang for git-credential-netrc Maxim Cournoyer
2025-06-25 14:25             ` [PATCH v4 2/3] contrib: warn for invalid netrc file ports in git-credential-netrc Maxim Cournoyer
2025-06-25 14:25             ` [PATCH v4 3/3] contrib: better support symbolic port names " Maxim Cournoyer
2025-06-25 16:49             ` [PATCH v4 0/3] git-credential-netrc: better symbolic port names support Junio C Hamano
2025-06-26  1:15               ` Maxim Cournoyer
2025-06-24  1:48 ` [PATCH v3 1/3] contrib: use a more portable shebang for git-credential-netrc Maxim Cournoyer
2025-06-24  1:48 ` [PATCH v3 2/3] contrib: warn for invalid netrc file ports in git-credential-netrc Maxim Cournoyer
2025-06-24  1:48 ` [PATCH v3 3/3] contrib: better support symbolic port names " Maxim Cournoyer
2025-06-24 16:06   ` 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=87o6ud52l8.fsf@terra.mail-host-address-is-not-set \
    --to=maxim@guixotic.coop \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).