git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH 5/5] git-instaweb: Use new PSGI interface mode of gitweb

From
Jakub Narebski <jnareb@gmail.com>
Date
Mar 3, 2012, 17:57 UTC
Message-ID
<1330797423-22926-6-git-send-email-jnareb@gmail.com>
In-Reply-To
<1330797423-22926-1-git-send-email-jnareb@gmail.com>

Now that gitweb supports PSGI interface itself, use it instead of Plack::App::WrapCGI.

Note that gitweb as PSGI serves static files and ensures correct handling of SIGCHLD, but the wrapper is still needed for logging, mimetype handling (probably unnecessary), and selecting host and port. It is now named gitweb-wrapper.psgi and not gitweb.psgi, though.

The advantage of previous version is that it uses persistent mode (similar to FastCGI); important if $per_request_config is false or coderef.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Should make git-instaweb plackup mode better.
 git-instaweb.sh |   33 +++++++--------------------------
 1 files changed, 7 insertions(+), 26 deletions(-)
diff --git a/git-instaweb.sh b/git-instaweb.sh
index 01a1b05..58e142a 100755
--- a/git-instaweb.sh
+++ b/git-instaweb.sh
@@ -53,8 +53,8 @@ resolve_full_httpd () {
 		fi
 		;;
 	*plackup*)
-		# server is started by running via generated gitweb.psgi in $fqgitdir/gitweb
-		full_httpd="$fqgitdir/gitweb/gitweb.psgi"
+		# server is started by running via generated gitweb-wrapper.psgi in $fqgitdir/gitweb
+		full_httpd="$fqgitdir/gitweb/gitweb-wrapper.psgi"
 		httpd_only="${httpd%% *}" # cut on first space
 		return
 		;;
@@ -434,7 +434,7 @@ EOF
 plackup_conf () {
 	# generate a standalone 'plackup' server script in $fqgitdir/gitweb
 	# with embedded configuration; it does not use "$conf" file
-	cat > "$fqgitdir/gitweb/gitweb.psgi" <<EOF
+	cat > "$fqgitdir/gitweb/gitweb-wrapper.psgi" <<EOF
 #!$PERL
 
 # gitweb - simple web interface to track changes in git repositories
@@ -445,8 +445,7 @@ use strict;
 use IO::Handle;
 use Plack::MIME;
 use Plack::Builder;
-use Plack::App::WrapCGI;
-use CGI::Emulate::PSGI 0.07; # minimum version required to work with gitweb
+use Plack::Util;
 
 # mimetype mapping (from lighttpd_conf)
 Plack::MIME->add_type(
@@ -538,25 +537,7 @@ my \$app = builder {
 			\$app->(\$env);
 		}
 	};
-	# 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).
-	enable_if { \$SIG{'CHLD'} eq 'IGNORE' } sub {
-		my \$app = shift;
-		sub {
-			my \$env = shift;
-			local \$SIG{'CHLD'} = 'DEFAULT';
-			local \$SIG{'CLD'}  = 'DEFAULT';
-			\$app->(\$env);
-		}
-	};
-	# serve static files, i.e. stylesheet, images, script
-	enable 'Static',
-		path => sub { m!\.(js|css|png)\$! && s!^/gitweb/!! },
-		root => "$root/",
-		encoding => 'utf-8'; # encoding for 'text/plain' files
-	# convert CGI application to PSGI app
-	Plack::App::WrapCGI->new(script => "$root/gitweb.cgi")->to_app;
+	Plack::Util::load_psgi("$root/gitweb.cgi");
 };
 
 # make it runnable as standalone app,
@@ -574,8 +555,8 @@ if (caller) {
 __END__
 EOF
 
-	chmod a+x "$fqgitdir/gitweb/gitweb.psgi"
-	# configuration is embedded in server script file, gitweb.psgi
+	chmod a+x "$fqgitdir/gitweb/gitweb-wrapper.psgi"
+	# configuration is embedded in server script file, gitweb-wrapper.psgi
 	rm -f "$conf"
 }
 
-- 
1.7.9
Previous: Jakub NarebskiNext: Jakub Narebski
Message 6 of 7 in “gitweb: Proof of concept of PSGI interface”
  1. 0/5 gitweb: Proof of concept of PSGI interfaceJakub Narebski, Mar 3, 2012
  2. 1/5 gitweb: Jump do DONE_REQUEST not DONE_GITWEB on errorJakub Narebski, Mar 3, 2012
  3. 2/5 gitweb: Prepare for splitting gitwebJakub Narebski, Mar 3, 2012
  4. 3/5 gitweb: Enable running gitweb as PSGI app, via CGI::Emulate::PSGIJakub Narebski, Mar 3, 2012
  5. 4/5 gitweb.psgi: Allow passing arguments to Plack::RunnerJakub Narebski, Mar 3, 2012
  6. 5/5 git-instaweb: Use new PSGI interface mode of gitwebJakub Narebski, Mar 3, 2012
  7. 6/5 gitweb.psgi: Use installed static files, if they are availableJakub Narebski, Mar 8, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.