Signed-off-by: Ted Zlatanov <tzz@xxxxxxxxxxxx> --- contrib/credential/netrc/git-credential-netrc | 38 +++++++++++++------------ 1 files changed, 20 insertions(+), 18 deletions(-) diff --git a/contrib/credential/netrc/git-credential-netrc b/contrib/credential/netrc/git-credential-netrc index a47a223..0e35918 100755 --- a/contrib/credential/netrc/git-credential-netrc +++ b/contrib/credential/netrc/git-credential-netrc @@ -3,8 +3,6 @@ use strict; use warnings; -use Data::Dumper; - use Getopt::Long; use File::Basename; @@ -58,7 +56,7 @@ if ($options{help}) $0 [-f AUTHFILE] [-d] get -Version $VERSION by tzz\@lifelogs.com. License: any use is OK. +Version $VERSION by tzz\@lifelogs.com. License: BSD. Options: -f AUTHFILE: specify a netrc-style file @@ -129,31 +127,36 @@ my $file = $options{file}; die "Sorry, you need to specify an existing netrc file (with or without a .gpg extension) with -f AUTHFILE" unless defined $file; -die "Sorry, the specified netrc $file is not accessible" - unless -f $file; +unless (-f $file) +{ + print STDERR "Sorry, the specified netrc $file is not accessible\n" if $debug; + exit 0; +} +my @data; if ($file =~ m/\.gpg$/) { - $file = "gpg --decrypt $file|"; + @data = load('-|', qw(gpg --decrypt), $file) +} +else +{ + @data = load('<', $file); } -my @data = load($file); chomp @data; -die "Sorry, we could not load data from [$file]" - unless (scalar @data); - -# the query -my %q; - -foreach my $v (values %{$options{tmap}}) +unless (scalar @data) { - undef $q{$v}; + print STDERR "Sorry, we could not load data from [$file]\n" if $debug; + exit; } +# the query: start with every token with no value +my %q = map { $_ => undef } values(%{$options{tmap}}); + while (<STDIN>) { - next unless m/([a-z]+)=(.+)/; + next unless m/([^=]+)=(.+)/; my ($token, $value) = ($1, $2); die "Unknown search token $1" unless exists $q{$token}; @@ -237,9 +240,8 @@ LINE: foreach my $line (@data) sub load { - my $file = shift; # this supports pipes too - my $io = new IO::File($file) or die "Could not open $file: $!\n"; + my $io = new IO::File(@_) or die "Could not open [@_]: $!\n"; return <$io>; # whole file } -- 1.7.9.rc2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html