Git fork

Merge branch 'mc/netrc-service-names'

"netrc" credential helper has been improved to understand textual
service names (like smtp) in addition to the numeric port numbers
(like 25).

* mc/netrc-service-names:
contrib: better support symbolic port names in git-credential-netrc
contrib: warn for invalid netrc file ports in git-credential-netrc
contrib: use a more portable shebang for git-credential-netrc

+46 -7
+11 -3
contrib/credential/netrc/git-credential-netrc.perl
··· 1 - #!/usr/bin/perl 2 3 use strict; 4 use warnings; ··· 267 if (!defined $nentry->{machine}) { 268 next; 269 } 270 - if (defined $nentry->{port} && $nentry->{port} =~ m/^\d+$/) { 271 - $num_port = $nentry->{port}; 272 delete $nentry->{port}; 273 } 274
··· 1 + #!/usr/bin/env perl 2 3 use strict; 4 use warnings; ··· 267 if (!defined $nentry->{machine}) { 268 next; 269 } 270 + if (defined $nentry->{port}) { 271 + $num_port = Git::port_num($nentry->{port}); 272 + unless ($num_port) { 273 + printf(STDERR "ignoring invalid port `%s' " . 274 + "from netrc file\n", $nentry->{port}); 275 + } 276 + # Since we've already validated and converted 277 + # the port to its numerical value, do not 278 + # capture it as the `protocol' value, as used 279 + # to be the case for symbolic port names. 280 delete $nentry->{port}; 281 } 282
+4 -4
contrib/credential/netrc/test.pl
··· 45 diag "Testing with invalid data\n"; 46 $cred = run_credential(['-f', $netrc, 'get'], 47 "bad data"); 48 - ok(scalar keys %$cred == 4, "Got first found keys with bad data"); 49 50 diag "Testing netrc file for a missing corovamilkbar entry\n"; 51 $cred = run_credential(['-f', $netrc, 'get'], ··· 64 65 diag "Testing netrc file for a username-specific entry\n"; 66 $cred = run_credential(['-f', $netrc, 'get'], 67 - { host => 'imap', username => 'bob' }); 68 69 - ok(scalar keys %$cred == 2, "Got 2 username-specific keys"); 70 71 is($cred->{password}, 'bobwillknow', "Got correct user-specific password"); 72 - is($cred->{protocol}, 'imaps', "Got correct user-specific protocol"); 73 74 diag "Testing netrc file for a host:port-specific entry\n"; 75 $cred = run_credential(['-f', $netrc, 'get'],
··· 45 diag "Testing with invalid data\n"; 46 $cred = run_credential(['-f', $netrc, 'get'], 47 "bad data"); 48 + ok(scalar keys %$cred == 3, "Got first found keys with bad data"); 49 50 diag "Testing netrc file for a missing corovamilkbar entry\n"; 51 $cred = run_credential(['-f', $netrc, 'get'], ··· 64 65 diag "Testing netrc file for a username-specific entry\n"; 66 $cred = run_credential(['-f', $netrc, 'get'], 67 + { host => 'imap:993', username => 'bob' }); 68 69 + # Only the password field gets returned. 70 + ok(scalar keys %$cred == 1, "Got 1 username-specific keys"); 71 72 is($cred->{password}, 'bobwillknow', "Got correct user-specific password"); 73 74 diag "Testing netrc file for a host:port-specific entry\n"; 75 $cred = run_credential(['-f', $netrc, 'get'],
+11
git-send-email.perl
··· 2112 } 2113 } 2114 2115 # Run the loop once again to avoid gaps in the counter due to FIFO 2116 # arguments provided by the user. 2117 my $num = 1;
··· 2112 } 2113 } 2114 2115 + # Validate the SMTP server port, if provided. 2116 + if (defined $smtp_server_port) { 2117 + my $port = Git::port_num($smtp_server_port); 2118 + if ($port) { 2119 + $smtp_server_port = $port; 2120 + } else { 2121 + die sprintf(__("error: invalid SMTP port '%s'\n"), 2122 + $smtp_server_port); 2123 + } 2124 + } 2125 + 2126 # Run the loop once again to avoid gaps in the counter due to FIFO 2127 # arguments provided by the user. 2128 my $num = 1;
+13
perl/Git.pm
··· 1061 delete @$self{@vars}; 1062 } 1063 1064 1065 =item credential_read( FILEHANDLE ) 1066
··· 1061 delete @$self{@vars}; 1062 } 1063 1064 + # Given PORT, a port number or service name, return its numerical 1065 + # value else undef. 1066 + sub port_num { 1067 + my ($port) = @_; 1068 + 1069 + # Port can be either a positive integer within the 16-bit range... 1070 + if ($port =~ /^\d+$/ && $port > 0 && $port <= (2**16 - 1)) { 1071 + return $port; 1072 + } 1073 + 1074 + # ... or a symbolic port (service name). 1075 + return scalar getservbyname($port, ''); 1076 + } 1077 1078 =item credential_read( FILEHANDLE ) 1079
+7
t/t9001-send-email.sh
··· 201 test_cmp expected-cc commandline1 202 ' 203 204 test_expect_success $PREREQ 'setup expect' " 205 cat >expected-show-all-headers <<\EOF 206 0001-Second.patch
··· 201 test_cmp expected-cc commandline1 202 ' 203 204 + test_expect_failure $PREREQ 'invalid smtp server port value' ' 205 + clean_fake_sendmail && 206 + git send-email -1 --to=recipient@example.com \ 207 + --smtp-server-port=bogus-symbolic-name \ 208 + --smtp-server="$(pwd)/fake.sendmail" 209 + ' 210 + 211 test_expect_success $PREREQ 'setup expect' " 212 cat >expected-show-all-headers <<\EOF 213 0001-Second.patch