aboutsummaryrefslogtreecommitdiff
path: root/gitweb
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-12-12 21:49:52 -0800
committerJunio C Hamano <gitster@pobox.com>2010-12-12 21:49:52 -0800
commite6234122b89cc21538d9d76cc3803a578b577e52 (patch)
treeea917ebf8bc27f9af157ac0fc79414868eef3dcf /gitweb
parent4a29c6a0db2a3ae7b8b94ad369f3b21c88482f95 (diff)
parentb3f52a9c3a5d02a6d1a3d05fe35deb90b70de510 (diff)
downloadgit-e6234122b89cc21538d9d76cc3803a578b577e52.tar.gz
git-e6234122b89cc21538d9d76cc3803a578b577e52.tar.xz
Merge branch 'jn/gitweb-per-request-config'
* jn/gitweb-per-request-config: gitweb: document $per_request_config better gitweb: selectable configurations that change with each request
Diffstat (limited to 'gitweb')
-rw-r--r--gitweb/README14
-rwxr-xr-xgitweb/gitweb.perl24
2 files changed, 35 insertions, 3 deletions
diff --git a/gitweb/README b/gitweb/README
index bf3664f2b..4a673933a 100644
--- a/gitweb/README
+++ b/gitweb/README
@@ -177,13 +177,15 @@ not include variables usually directly set during build):
* $my_url, $my_uri
Full URL and absolute URL of gitweb script;
in earlier versions of gitweb you might have need to set those
- variables, now there should be no need to do it.
+ variables, now there should be no need to do it. See
+ $per_request_config if you need to set them still.
* $base_url
Base URL for relative URLs in pages generated by gitweb,
(e.g. $logo, $favicon, @stylesheets if they are relative URLs),
needed and used only for URLs with nonempty PATH_INFO via
<base href="$base_url">. Usually gitweb sets its value correctly,
and there is no need to set this variable, e.g. to $my_uri or "/".
+ See $per_request_config if you need to set it anyway.
* $home_link
Target of the home link on top of all pages (the first part of view
"breadcrumbs"). By default set to absolute URI of a page ($my_uri).
@@ -246,6 +248,16 @@ not include variables usually directly set during build):
http://www.andre-simon.de due to assumptions about parameters and output).
Useful if highlight is not installed on your webserver's PATH.
[Default: highlight]
+ * $per_request_config
+ If set to code reference, it would be run once per each request. You can
+ set parts of configuration that change per session, e.g. by setting it to
+ sub { $ENV{GL_USER} = $cgi->remote_user || "gitweb"; }
+ Otherwise it is treated as boolean value: if true gitweb would process
+ config file once per request, if false it would process config file only
+ once. Note: $my_url, $my_uri, and $base_url are overwritten with
+ their default values before every request, so if you want to change
+ them, be sure to set this variable to true or a code reference effecting
+ the desired changes. The default is true.
Projects list file format
~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 75306ca96..62b2d21b8 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -611,6 +611,14 @@ sub filter_snapshot_fmts {
!$known_snapshot_formats{$_}{'disabled'}} @fmts;
}
+# If it is set to code reference, it is code that it is to be run once per
+# request, allowing updating configurations that change with each request,
+# while running other code in config file only once.
+#
+# Otherwise, if it is false then gitweb would process config file only once;
+# if it is true then gitweb config would be run for each request.
+our $per_request_config = 1;
+
our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
sub evaluate_gitweb_config {
our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
@@ -1081,12 +1089,22 @@ sub reset_timer {
our $number_of_git_cmds = 0;
}
+our $first_request = 1;
sub run_request {
reset_timer();
evaluate_uri();
- evaluate_gitweb_config();
- evaluate_git_version();
+ if ($first_request) {
+ evaluate_gitweb_config();
+ evaluate_git_version();
+ }
+ if ($per_request_config) {
+ if (ref($per_request_config) eq 'CODE') {
+ $per_request_config->();
+ } elsif (!$first_request) {
+ evaluate_gitweb_config();
+ }
+ }
check_loadavg();
# $projectroot and $projects_list might be set in gitweb config file
@@ -1140,6 +1158,7 @@ sub evaluate_argv {
sub run {
evaluate_argv();
+ $first_request = 1;
$pre_listen_hook->()
if $pre_listen_hook;
@@ -1152,6 +1171,7 @@ sub run {
$post_dispatch_hook->()
if $post_dispatch_hook;
+ $first_request = 0;
last REQUEST if ($is_last_request->());
}