From 585101959d74c3d207c871471ff089998c3e9b77 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 1 Jan 2018 00:37:27 -0800 Subject: [PATCH] Project.pm: allow unset config values to remain undef When loading values from the local project's config file, any values that do not have a value still end up getting loaded and assigned to the object with a value of "" (or possibly a different default value), but they always create the key in the project object's hash. Change this so that if the default value is specified explicitly as "undef" then when the config value does not exist no key will be created in the project object's hash for it at all. Signed-off-by: Kyle J. McKay --- Girocco/Project.pm | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Girocco/Project.pm b/Girocco/Project.pm index ae284e3..61b14ad 100644 --- a/Girocco/Project.pm +++ b/Girocco/Project.pm @@ -185,13 +185,14 @@ sub _property_fget { $pname or die "unknown property: $name"; if ($pname =~ /^([:%!])([^:]+)(:.*)?$/) { my ($where, $pname, $defval) = ($1, lc($2), substr(($3||":"),1)); + $defval = undef if $defval eq "undef"; $defval = '' if $nodef; $self->_readlocalconfigfile unless ref($self->{configfilehash}) eq 'HASH'; $pname = "gitweb." . $pname if $where eq ':' or $where eq '!' && $pname !~ /[.]/; my $val = $self->{configfilehash}->{$pname}; defined($val) or $val = $defval; - chomp $val; + chomp $val if defined($val); $val = _boolval($val, $defval) if $where eq '!'; return $nodef && !exists($self->{configfilehash}->{$pname}) ? undef : $val; } @@ -283,17 +284,13 @@ sub _lint_readme { sub _properties_load { my $self = shift; - foreach my $prop (keys %propmap) { - $self->{$prop} = $self->_property_fget($prop); - } - foreach my $prop (keys %propmapro) { - $self->{$prop} = $self->_property_fget($prop); - } - if ($self->{mirror}) { - foreach my $prop (keys %propmapromirror) { - $self->{$prop} = $self->_property_fget($prop); - } - } + my $setprop = sub { + my $propval = $self->_property_fget($_); + defined($propval) and $self->{$_} = $propval; + }; + &$setprop foreach keys %propmap; + &$setprop foreach keys %propmapro; + do {&$setprop foreach keys %propmapromirror} if $self->{mirror}; $self->_readlocalconfigfile unless ref($self->{configfilehash}) eq 'HASH'; delete $self->{auth}; -- 2.11.4.GIT