@matheusbsbs / matheus-bagliano / commits / 17a8b25005
Fork 0

gitweb: fallback to system-wide config file if default config does not exist

From a distribution point of view, configuration files for applications should reside in /etc/. On the other hand it's convenient for multiple instances of gitweb (e.g. virtual web servers on a single machine) to have a per-instance configuration file, just as gitweb currently supports through the file gitweb_config.perl next to the cgi. To support both at runtime, this commit introduces GITWEB_CONFIG_SYSTEM as a system-wide configuration file which will be used as a fallback if the config file sprecified throug GITWEB_CONFIG does not exist. See also http://bugs.debian.org/450592 Signed-off-by: Gerrit Pape <pape@smarden.org> Acked-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Gerrit Pape committed Mar 26, 2008 at 18:11 UTC 17a8b25005bb09b03bee7ddac5412c7d29675eef
4 files changed +20 -3
Makefile
+1
@@ -189,6 +189,7 @@ ETC_GITCONFIG = $(sysconfdir)/gitconfig
189
190 # default configuration for gitweb
191 GITWEB_CONFIG = gitweb_config.perl
192 +GITWEB_CONFIG_SYSTEM = /etc/gitweb.conf
193 GITWEB_HOME_LINK_STR = projects
194 GITWEB_SITENAME =
195 GITWEB_PROJECTROOT = /pub/git
gitweb/INSTALL
+5 -1
@@ -95,7 +95,11 @@ for gitweb (in gitweb/README).
95 by default it is file named gitweb_config.perl in the same place as
96 gitweb.cgi script. You can control default place for config file
97 using GITWEB_CONFIG build configuration variable, and you can set it
98 - using GITWEB_CONFIG environmental variable.
98 + using GITWEB_CONFIG environmental variable. If this file does not
99 + exist, gitweb looks for a system-wide configuration file, normally
100 + /etc/gitweb.conf. You can change the default using the
101 + GITWEB_CONFIG_SYSTEM build configuration variable, and override it
102 + through GITWEB_CONFIG_SYSTEM environmental variable.
103
104 - Gitweb config file is [fragment] of perl code. You can set variables
105 using "our $variable = value"; text from "#" character until the end
gitweb/README
+8 -1
@@ -100,13 +100,20 @@ You can specify the following configuration variables when building GIT:
100 is set when gitweb.cgi is executed, then the file specified in the
101 environment variable will be loaded instead of the file specified
102 when gitweb.cgi was created. [Default: gitweb_config.perl]
103 + * GITWEB_CONFIG_SYSTEM
104 + This Perl file will be loaded using 'do' as a fallback if GITWEB_CONFIG
105 + does not exist. If the environment variable GITWEB_CONFIG_SYSTEM is set
106 + when gitweb.cgi is executed, then the file specified in the environment
107 + variable will be loaded instead of the file specified when gitweb.cgi was
108 + created. [Default: /etc/gitweb.conf]
109
110
111 Runtime gitweb configuration
112 ----------------------------
113
114 You can adjust gitweb behaviour using the file specified in `GITWEB_CONFIG`
109 -(defaults to 'gitweb_config.perl' in the same directory as the CGI).
115 +(defaults to 'gitweb_config.perl' in the same directory as the CGI), and
116 +as a fallback `GITWEB_CONFIG_SYSTEM` (defaults to /etc/gitweb.conf).
117 The most notable thing that is not configurable at compile time are the
118 optional features, stored in the '%features' variable.
119
gitweb/gitweb.perl
+6 -1
@@ -369,7 +369,12 @@ sub filter_snapshot_fmts {
369 }
370
371 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
372 -do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
372 +if (-e $GITWEB_CONFIG) {
373 + do $GITWEB_CONFIG;
374 +} else {
375 + our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
376 + do $GITWEB_CONFIG_SYSTEM if -e $GITWEB_CONFIG_SYSTEM;
377 +}
378
379 # version of the core git binary
380 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";