]> asedeno.scripts.mit.edu Git - git.git/blobdiff - gitweb/gitweb.perl
Merge branch 'maint'
[git.git] / gitweb / gitweb.perl
index 9e5e0bf3ee6a86df6329da145f7f597e7abf491f..8b0276727146d6fbd9123b6bbe8b5f0631f823b1 100755 (executable)
@@ -232,6 +232,29 @@ our %avatar_size = (
 # Leave it undefined (or set to 'undef') to turn off load checking.
 our $maxload = 300;
 
+# configuration for 'highlight' (http://www.andre-simon.de/)
+# match by basename
+our %highlight_basename = (
+       #'Program' => 'py',
+       #'Library' => 'py',
+       'SConstruct' => 'py', # SCons equivalent of Makefile
+       'Makefile' => 'make',
+);
+# match by extension
+our %highlight_ext = (
+       # main extensions, defining name of syntax;
+       # see files in /usr/share/highlight/langDefs/ directory
+       map { $_ => $_ }
+               qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
+       # alternate extensions, see /etc/highlight/filetypes.conf
+       'h' => 'c',
+       map { $_ => 'cpp' } qw(cxx c++ cc),
+       map { $_ => 'php' } qw(php3 php4),
+       map { $_ => 'pl'  } qw(perl pm), # perhaps also 'cgi'
+       'mak' => 'make',
+       map { $_ => 'xml' } qw(xhtml html htm),
+);
+
 # You define site-wide feature defaults here; override them with
 # $GITWEB_CONFIG as necessary.
 our %feature = (
@@ -1027,18 +1050,18 @@ sub dispatch {
        $actions{$action}->();
 }
 
-sub run_request {
+sub reset_timer {
        our $t0 = [Time::HiRes::gettimeofday()]
                if defined $t0;
+       our $number_of_git_cmds = 0;
+}
+
+sub run_request {
+       reset_timer();
 
        evaluate_uri();
-       evaluate_gitweb_config();
-       evaluate_git_version();
        check_loadavg();
 
-       # $projectroot and $projects_list might be set in gitweb config file
-       $projects_list ||= $projectroot;
-
        evaluate_query_params();
        evaluate_path_info();
        evaluate_and_validate_params();
@@ -1086,6 +1109,11 @@ sub evaluate_argv {
 
 sub run {
        evaluate_argv();
+       evaluate_gitweb_config();
+       evaluate_git_version();
+
+       # $projectroot and $projects_list might be set in gitweb config file
+       $projects_list ||= $projectroot;
 
        $pre_listen_hook->()
                if $pre_listen_hook;
@@ -1097,7 +1125,7 @@ sub run {
 
                run_request();
 
-               $pre_dispatch_hook->()
+               $post_dispatch_hook->()
                        if $post_dispatch_hook;
 
                last REQUEST if ($is_last_request->());
@@ -1109,6 +1137,15 @@ sub run {
 
 run();
 
+if (defined caller) {
+       # wrapped in a subroutine processing requests,
+       # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
+       return;
+} else {
+       # pure CGI script, serving single request
+       exit;
+}
+
 ## ======================================================================
 ## action links
 
@@ -1313,8 +1350,7 @@ sub esc_param {
 sub esc_url {
        my $str = shift;
        return undef unless defined $str;
-       $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
-       $str =~ s/\+/%2B/g;
+       $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&= ]+)/CGI::escape($1)/eg;
        $str =~ s/ /\+/g;
        return $str;
 }
@@ -3303,30 +3339,6 @@ sub blob_contenttype {
 sub guess_file_syntax {
        my ($highlight, $mimetype, $file_name) = @_;
        return undef unless ($highlight && defined $file_name);
-
-       # configuration for 'highlight' (http://www.andre-simon.de/)
-       # match by basename
-       my %highlight_basename = (
-               #'Program' => 'py',
-               #'Library' => 'py',
-               'SConstruct' => 'py', # SCons equivalent of Makefile
-               'Makefile' => 'make',
-       );
-       # match by extension
-       my %highlight_ext = (
-               # main extensions, defining name of syntax;
-               # see files in /usr/share/highlight/langDefs/ directory
-               map { $_ => $_ }
-                       qw(py c cpp rb java css php sh pl js tex bib xml awk bat ini spec tcl),
-               # alternate extensions, see /etc/highlight/filetypes.conf
-               'h' => 'c',
-               map { $_ => 'cpp' } qw(cxx c++ cc),
-               map { $_ => 'php' } qw(php3 php4),
-               map { $_ => 'pl'  } qw(perl pm), # perhaps also 'cgi'
-               'mak' => 'make',
-               map { $_ => 'xml' } qw(xhtml html htm),
-       );
-
        my $basename = basename($file_name, '.in');
        return $highlight_basename{$basename}
                if exists $highlight_basename{$basename};