From ed12b3a3baebf1423cf8395d5ed3953dabb70d1e Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Mon, 14 Jun 2010 13:49:29 +0200 Subject: [PATCH] gitweb: Add startup delay to activity indicator for cache This adds support for [optional] startup delay to git_generating_data_html() subroutine, which is used to provide "Generating..." page as activity indicator when waiting for page to be generated if caching. If the data (page contents) gets generated within $generating_options{'staryp_delay'} seconds, the "Generating..." page won't get displayed. This feature was created in response to complaint by Petr 'Pasky' Baudis' about "Generating..." feature. Signed-off-by: Jakub Narebski --- gitweb/gitweb.perl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 8d7540e6be..313114c358 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -326,6 +326,9 @@ our %cache_options = ( # (which means that $cache_options{'generating_info'} is set to coderef); # override them with $GITWEB_CONFIG as necessary. our %generating_options = ( + # The delay before displaying "Generating..." page, in seconds. It is + # intended for "Generating..." page to be shown only when really needed. + 'startup_delay' => 1, # The time between generating new piece of output to prevent from # redirection before data is ready, i.e. time between printing each # dot in activity indicator / progress info, in seconds. @@ -3368,6 +3371,23 @@ sub git_generating_data_html { # return; #} + # Initial delay + if ($generating_options{'startup_delay'} > 0) { + eval { + local $SIG{ALRM} = sub { die "alarm clock restart\n" }; # NB: \n required + alarm $generating_options{'startup_delay'}; + flock($lock_fh, LOCK_SH); # blocking readers lock + alarm 0; + }; + if ($@) { + # propagate unexpected errors + die $@ if $@ !~ /alarm clock restart/; + } else { + # we got response within 'startup_delay' timeout + return; + } + } + # Stop capturing response, just in case (we should be not generating response) # capture_stop(); # or gitweb could use 'print $STDOUT' in place of 'print STDOUT' -- 2.11.4.GIT