When gitweb is running as PSGI app, it must itself take care of serving static files: stylesheets, script, images that are required to render gitweb output. This commit makes gitweb (in PSGI mode) use installed static files from $(gitwebstaticdir) if such directory exists. Before this commit gitweb served static files from 'static/' directory relative to position of gitweb script itself (to __DIR__). This allows to use gitweb in PSGI mode even if static files are installed to non-standard place. Note that mechanism of serving is slightly different: the one with __DIR__ uses Plack::Middleware::Static, while the installdir one uses URLMap-ped set of Plack::App::File. Signed-off-by: Jakub Narebski <jnareb@xxxxxxxxx> --- This probably would have to be reworked, so that using Plack::Middleware::Static is preferred over set of Plack::App::File (which I think is slightly slower). gitweb/Makefile | 7 +++++-- gitweb/gitweb.perl | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/gitweb/Makefile b/gitweb/Makefile index 549e7dc..6f673ff 100644 --- a/gitweb/Makefile +++ b/gitweb/Makefile @@ -13,6 +13,8 @@ all:: prefix ?= $(HOME) bindir ?= $(prefix)/bin gitwebdir ?= /var/www/cgi-bin +gitwebstaticdir ?= $(gitwebdir)/static +gitweblibdir ?= $(gitwebdir)/lib RM ?= rm -f INSTALL ?= install @@ -58,8 +60,8 @@ PERL_PATH ?= /usr/bin/perl # Shell quote; bindir_SQ = $(subst ','\'',$(bindir))#' gitwebdir_SQ = $(subst ','\'',$(gitwebdir))#' -gitwebstaticdir_SQ = $(subst ','\'',$(gitwebdir)/static)#' -gitweblibdir_SQ = $(subst ','\'',$(gitwebdir)/lib)#' +gitwebstaticdir_SQ = $(subst ','\'',$(gitwebstaticdir))#' +gitweblibdir_SQ = $(subst ','\'',$(gitweblibdir))#' SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))#' PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))#' DESTDIR_SQ = $(subst ','\'',$(DESTDIR))#' @@ -130,6 +132,7 @@ GITWEB_JSLIB_FILES += static/js/blame_incremental.js GITWEB_REPLACE = \ -e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \ -e 's|++GIT_BINDIR++|$(bindir)|g' \ + -e 's|++GITWEBSTATICDIR++|$(gitwebstaticdir)|g' \ -e 's|++GITWEB_CONFIG++|$(GITWEB_CONFIG)|g' \ -e 's|++GITWEB_CONFIG_SYSTEM++|$(GITWEB_CONFIG_SYSTEM)|g' \ -e 's|++GITWEB_CONFIG_COMMON++|$(GITWEB_CONFIG_COMMON)|g' \ diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 6bd7b08..f871090 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1271,9 +1271,10 @@ sub to_psgi_app { } sub build_psgi_app { - require Plack::Builder; - require Plack::Middleware::Static; - + # gitweb currently doesn't work with $SIG{CHLD} set to 'IGNORE', + # because it uses 'close $fd or die...' on piped filehandle $fh + # (which causes the parent process to wait for child to finish). + # this middleware is enabled only if $SIG{CHLD} is 'IGNORE'. my $sigchld_mw = sub { my $app = shift; sub { @@ -1288,14 +1289,35 @@ sub build_psgi_app { # note: Plack::Builder DSL (builder, enable_if, enable) won't work # with "require Plack::Builder" outside BEGIN section. my $app = to_psgi_app(); - $app = Plack::Middleware::Static->wrap($app, - path => qr{(?:^|/)static/.*\.(?:js|css|png)$}, - root => __DIR__, - encoding => 'utf-8', # encoding for 'text/plain' files - ); $app = $sigchld_mw->($app) if (defined $SIG{'CHLD'} && $SIG{'CHLD'} eq 'IGNORE'); + if (-d "++GITWEBSTATICDIR++") { + require Plack::App::URLMap; + require Plack::App::File; + + my $urlmap = Plack::App::URLMap->new(); + $urlmap->map("/" => $app); + foreach my $static_url (@stylesheets, $stylesheet, $logo, $favicon, $javascript) { + next if (!defined $static_url || $static_url eq ""); + + (my $static_file = $static_url) =~ s!^.*/!!; # basename + $static_file = "++GITWEBSTATICDIR++/$static_file"; + $urlmap->map($static_url => Plack::App::File->new(file => $static_file)); + } + $app = $urlmap->to_app(); + + } else { + require Plack::Middleware::Static; + + $app = Plack::Middleware::Static->wrap($app, + path => qr{(?:^|/)static/.*\.(?:js|css|png)$}, + root => __DIR__, + encoding => 'utf-8', # encoding for 'text/plain' files + ); + + } + return $app; } -- 1.7.9 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html