Skip to content

Commit

Permalink
gitweb: fallback to system-wide config file if default config does no…
Browse files Browse the repository at this point in the history
…t 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 <[email protected]>
Acked-by: Jakub Narebski <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
Gerrit Pape authored and gitster committed Mar 27, 2008
1 parent 1768905 commit 17a8b25
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ ETC_GITCONFIG = $(sysconfdir)/gitconfig

# default configuration for gitweb
GITWEB_CONFIG = gitweb_config.perl
GITWEB_CONFIG_SYSTEM = /etc/gitweb.conf
GITWEB_HOME_LINK_STR = projects
GITWEB_SITENAME =
GITWEB_PROJECTROOT = /pub/git
Expand Down
6 changes: 5 additions & 1 deletion gitweb/INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ for gitweb (in gitweb/README).
by default it is file named gitweb_config.perl in the same place as
gitweb.cgi script. You can control default place for config file
using GITWEB_CONFIG build configuration variable, and you can set it
using GITWEB_CONFIG environmental variable.
using GITWEB_CONFIG environmental variable. If this file does not
exist, gitweb looks for a system-wide configuration file, normally
/etc/gitweb.conf. You can change the default using the
GITWEB_CONFIG_SYSTEM build configuration variable, and override it
through GITWEB_CONFIG_SYSTEM environmental variable.

- Gitweb config file is [fragment] of perl code. You can set variables
using "our $variable = value"; text from "#" character until the end
Expand Down
9 changes: 8 additions & 1 deletion gitweb/README
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,20 @@ You can specify the following configuration variables when building GIT:
is set when gitweb.cgi is executed, then the file specified in the
environment variable will be loaded instead of the file specified
when gitweb.cgi was created. [Default: gitweb_config.perl]
* GITWEB_CONFIG_SYSTEM
This Perl file will be loaded using 'do' as a fallback if GITWEB_CONFIG
does not exist. If the environment variable GITWEB_CONFIG_SYSTEM is set
when gitweb.cgi is executed, then the file specified in the environment
variable will be loaded instead of the file specified when gitweb.cgi was
created. [Default: /etc/gitweb.conf]


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).
(defaults to 'gitweb_config.perl' in the same directory as the CGI), and
as a fallback `GITWEB_CONFIG_SYSTEM` (defaults to /etc/gitweb.conf).
The most notable thing that is not configurable at compile time are the
optional features, stored in the '%features' variable.

Expand Down
7 changes: 6 additions & 1 deletion gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,12 @@ sub filter_snapshot_fmts {
}

our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
if (-e $GITWEB_CONFIG) {
do $GITWEB_CONFIG;
} else {
our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
do $GITWEB_CONFIG_SYSTEM if -e $GITWEB_CONFIG_SYSTEM;
}

# version of the core git binary
our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
Expand Down

0 comments on commit 17a8b25

Please sign in to comment.