Skip to content

Commit da4b243

Browse files
jnarebgitster
authored andcommitted
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 <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7d43de9 commit da4b243

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

gitweb/README

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ not include variables usually directly set during build):
246246
http://www.andre-simon.de due to assumptions about parameters and output).
247247
Useful if highlight is not installed on your webserver's PATH.
248248
[Default: highlight]
249+
* $per_request_config
250+
If set to code reference, it would be run once per each request. You can
251+
set parts of configuration that change per session, e.g. by setting it to
252+
sub { $ENV{GL_USER} = $cgi->remote_user || "gitweb"; }
253+
Otherwise it is treated as boolean value: if true gitweb would process
254+
config file once per request, if false it would process config file only
255+
once. The default is true.
249256

250257
Projects list file format
251258
~~~~~~~~~~~~~~~~~~~~~~~~~

gitweb/gitweb.perl

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,14 @@ sub filter_snapshot_fmts {
601601
!$known_snapshot_formats{$_}{'disabled'}} @fmts;
602602
}
603603

604+
# If it is set to code reference, it is code that it is to be run once per
605+
# request, allowing updating configurations that change with each request,
606+
# while running other code in config file only once.
607+
#
608+
# Otherwise, if it is false then gitweb would process config file only once;
609+
# if it is true then gitweb config would be run for each request.
610+
our $per_request_config = 1;
611+
604612
our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
605613
sub evaluate_gitweb_config {
606614
our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
@@ -1070,12 +1078,22 @@ sub reset_timer {
10701078
our $number_of_git_cmds = 0;
10711079
}
10721080

1081+
our $first_request = 1;
10731082
sub run_request {
10741083
reset_timer();
10751084

10761085
evaluate_uri();
1077-
evaluate_gitweb_config();
1078-
evaluate_git_version();
1086+
if ($first_request) {
1087+
evaluate_gitweb_config();
1088+
evaluate_git_version();
1089+
}
1090+
if ($per_request_config) {
1091+
if (ref($per_request_config) eq 'CODE') {
1092+
$per_request_config->();
1093+
} elsif (!$first_request) {
1094+
evaluate_gitweb_config();
1095+
}
1096+
}
10791097
check_loadavg();
10801098

10811099
# $projectroot and $projects_list might be set in gitweb config file
@@ -1129,6 +1147,7 @@ sub evaluate_argv {
11291147
sub run {
11301148
evaluate_argv();
11311149

1150+
$first_request = 1;
11321151
$pre_listen_hook->()
11331152
if $pre_listen_hook;
11341153

@@ -1141,6 +1160,7 @@ sub run {
11411160

11421161
$post_dispatch_hook->()
11431162
if $post_dispatch_hook;
1163+
$first_request = 0;
11441164

11451165
last REQUEST if ($is_last_request->());
11461166
}

0 commit comments

Comments
 (0)