]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Config.pm
config: use NUL-delimited git-config(1) output
[public-inbox.git] / lib / PublicInbox / Config.pm
index 09f9179b085a4dd90aed20e0d8b277ede66cc870..4fcb20d24437dee77aeb1bdf6e1ecc6f92c9466d 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2014-2019 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Used throughout the project for reading configuration
@@ -151,14 +151,14 @@ sub git_config_dump {
        my ($file) = @_;
        my (%section_seen, @section_order);
        return {} unless -e $file;
-       my @cmd = (qw/git config/, "--file=$file", '-l');
+       my @cmd = (qw/git config -z -l/, "--file=$file");
        my $cmd = join(' ', @cmd);
        my $fh = popen_rd(\@cmd) or die "popen_rd failed for $file: $!\n";
        my %rv;
-       local $/ = "\n";
+       local $/ = "\0";
        while (defined(my $line = <$fh>)) {
                chomp $line;
-               my ($k, $v) = split(/=/, $line, 2);
+               my ($k, $v) = split(/\n/, $line, 2);
 
                my ($section) = ($k =~ /\A(\S+)\.[^\.]+\z/);
                unless (defined $section_seen{$section}) {
@@ -307,7 +307,7 @@ sub parse_cgitrc {
                        }
                } elsif (m!\Ainclude=(.+)\z!) {
                        parse_cgitrc($self, $1, $nesting + 1);
-               } elsif (m!\A(scan-hidden-path|remove-suffix)=(\d+)\z!) {
+               } elsif (m!\A(scan-hidden-path|remove-suffix)=([0-9]+)\z!) {
                        my ($k, $v) = ($1, $2);
                        $k =~ tr/-/_/;
                        $self->{"-cgit_$k"} = $v;
@@ -366,6 +366,17 @@ sub _fill_code_repo {
        $git;
 }
 
+sub _git_config_bool ($) {
+       my ($val) = @_;
+       if ($val =~ /\A(?:false|no|off|[\-\+]?(?:0x)?0+)\z/i) {
+               0;
+       } elsif ($val =~ /\A(?:true|yes|on|[\-\+]?(?:0x)?[0-9]+)\z/i) {
+               1;
+       } else {
+               undef;
+       }
+}
+
 sub _fill {
        my ($self, $pfx) = @_;
        my $ibx = {};
@@ -379,10 +390,8 @@ sub _fill {
        foreach my $k (qw(obfuscate)) {
                my $v = $self->{"$pfx.$k"};
                defined $v or next;
-               if ($v =~ /\A(?:false|no|off|0)\z/) {
-                       $ibx->{$k} = 0;
-               } elsif ($v =~ /\A(?:true|yes|on|1)\z/) {
-                       $ibx->{$k} = 1;
+               if (defined(my $bval = _git_config_bool($v))) {
+                       $ibx->{$k} = $bval;
                } else {
                        warn "Ignoring $pfx.$k=$v in config, not boolean\n";
                }