From da4b2432cc6fe514dd72431de7be3ff2b4c86d7e Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Thu, 25 Nov 2010 19:43:59 +0100 Subject: gitweb: selectable configurations that change with each request Allow selecting whether configuration file should be (re)parsed on each request (the default, for backward compatibility with configurations that change per session, see commit 7f425db (gitweb: allow configurations that change with each request, 2010-07-30)), or whether should it be parsed only once (for performance speedup for persistent environments, though currently only FastCGI is able to make use of it, when flexibility is not important). You can also have configuration file parsed only once, but have parts of configuration (re)evaluated once per each request. This is done by introducing $per_request_config variable: if set to code reference, this code would be run once per request, while config file would be parsed only once. For example gitolite's contrib/gitweb/gitweb.conf fragment mentioned in 7f425db could be rewritten as our $per_request_config = sub { $ENV{GL_USER} = ($cgi && $cgi->remote_user) || "gitweb"; }; to make use of this feature. If $per_request_config is not a code reference, it is taken to be boolean variable, to choose between running config file for each request (flexibility), and running config file only once (performance in persistent environments). The default value for $per_request_config is 1 (true), which means that old configuration that require to change per session (like gitolite's) will keep working. While at it, make it so evaluate_git_version() is run only once. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/README | 7 +++++++ gitweb/gitweb.perl | 24 ++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'gitweb') diff --git a/gitweb/README b/gitweb/README index bf3664f2b..6646fdaed 100644 --- a/gitweb/README +++ b/gitweb/README @@ -246,6 +246,13 @@ 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. The default is true. Projects list file format ~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 679f2da3e..d8e4263ba 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -601,6 +601,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++"; @@ -1070,12 +1078,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 @@ -1129,6 +1147,7 @@ sub evaluate_argv { sub run { evaluate_argv(); + $first_request = 1; $pre_listen_hook->() if $pre_listen_hook; @@ -1141,6 +1160,7 @@ sub run { $post_dispatch_hook->() if $post_dispatch_hook; + $first_request = 0; last REQUEST if ($is_last_request->()); } -- cgit v1.2.1 From b3f52a9c3a5d02a6d1a3d05fe35deb90b70de510 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sun, 28 Nov 2010 18:19:08 -0600 Subject: gitweb: document $per_request_config better Global variables $my_url, $my_uri and $base_url have subtle interactions that need to be desribed, and can be influenced most cleanly by $per_request_config. Signed-off-by: Jonathan Nieder Acked-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/README | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'gitweb') diff --git a/gitweb/README b/gitweb/README index 6646fdaed..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 . 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). @@ -252,7 +254,10 @@ not include variables usually directly set during build): 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. The default is true. + 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 ~~~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.2.1