Skip to content

Commit df5d10a

Browse files
Marcel M. Carygitster
authored andcommitted
gitweb: Fix warnings with override permitted but no repo override
When a feature like "blame" is permitted to be overridden in the repository configuration but it is not actually set in the repository, a warning is emitted due to the undefined value of the repository configuration, even though it's a perfectly normal condition. Emitting warning is grounds for test failure in the gitweb test script. This error was caused by rewrite of git_get_project_config from using "git config [<type>] <name>" for each individual configuration variable checked to parsing "git config --list --null" output in commit b201927 (gitweb: Read repo config using 'git config -z -l'). Earlier version of git_get_project_config was returning empty string if variable do not exist in config; newer version is meant to return undef in this case, therefore change in feature_bool was needed. Additionally config_to_* subroutines were meant to be invoked only if configuration variable exists; therefore we added early return to git_get_project_config: it now returns no value if variable does not exists in config. Otherwise config_to_* subroutines (config_to_bool in paryicular) wouldn't be able to distinguish between the case where variable does not exist and the case where variable doesn't have value (the "[section] noval" case, which evaluates to true for boolean). While at it fix bug in config_to_bool, where checking if $val is defined (if config variable has value) was done _after_ stripping leading and trailing whitespace, which lead to 'Use of uninitialized value' warning. Add test case for features overridable but not overriden in repo config, and case for no value boolean configuration variable. Signed-off-by: Marcel M. Cary <marcel@oak.homeunix.org> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent bf3c20f commit df5d10a

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

gitweb/gitweb.perl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,13 @@ sub feature_bool {
402402
my $key = shift;
403403
my ($val) = git_get_project_config($key, '--bool');
404404

405-
if ($val eq 'true') {
405+
if (!defined $val) {
406+
return ($_[0]);
407+
} elsif ($val eq 'true') {
406408
return (1);
407409
} elsif ($val eq 'false') {
408410
return (0);
409411
}
410-
411-
return ($_[0]);
412412
}
413413

414414
sub feature_snapshot {
@@ -1914,18 +1914,19 @@ sub git_parse_project_config {
19141914
return %config;
19151915
}
19161916

1917-
# convert config value to boolean, 'true' or 'false'
1917+
# convert config value to boolean: 'true' or 'false'
19181918
# no value, number > 0, 'true' and 'yes' values are true
19191919
# rest of values are treated as false (never as error)
19201920
sub config_to_bool {
19211921
my $val = shift;
19221922

1923+
return 1 if !defined $val; # section.key
1924+
19231925
# strip leading and trailing whitespace
19241926
$val =~ s/^\s+//;
19251927
$val =~ s/\s+$//;
19261928

1927-
return (!defined $val || # section.key
1928-
($val =~ /^\d+$/ && $val) || # section.key = 1
1929+
return (($val =~ /^\d+$/ && $val) || # section.key = 1
19291930
($val =~ /^(?:true|yes)$/i)); # section.key = true
19301931
}
19311932

@@ -1978,6 +1979,9 @@ sub git_get_project_config {
19781979
$config_file = "$git_dir/config";
19791980
}
19801981

1982+
# check if config variable (key) exists
1983+
return unless exists $config{"gitweb.$key"};
1984+
19811985
# ensure given type
19821986
if (!defined $type) {
19831987
return $config{"gitweb.$key"};

t/t9500-gitweb-standalone-no-errors.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,11 @@ cat >>gitweb_config.perl <<EOF
661661
\$feature{'snapshot'}{'override'} = 1;
662662
EOF
663663

664+
test_expect_success \
665+
'config override: tree view, features not overridden in repo config' \
666+
'gitweb_run "p=.git;a=tree"'
667+
test_debug 'cat gitweb.log'
668+
664669
test_expect_success \
665670
'config override: tree view, features disabled in repo config' \
666671
'git config gitweb.blame no &&
@@ -669,12 +674,23 @@ test_expect_success \
669674
test_debug 'cat gitweb.log'
670675

671676
test_expect_success \
672-
'config override: tree view, features enabled in repo config' \
677+
'config override: tree view, features enabled in repo config (1)' \
673678
'git config gitweb.blame yes &&
674679
git config gitweb.snapshot "zip,tgz, tbz2" &&
675680
gitweb_run "p=.git;a=tree"'
676681
test_debug 'cat gitweb.log'
677682

683+
cat >.git/config <<\EOF
684+
# testing noval and alternate separator
685+
[gitweb]
686+
blame
687+
snapshot = zip tgz
688+
EOF
689+
test_expect_success \
690+
'config override: tree view, features enabled in repo config (2)' \
691+
'gitweb_run "p=.git;a=tree"'
692+
test_debug 'cat gitweb.log'
693+
678694
# ----------------------------------------------------------------------
679695
# non-ASCII in README.html
680696

0 commit comments

Comments
 (0)