Skip to content

Commit 9be3614

Browse files
jnarebgitster
authored andcommitted
gitweb: Fix project-specific feature override behavior
This commit fixes a bug in processing project-specific override in a situation when there is no project, e.g. for the projects list page. When 'snapshot' feature had project specific config override enabled by putting $feature{'snapshot'}{'override'} = 1; (or equivalent) in $GITWEB_CONFIG, and when viewing toplevel gitweb page, which means the projects list page (to be more exact this happens for any project-less action), gitweb would put the following Perl warnings in error log: gitweb.cgi: Use of uninitialized value $git_dir in concatenation (.) or string at gitweb.cgi line 2065. fatal: error processing config file(s) gitweb.cgi: Use of uninitialized value $git_dir in concatenation (.) or string at gitweb.cgi line 2221. gitweb.cgi: Use of uninitialized value $git_dir in concatenation (.) or string at gitweb.cgi line 2218. The problem is in the following fragment of code: # path to the current git repository our $git_dir; $git_dir = "$projectroot/$project" if $project; # list of supported snapshot formats our @snapshot_fmts = gitweb_get_feature('snapshot'); @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts); For the toplevel gitweb page, which is the list of projects, $project is not defined, therefore neither is $git_dir. gitweb_get_feature() subroutine calls git_get_project_config() if project specific override is turned on... but we don't have project here. Those errors mentioned above occur in the following fragment of code in git_get_project_config(): # get config if (!defined $config_file || $config_file ne "$git_dir/config") { %config = git_parse_project_config('gitweb'); $config_file = "$git_dir/config"; } git_parse_project_config() calls git_cmd() which has '--git-dir='.$git_dir There are (at least) three possible solutions: 1. Harden gitweb_get_feature() so that it doesn't call git_get_project_config() if $project (and therefore $git_dir) is not defined; there is no project for project specific config. 2. Harden git_get_project_config() like you did in your fix, returning early if $git_dir is not defined. 3. Harden git_cmd() so that it doesn't add "--git-dir=$git_dir" if $git_dir is not defined, and change git_get_project_config() so that it doesn't even try to access $git_dir if it is not defined. This commit implements both 1.) and 2.), i.e. gitweb_get_feature() doesn't call project-specific override if $git_dir is not defined (if there is no project), and git_get_project_config() returns early if $git_dir is not defined. Add a test for this bug to t/t9500-gitweb-standalone-no-errors.sh test. Reported-by: Eli Barzilay <eli@barzilay.org> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 964ad92 commit 9be3614

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

gitweb/gitweb.perl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,11 @@ sub gitweb_get_feature {
454454
$feature{$name}{'sub'},
455455
$feature{$name}{'override'},
456456
@{$feature{$name}{'default'}});
457-
if (!$override) { return @defaults; }
457+
# project specific override is possible only if we have project
458+
our $git_dir; # global variable, declared later
459+
if (!$override || !defined $git_dir) {
460+
return @defaults;
461+
}
458462
if (!defined $sub) {
459463
warn "feature $name is not overridable";
460464
return @defaults;
@@ -2202,6 +2206,9 @@ sub config_to_multi {
22022206
sub git_get_project_config {
22032207
my ($key, $type) = @_;
22042208

2209+
# do we have project
2210+
return unless (defined $project && defined $git_dir);
2211+
22052212
# key sanity check
22062213
return unless ($key);
22072214
$key =~ s/^gitweb\.//;

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,21 @@ test_debug 'cat gitweb.log'
591591
# ----------------------------------------------------------------------
592592
# gitweb config and repo config
593593

594-
cat >>gitweb_config.perl <<EOF
595-
596-
\$feature{'blame'}{'override'} = 1;
597-
\$feature{'snapshot'}{'override'} = 1;
598-
\$feature{'avatar'}{'override'} = 1;
594+
cat >>gitweb_config.perl <<\EOF
595+
596+
# turn on override for each overridable feature
597+
foreach my $key (keys %feature) {
598+
if ($feature{$key}{'sub'}) {
599+
$feature{$key}{'override'} = 1;
600+
}
601+
}
599602
EOF
600603

604+
test_expect_success \
605+
'config override: projects list (implicit)' \
606+
'gitweb_run'
607+
test_debug 'cat gitweb.log'
608+
601609
test_expect_success \
602610
'config override: tree view, features not overridden in repo config' \
603611
'gitweb_run "p=.git;a=tree"'

0 commit comments

Comments
 (0)