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

Re: [PATCHv5] Add contrib/credentials/netrc with GPG support

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 5, 2013, 23:58 UTC
Message-ID
<7vtxpqnwiv.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vip66qu0u.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
> Otherwise, looks almost ready to me.

For now, I've queued this as a minimum fix-up on top of your patch and pushed the result out. It is an equivalent of the previous review comments in a patch form. Please review and incorporate in your reroll as appropriate.

I haven't looked at the part that interacts with the credential subsystem itself, though.

 contrib/credential/netrc/git-credential-netrc | 35 ++++++++++++---------------
 1 file changed, 16 insertions(+), 19 deletions(-)
diff --git a/contrib/credential/netrc/git-credential-netrc b/contrib/credential/netrc/git-credential-netrc
index 8298564..30e05fb 100755
--- a/contrib/credential/netrc/git-credential-netrc
+++ b/contrib/credential/netrc/git-credential-netrc
@@ -74,6 +74,10 @@ Options:
                        first matching entry found is returned via the credential
                        helper protocol (see below).
 
+                       When no -f option is given, .authinfo.gpg, .netrc.gpg,
+		       .authinfo, and .netrc files in your home directory are used
+		       in this order.
+
   -k|--insecure      : ignore bad file ownership or permissions
 
   -d|--debug         : turn on debugging (developer info)
@@ -206,8 +210,7 @@ foreach my $file (@$files) {
 	unless (scalar @entries) {
 		if ($!) {
 			log_verbose("Unable to open $file: $!");
-		}
-		else {
+		} else {
 			log_verbose("No netrc entries found in $file");
 		}
 
@@ -230,15 +233,10 @@ sub load_netrc {
 
 	my $io;
 	if ($gpgmode) {
-		# typical shell character escapes from http://www.slac.stanford.edu/slac/www/resource/how-to-use/cgi-rexx/cgi-esc.html
-		my $f = $file;
-		$f =~ s/([;<>\*\|`&\$!#\(\)\[\]\{\}:'"])/\\$1/g;
-		# GPG doesn't work well with 2- or 3-argument open
-		my $cmd = "gpg --decrypt $f";
-		log_verbose("Using GPG to open $file: [$cmd]");
-		open $io, "$cmd|";
-	}
-	else {
+		my @cmd = (qw(gpg --decrypt), $file)
+		log_verbose("Using GPG to open $file: [@cmd]");
+		open $io, "-|", @cmd;
+	} else {
 		log_verbose("Opening $file...");
 		open $io, '<', $file;
 	}
@@ -257,6 +255,9 @@ sub load_netrc {
 		my %entry;
 		my $num_port;
 
+		if (!defined $nentry->{machine}) {
+			next;
+		}
 		if (defined $nentry->{port} && $nentry->{port} =~ m/^\d+$/) {
 			$num_port = $nentry->{port};
 			delete $nentry->{port};
@@ -302,8 +303,7 @@ sub net_netrc_loader {
 		while (@tok) {
 			if ($tok[0] eq "default") {
 				shift(@tok);
-				undef $mach; # ignore 'default' lines
-
+				$mach = { machine => undef }
 				next TOKEN;
 			}
 
@@ -313,8 +313,7 @@ sub net_netrc_loader {
 				my $host = shift @tok;
 				$mach = { machine => $host };
 				push @entries, $mach;
-			}
-			elsif (exists $options{tmap}->{$tok}) {
+			} elsif (exists $options{tmap}->{$tok}) {
 				unless ($mach) {
 					log_debug("Skipping token $tok because no machine was given");
 					next TOKEN;
@@ -329,8 +328,7 @@ sub net_netrc_loader {
 				# Following line added by rmerrell to remove '/' escape char in .netrc
 				$value =~ s/\/\\/\\/g;
 				$mach->{$tok} = $value;
-			}
-			elsif ($tok eq "macdef") { # we ignore macros
+			} elsif ($tok eq "macdef") { # we ignore macros
 				next TOKEN unless $mach;
 				my $value = shift @tok;
 				$macdef = 1;
@@ -380,8 +378,7 @@ sub find_netrc_entry {
 				unless ($query->{$check} eq $entry->{$check}) {
 					next ENTRY;
 				}
-			}
-			else {
+			} else {
 				log_debug("OK: any value satisfies check $check");
 			}
 		}
-- 
1.8.1.2.641.g0b90ac4
Previous: Junio C HamanoNext: Ted Zlatanov
Message 26 of 38 in “Add contrib/credentials/netrc with GPG support”
  1. Add contrib/credentials/netrc with GPG supportTed Zlatanov, Feb 4, 2013
  2. Jeff KingFeb 4, 2013
  3. Ted ZlatanovFeb 4, 2013
  4. Add contrib/credentials/netrc with GPG support, try #2Ted Zlatanov, Feb 4, 2013
  5. Junio C HamanoFeb 4, 2013
  6. Jeff KingFeb 4, 2013
  7. Junio C HamanoFeb 4, 2013
  8. Ted ZlatanovFeb 4, 2013
  9. [PATCHv3] Add contrib/credentials/netrc with GPG supportTed Zlatanov, Feb 4, 2013
  10. Ted ZlatanovFeb 4, 2013
  11. Junio C HamanoFeb 4, 2013
  12. Ted ZlatanovFeb 4, 2013
  13. Junio C HamanoFeb 5, 2013
  14. Ted ZlatanovFeb 5, 2013
  15. Junio C HamanoFeb 5, 2013
  16. Junio C HamanoFeb 5, 2013
  17. Junio C HamanoFeb 5, 2013
  18. Ted ZlatanovFeb 5, 2013
  19. [PATCHv4] Add contrib/credentials/netrc with GPG supportTed Zlatanov, Feb 5, 2013
  20. Junio C HamanoFeb 5, 2013
  21. Ted ZlatanovFeb 5, 2013
  22. Junio C HamanoFeb 5, 2013
  23. Ted ZlatanovFeb 5, 2013
  24. [PATCHv5] Add contrib/credentials/netrc with GPG supportTed Zlatanov, Feb 5, 2013
  25. Junio C HamanoFeb 5, 2013
  26. Junio C HamanoFeb 5, 2013
  27. [PATCHv6] Add contrib/credentials/netrc with GPG supportTed Zlatanov, Feb 6, 2013
  28. Junio C HamanoFeb 7, 2013
  29. Ted ZlatanovFeb 8, 2013
  30. Junio C HamanoFeb 8, 2013
  31. Jeff KingFeb 8, 2013
  32. Ted ZlatanovFeb 25, 2013
  33. Add contrib/credentials/netrc with GPG supportTed Zlatanov, Feb 25, 2013
  34. Ted ZlatanovFeb 6, 2013
  35. Junio C HamanoFeb 5, 2013
  36. Ted ZlatanovFeb 5, 2013
  37. Junio C HamanoFeb 5, 2013
  38. Ted ZlatanovFeb 5, 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.