Skip to content

Commit

Permalink
Merge branch 'jn/gitweb-system-config'
Browse files Browse the repository at this point in the history
* jn/gitweb-system-config:
  gitweb: Introduce common system-wide settings for convenience
  • Loading branch information
Junio C Hamano committed Aug 8, 2011
2 parents 75745bc + 131d6af commit 86bd7f9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
13 changes: 12 additions & 1 deletion gitweb/INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Gitweb config file
See also "Runtime gitweb configuration" section in README file
for gitweb (in gitweb/README).

- You can configure gitweb further using the gitweb configuration file;
- You can configure gitweb further using the per-instance gitweb configuration file;
by default this is a file named gitweb_config.perl in the same place as
gitweb.cgi script. You can control the default place for the config file
using the GITWEB_CONFIG build configuration variable, and you can set it
Expand All @@ -241,6 +241,17 @@ for gitweb (in gitweb/README).
GITWEB_CONFIG_SYSTEM build configuration variable, and override it
through the GITWEB_CONFIG_SYSTEM environment variable.

Note that if per-instance configuration file exists, then system-wide
configuration is _not used at all_. This is quite untypical and suprising
behavior. On the other hand changing current behavior would break backwards
compatibility and can lead to unexpected changes in gitweb behavior.
Therefore gitweb also looks for common system-wide configuration file,
normally /etc/gitweb-common.conf (set during build time using build time
configuration variable GITWEB_CONFIG_COMMON, set it at runtime using
environment variable with the same name). Settings from per-instance or
system-wide configuration file override those from common system-wide
configuration file.

- The gitweb config file is a fragment of perl code. You can set variables
using "our $variable = value"; text from "#" character until the end
of a line is ignored. See perlsyn(1) for details.
Expand Down
2 changes: 2 additions & 0 deletions gitweb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ INSTALL ?= install
# default configuration for gitweb
GITWEB_CONFIG = gitweb_config.perl
GITWEB_CONFIG_SYSTEM = /etc/gitweb.conf
GITWEB_CONFIG_COMMON = /etc/gitweb-common.conf
GITWEB_HOME_LINK_STR = projects
GITWEB_SITENAME =
GITWEB_PROJECTROOT = /pub/git
Expand Down Expand Up @@ -129,6 +130,7 @@ GITWEB_REPLACE = \
-e 's|++GIT_BINDIR++|$(bindir)|g' \
-e 's|++GITWEB_CONFIG++|$(GITWEB_CONFIG)|g' \
-e 's|++GITWEB_CONFIG_SYSTEM++|$(GITWEB_CONFIG_SYSTEM)|g' \
-e 's|++GITWEB_CONFIG_COMMON++|$(GITWEB_CONFIG_COMMON)|g' \
-e 's|++GITWEB_HOME_LINK_STR++|$(GITWEB_HOME_LINK_STR)|g' \
-e 's|++GITWEB_SITENAME++|$(GITWEB_SITENAME)|g' \
-e 's|++GITWEB_PROJECTROOT++|$(GITWEB_PROJECTROOT)|g' \
Expand Down
27 changes: 24 additions & 3 deletions gitweb/README
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,30 @@ From the git version 1.4.0 gitweb is bundled with git.
Runtime gitweb configuration
----------------------------

You can adjust gitweb behaviour using the file specified in `GITWEB_CONFIG`
(defaults to 'gitweb_config.perl' in the same directory as the CGI), and
as a fallback `GITWEB_CONFIG_SYSTEM` (defaults to /etc/gitweb.conf).
Gitweb obtains configuration data from the following sources in the
following order:

1. built-in values (some set during build stage),
2. common system-wide configuration file (`GITWEB_CONFIG_COMMON`,
defaults to '/etc/gitweb-common.conf'),
3. either per-instance configuration file (`GITWEB_CONFIG`, defaults to
'gitweb_config.perl' in the same directory as the installed gitweb),
or if it does not exists then system-wide configuration file
(`GITWEB_CONFIG_SYSTEM`, defaults to '/etc/gitweb.conf').

Values obtained in later configuration files override values obtained earlier
in above sequence.

You can read defaults in system-wide GITWEB_CONFIG_SYSTEM from GITWEB_CONFIG
by adding

read_config_file($GITWEB_CONFIG_SYSTEM);

at very beginning of per-instance GITWEB_CONFIG file. In this case
settings in said per-instance file will override settings from
system-wide configuration file. Note that read_config_file checks
itself that the $GITWEB_CONFIG_SYSTEM file exists.

The most notable thing that is not configurable at compile time are the
optional features, stored in the '%features' variable.

Expand Down
18 changes: 15 additions & 3 deletions gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -665,13 +665,25 @@ sub read_config_file {
return;
}

our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM, $GITWEB_CONFIG_COMMON);
sub evaluate_gitweb_config {
our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
our $GITWEB_CONFIG_COMMON = $ENV{'GITWEB_CONFIG_COMMON'} || "++GITWEB_CONFIG_COMMON++";

# use first config file that exists
read_config_file($GITWEB_CONFIG) or
# Protect agains duplications of file names, to not read config twice.
# Only one of $GITWEB_CONFIG and $GITWEB_CONFIG_SYSTEM is used, so
# there possibility of duplication of filename there doesn't matter.
$GITWEB_CONFIG = "" if ($GITWEB_CONFIG eq $GITWEB_CONFIG_COMMON);
$GITWEB_CONFIG_SYSTEM = "" if ($GITWEB_CONFIG_SYSTEM eq $GITWEB_CONFIG_COMMON);

# Common system-wide settings for convenience.
# Those settings can be ovverriden by GITWEB_CONFIG or GITWEB_CONFIG_SYSTEM.
read_config_file($GITWEB_CONFIG_COMMON);

# Use first config file that exists. This means use the per-instance
# GITWEB_CONFIG if exists, otherwise use GITWEB_SYSTEM_CONFIG.
read_config_file($GITWEB_CONFIG) and return;
read_config_file($GITWEB_CONFIG_SYSTEM);
}

Expand Down

0 comments on commit 86bd7f9

Please sign in to comment.