Skip to content

Commit e623412

Browse files
committed
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
2 parents 4a29c6a + b3f52a9 commit e623412

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

gitweb/README

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,15 @@ not include variables usually directly set during build):
177177
* $my_url, $my_uri
178178
Full URL and absolute URL of gitweb script;
179179
in earlier versions of gitweb you might have need to set those
180-
variables, now there should be no need to do it.
180+
variables, now there should be no need to do it. See
181+
$per_request_config if you need to set them still.
181182
* $base_url
182183
Base URL for relative URLs in pages generated by gitweb,
183184
(e.g. $logo, $favicon, @stylesheets if they are relative URLs),
184185
needed and used only for URLs with nonempty PATH_INFO via
185186
<base href="$base_url">. Usually gitweb sets its value correctly,
186187
and there is no need to set this variable, e.g. to $my_uri or "/".
188+
See $per_request_config if you need to set it anyway.
187189
* $home_link
188190
Target of the home link on top of all pages (the first part of view
189191
"breadcrumbs"). By default set to absolute URI of a page ($my_uri).
@@ -246,6 +248,16 @@ not include variables usually directly set during build):
246248
http://www.andre-simon.de due to assumptions about parameters and output).
247249
Useful if highlight is not installed on your webserver's PATH.
248250
[Default: highlight]
251+
* $per_request_config
252+
If set to code reference, it would be run once per each request. You can
253+
set parts of configuration that change per session, e.g. by setting it to
254+
sub { $ENV{GL_USER} = $cgi->remote_user || "gitweb"; }
255+
Otherwise it is treated as boolean value: if true gitweb would process
256+
config file once per request, if false it would process config file only
257+
once. Note: $my_url, $my_uri, and $base_url are overwritten with
258+
their default values before every request, so if you want to change
259+
them, be sure to set this variable to true or a code reference effecting
260+
the desired changes. The default is true.
249261

250262
Projects list file format
251263
~~~~~~~~~~~~~~~~~~~~~~~~~

gitweb/gitweb.perl

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,14 @@ sub filter_snapshot_fmts {
611611
!$known_snapshot_formats{$_}{'disabled'}} @fmts;
612612
}
613613

614+
# If it is set to code reference, it is code that it is to be run once per
615+
# request, allowing updating configurations that change with each request,
616+
# while running other code in config file only once.
617+
#
618+
# Otherwise, if it is false then gitweb would process config file only once;
619+
# if it is true then gitweb config would be run for each request.
620+
our $per_request_config = 1;
621+
614622
our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM);
615623
sub evaluate_gitweb_config {
616624
our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
@@ -1081,12 +1089,22 @@ sub reset_timer {
10811089
our $number_of_git_cmds = 0;
10821090
}
10831091

1092+
our $first_request = 1;
10841093
sub run_request {
10851094
reset_timer();
10861095

10871096
evaluate_uri();
1088-
evaluate_gitweb_config();
1089-
evaluate_git_version();
1097+
if ($first_request) {
1098+
evaluate_gitweb_config();
1099+
evaluate_git_version();
1100+
}
1101+
if ($per_request_config) {
1102+
if (ref($per_request_config) eq 'CODE') {
1103+
$per_request_config->();
1104+
} elsif (!$first_request) {
1105+
evaluate_gitweb_config();
1106+
}
1107+
}
10901108
check_loadavg();
10911109

10921110
# $projectroot and $projects_list might be set in gitweb config file
@@ -1140,6 +1158,7 @@ sub evaluate_argv {
11401158
sub run {
11411159
evaluate_argv();
11421160

1161+
$first_request = 1;
11431162
$pre_listen_hook->()
11441163
if $pre_listen_hook;
11451164

@@ -1152,6 +1171,7 @@ sub run {
11521171

11531172
$post_dispatch_hook->()
11541173
if $post_dispatch_hook;
1174+
$first_request = 0;
11551175

11561176
last REQUEST if ($is_last_request->());
11571177
}

0 commit comments

Comments
 (0)