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

Re: [PATCH v2 3/3] contrib: better support symbolic port names in git-credential-netrc

From
MCMaxim Cournoyer <maxim@guixotic.coop>
Date
Jun 24, 2025, 01:51 UTC
Message-ID
<87o6ud52l8.fsf@terra.mail-host-address-is-not-set>
In-Reply-To
<xmqqh6065o9f.fsf@gitster.g>
Hi!
tl;dr: I've submitted a v3 with most of your suggestions implemented.
Junio C Hamano <gitster@pobox.com> writes:
[...]
Show 25 quoted lines
>> 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.

[...]
Show 8 quoted lines
> 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.
Show 17 quoted lines
>> +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
Previous: Junio C HamanoNext: Maxim Cournoyer
Message 15 of 31 in “contrib: Honor symbolic port in git-credential-netrc.”
  1. contrib: Honor symbolic port in git-credential-netrc.Maxim Cournoyer, Jun 20, 2025
  2. Junio C HamanoJun 20, 2025
  3. Andreas SchwabJun 20, 2025
  4. Junio C HamanoJun 20, 2025
  5. Maxim CournoyerJun 21, 2025
  6. Maxim CournoyerJun 23, 2025
  7. Maxim CournoyerJun 23, 2025
  8. brian m. carlsonJun 20, 2025
  9. Maxim CournoyerJun 21, 2025
  10. brian m. carlsonJun 21, 2025
  11. 1/3 contrib: use a more portable shebang for git-credential-netrcMaxim Cournoyer, Jun 22, 2025
  12. 0/3 git-credential-netrc: better symbolic port names supportMaxim Cournoyer, Jun 22, 2025
  13. 3/3 contrib: better support symbolic port names in git-credential-netrcMaxim Cournoyer, Jun 22, 2025
  14. Junio C HamanoJun 23, 2025
  15. Maxim CournoyerJun 24, 2025
  16. 2/3 contrib: warn for invalid netrc file ports in git-credential-netrcMaxim Cournoyer, Jun 22, 2025
  17. 1/3 contrib: use a more portable shebang for git-credential-netrcMaxim Cournoyer, Jun 24, 2025
  18. 0/3 git-credential-netrc: better symbolic port names supportMaxim Cournoyer, Jun 24, 2025
  19. Junio C HamanoJun 24, 2025
  20. Maxim CournoyerJun 24, 2025
  21. Junio C HamanoJun 25, 2025
  22. Maxim CournoyerJun 25, 2025
  23. 0/3 git-credential-netrc: better symbolic port names supportMaxim Cournoyer, Jun 25, 2025
  24. 2/3 contrib: warn for invalid netrc file ports in git-credential-netrcMaxim Cournoyer, Jun 25, 2025
  25. 3/3 contrib: better support symbolic port names in git-credential-netrcMaxim Cournoyer, Jun 25, 2025
  26. 1/3 contrib: use a more portable shebang for git-credential-netrcMaxim Cournoyer, Jun 25, 2025
  27. Junio C HamanoJun 25, 2025
  28. Maxim CournoyerJun 26, 2025
  29. 3/3 contrib: better support symbolic port names in git-credential-netrcMaxim Cournoyer, Jun 24, 2025
  30. Junio C HamanoJun 24, 2025
  31. 2/3 contrib: warn for invalid netrc file ports in git-credential-netrcMaxim Cournoyer, Jun 24, 2025

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.