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 <jnareb@gmail.com> Acked-by: John 'Warthog9' Hawley <warthog9@kernel.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jakub Narebski committed May 25, 2011 at 18:35 UTC f612a71cc901e34f5cf154e6605b7251744f6b95
1 file changed +20 -8
gitweb/gitweb.perl
+20 -8
@@ -623,18 +623,30 @@ sub filter_snapshot_fmts {
623 # if it is true then gitweb config would be run for each request.
624 our $per_request_config = 1;
625
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 +
642 our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
643 sub evaluate_gitweb_config {
644 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
645 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);
650 }
651
652 # Get loadavg of system, to compare against $maxload.