gitweb: Introduce common system-wide settings for convenience

Because of backward compatibility we cannot change gitweb to always use /etc/gitweb.conf (i.e. even if gitweb_config.perl exists). For common system-wide settings we therefore need separate configuration file: /etc/gitweb-common.conf. Long description: gitweb currently obtains configuration from the following sources: 1. per-instance configuration file (default: gitweb_conf.perl) 2. system-wide configuration file (default: /etc/gitweb.conf) If per-instance configuration file exists, then system-wide configuration is _not used at all_. This is quite untypical and suprising behavior. Moreover it is different from way git itself treats /etc/git.conf. It reads in stuff from /etc/git.conf and then local repos can change or override things as needed. In fact this is quite beneficial, because it gives site admins a simple and easy way to give an automatic hint to a repo about things the admin would like. On the other hand changing current behavior may lead to the situation, where something in /etc/gitweb.conf may interfere with unintended interaction in the local repository. One solution would be to _require_ to do explicit include; with read_config_file() it is now easy, as described in gitweb/README (description introduced in this commit). But as J.H. noticed we cannot ask people to modify their per-instance gitweb config file to include system-wide settings, nor we can require them to do this. Therefore, as proposed by Junio, for gitweb to have centralized config elements while retaining backwards compatibility, introduce separate common system-wide configuration file, by default /etc/gitweb-common.conf Noticed-by: Drew Northup <drew.northup@maine.edu> Helped-by: John 'Warthog9' Hawley <warthog9@kernel.org> Inspired-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jakub Narebski committed Jul 25, 2011 at 00:29 UTC 131d6afcba657f9348031ee2e20f62d25d69ce7a
4 files changed +53 -7
gitweb/INSTALL
+12 -1
@@ -231,7 +231,7 @@ Gitweb config file
231 See also "Runtime gitweb configuration" section in README file
232 for gitweb (in gitweb/README).
233
234 -- You can configure gitweb further using the gitweb configuration file;
234 +- You can configure gitweb further using the per-instance gitweb configuration file;
235 by default this is a file named gitweb_config.perl in the same place as
236 gitweb.cgi script. You can control the default place for the config file
237 using the GITWEB_CONFIG build configuration variable, and you can set it
@@ -241,6 +241,17 @@ for gitweb (in gitweb/README).
241 GITWEB_CONFIG_SYSTEM build configuration variable, and override it
242 through the GITWEB_CONFIG_SYSTEM environment variable.
243
244 + Note that if per-instance configuration file exists, then system-wide
245 + configuration is _not used at all_. This is quite untypical and suprising
246 + behavior. On the other hand changing current behavior would break backwards
247 + compatibility and can lead to unexpected changes in gitweb behavior.
248 + Therefore gitweb also looks for common system-wide configuration file,
249 + normally /etc/gitweb-common.conf (set during build time using build time
250 + configuration variable GITWEB_CONFIG_COMMON, set it at runtime using
251 + environment variable with the same name). Settings from per-instance or
252 + system-wide configuration file override those from common system-wide
253 + configuration file.
254 +
255 - The gitweb config file is a fragment of perl code. You can set variables
256 using "our $variable = value"; text from "#" character until the end
257 of a line is ignored. See perlsyn(1) for details.
gitweb/Makefile
+2
@@ -20,6 +20,7 @@ INSTALL ?= install
20 # default configuration for gitweb
21 GITWEB_CONFIG = gitweb_config.perl
22 GITWEB_CONFIG_SYSTEM = /etc/gitweb.conf
23 +GITWEB_CONFIG_COMMON = /etc/gitweb-common.conf
24 GITWEB_HOME_LINK_STR = projects
25 GITWEB_SITENAME =
26 GITWEB_PROJECTROOT = /pub/git
@@ -129,6 +130,7 @@ GITWEB_REPLACE = \
130 -e 's|++GIT_BINDIR++|$(bindir)|g' \
131 -e 's|++GITWEB_CONFIG++|$(GITWEB_CONFIG)|g' \
132 -e 's|++GITWEB_CONFIG_SYSTEM++|$(GITWEB_CONFIG_SYSTEM)|g' \
133 + -e 's|++GITWEB_CONFIG_COMMON++|$(GITWEB_CONFIG_COMMON)|g' \
134 -e 's|++GITWEB_HOME_LINK_STR++|$(GITWEB_HOME_LINK_STR)|g' \
135 -e 's|++GITWEB_SITENAME++|$(GITWEB_SITENAME)|g' \
136 -e 's|++GITWEB_PROJECTROOT++|$(GITWEB_PROJECTROOT)|g' \
gitweb/README
+24 -3
@@ -10,9 +10,30 @@ From the git version 1.4.0 gitweb is bundled with git.
10 Runtime gitweb configuration
11 ----------------------------
12
13 -You can adjust gitweb behaviour using the file specified in `GITWEB_CONFIG`
14 -(defaults to 'gitweb_config.perl' in the same directory as the CGI), and
15 -as a fallback `GITWEB_CONFIG_SYSTEM` (defaults to /etc/gitweb.conf).
13 +Gitweb obtains configuration data from the following sources in the
14 +following order:
15 +
16 +1. built-in values (some set during build stage),
17 +2. common system-wide configuration file (`GITWEB_CONFIG_COMMON`,
18 + defaults to '/etc/gitweb-common.conf'),
19 +3. either per-instance configuration file (`GITWEB_CONFIG`, defaults to
20 + 'gitweb_config.perl' in the same directory as the installed gitweb),
21 + or if it does not exists then system-wide configuration file
22 + (`GITWEB_CONFIG_SYSTEM`, defaults to '/etc/gitweb.conf').
23 +
24 +Values obtained in later configuration files override values obtained earlier
25 +in above sequence.
26 +
27 +You can read defaults in system-wide GITWEB_CONFIG_SYSTEM from GITWEB_CONFIG
28 +by adding
29 +
30 + read_config_file($GITWEB_CONFIG_SYSTEM);
31 +
32 +at very beginning of per-instance GITWEB_CONFIG file. In this case
33 +settings in said per-instance file will override settings from
34 +system-wide configuration file. Note that read_config_file checks
35 +itself that the $GITWEB_CONFIG_SYSTEM file exists.
36 +
37 The most notable thing that is not configurable at compile time are the
38 optional features, stored in the '%features' variable.
39
gitweb/gitweb.perl
+15 -3
@@ -661,13 +661,25 @@ sub read_config_file {
661 return;
662 }
663
664 -our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
664 +our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM, $GITWEB_CONFIG_COMMON);
665 sub evaluate_gitweb_config {
666 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
667 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
668 + our $GITWEB_CONFIG_COMMON = $ENV{'GITWEB_CONFIG_COMMON'} || "++GITWEB_CONFIG_COMMON++";
669
669 - # use first config file that exists
670 - read_config_file($GITWEB_CONFIG) or
670 + # Protect agains duplications of file names, to not read config twice.
671 + # Only one of $GITWEB_CONFIG and $GITWEB_CONFIG_SYSTEM is used, so
672 + # there possibility of duplication of filename there doesn't matter.
673 + $GITWEB_CONFIG = "" if ($GITWEB_CONFIG eq $GITWEB_CONFIG_COMMON);
674 + $GITWEB_CONFIG_SYSTEM = "" if ($GITWEB_CONFIG_SYSTEM eq $GITWEB_CONFIG_COMMON);
675 +
676 + # Common system-wide settings for convenience.
677 + # Those settings can be ovverriden by GITWEB_CONFIG or GITWEB_CONFIG_SYSTEM.
678 + read_config_file($GITWEB_CONFIG_COMMON);
679 +
680 + # Use first config file that exists. This means use the per-instance
681 + # GITWEB_CONFIG if exists, otherwise use GITWEB_SYSTEM_CONFIG.
682 + read_config_file($GITWEB_CONFIG) and return;
683 read_config_file($GITWEB_CONFIG_SYSTEM);
684 }
685