Skip to content

Commit f612a71

Browse files
jnarebgitster
authored andcommitted
gitweb: Refactor reading and parsing config file into read_config_file
Beside being obvious reduction of duplicated code, this is enables us to easily call site-wide config file in per-installation config file. The actual update to documentation is left for next commit, because of possible exclusive alternative (possible other next commit) of always reading system-wide config file and relying on per-instalation config file overriding system-wide defaults. Signed-off-by: Jakub Narebski <[email protected]> Acked-by: John 'Warthog9' Hawley <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 600a6a6 commit f612a71

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

gitweb/gitweb.perl

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -623,18 +623,30 @@ sub filter_snapshot_fmts {
623623
# if it is true then gitweb config would be run for each request.
624624
our $per_request_config = 1;
625625

626+
# read and parse gitweb config file given by its parameter.
627+
# returns true on success, false on recoverable error, allowing
628+
# to chain this subroutine, using first file that exists.
629+
# dies on errors during parsing config file, as it is unrecoverable.
630+
sub read_config_file {
631+
my $filename = shift;
632+
return unless defined $filename;
633+
# die if there are errors parsing config file
634+
if (-e $filename) {
635+
do $filename;
636+
die $@ if $@;
637+
return 1;
638+
}
639+
return;
640+
}
641+
626642
our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
627643
sub evaluate_gitweb_config {
628644
our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
629645
our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
630-
# die if there are errors parsing config file
631-
if (-e $GITWEB_CONFIG) {
632-
do $GITWEB_CONFIG;
633-
die $@ if $@;
634-
} elsif (-e $GITWEB_CONFIG_SYSTEM) {
635-
do $GITWEB_CONFIG_SYSTEM;
636-
die $@ if $@;
637-
}
646+
647+
# use first config file that exists
648+
read_config_file($GITWEB_CONFIG) or
649+
read_config_file($GITWEB_CONFIG_SYSTEM);
638650
}
639651

640652
# Get loadavg of system, to compare against $maxload.

0 commit comments

Comments
 (0)