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

Re: FastCGI support in gitweb

From
Jakub Narebski <jnareb@gmail.com>
Date
Mar 1, 2008, 21:50 UTC
Message-ID
<m38x12jeqt.fsf@localhost.localdomain>
In-Reply-To
<1c3be50f0803011334u2629011cg85cb8728a244ea4e@mail.gmail.com>
"Juan Jose Comellas" <juanjo@comellas.org> writes:
Show 5 quoted lines
> I've seen that the current version of Gitweb (1.5.4.2) does not
> support FastCGI, and looking in Google I found that about a year ago a
> patch was sent to the list adding this functionality to it. I couldn't
> find any additional emails indicating why they weren't accepted. Is
> there any plan to add FastCGI support to Gitweb?

First, as far as I understand it, the patch made gitweb had to be used with FastCGI server. It has no comments in code, and if I remember correctly the commit message was also fairly nonexistent. It mixes FastCGI changes with site-wide changes. It wrapped the whole file in "until last request" loop instead of wrapping dispatch only.

Also I am not sure if gitweb doesn't rely on variables being correctly set which they are not in FastCGI mode.

But most important part: it was never resend (IIRC it was send when gitweb development was in separate repository)

I have attached the FastCGI patch and CC-ed the author.
From: root <root@vgasm.watts.utsl.gen.nz>
Date: Wed, 22 Mar 2006 00:53:07 +0000 (+1200)
Subject: add support for FastCGI
X-Git-Url: http://utsl.gen.nz/gitweb/?p=gitweb;a=commitdiff;h=56d7d436644ab296155a697552ea1345f2701620

add support for FastCGI ---

--- a/gitweb.cgi
+++ b/gitweb.cgi
@@ -5,10 +5,22 @@
 # (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
 # (C) 2005, Christian Gierke <ch@gierke.de>
 #
+# FastCGI adaptations:
+#   (c) 2006, Sam Vilain <sam.vilain@catalyst.net.nz>
+#
 # This program is licensed under the GPLv2
 
+# 
+
 use strict;
 use warnings;
+
+my $last_request = sub { 1 };
+my $pre_dispatch_hook = sub { };
+my $post_dispatch_hook = sub { };
+my $CGI = "CGI";
+my $pre_listen_hook = sub { };
+
 use CGI qw(:standard :escapeHTML -nosticky);
 use CGI::Util qw(unescape);
 use CGI::Carp qw(fatalsToBrowser);
@@ -16,7 +28,34 @@ use Encode;
 use Fcntl ':mode';
 binmode STDOUT, ':utf8';
 
-my $cgi = new CGI;
+    if (@ARGV) {
+	require Getopt::Long;
+	Getopt::Long::GetOptions
+	    ( "fastcgi|f" => sub {
+		  require CGI::Fast;
+		  $CGI = "CGI::Fast";
+		  my $c;
+		  # let each child service 100 requests
+		  $last_request = sub { ++$c > 100 }
+	      },
+              "nproc|n=i"   => sub {
+		  my ($arg, $val) = @_;
+		  require FCGI::ProcManager;
+                  my $pm = FCGI::ProcManager->new({
+			n_processes => $val,
+                  });
+	          $pre_listen_hook    = sub { $pm->pm_manage        };
+	          $pre_dispatch_hook  = sub { $pm->pm_pre_dispatch  };
+	          $post_dispatch_hook = sub { $pm->pm_post_dispatch };
+              },
+            );
+    }
+
+$pre_listen_hook->();
+do {
+my $cgi = $CGI->new or last;
+$pre_dispatch_hook->();
+
 my $version =		"264";
 my $my_url =		$cgi->url();
 my $my_uri =		$cgi->url(-absolute => 1);
@@ -24,7 +63,7 @@ my $rss_link =		"";
 
 # absolute fs-path which will be prepended to the project path
 #my $projectroot =	"/pub/scm";
-my $projectroot =	"/home/kay/public_html/pub/scm";
+my $projectroot =	"/var/lib/git";
 
 # location of the git-core binaries
 my $gitbin =		"/usr/bin";
@@ -40,7 +79,7 @@ my $home_text =		"indextext.html";
 
 # source of projects list
 #my $projects_list =	$projectroot;
-my $projects_list =	"index/index.aux";
+my $projects_list =	"/var/lib/git";
 
 # input validation and dispatch
 my $action = $cgi->param('a');
@@ -51,10 +90,10 @@ if (defined $action) {
 	}
 	if ($action eq "git-logo.png") {
 		git_logo();
-		exit;
+	goto out;
 	} elsif ($action eq "opml") {
 		git_opml();
-		exit;
+	goto out;
 	}
 }
 
@@ -85,7 +124,7 @@ if (defined $project) {
 	$ENV{'GIT_DIR'} = "$projectroot/$project";
 } else {
 	git_project_list();
-	exit;
+	goto out;
 }
 
 my $file_name = $cgi->param('f');
@@ -154,61 +193,62 @@ sub validate_input {
 
 if (!defined $action || $action eq "summary") {
 	git_summary();
-	exit;
+	goto out;
 } elsif ($action eq "heads") {
 	git_heads();
-	exit;
+	goto out;
 } elsif ($action eq "tags") {
 	git_tags();
-	exit;
+	goto out;
 } elsif ($action eq "blob") {
 	git_blob();
-	exit;
+	goto out;
 } elsif ($action eq "blob_plain") {
 	git_blob_plain();
-	exit;
+	goto out;
 } elsif ($action eq "tree") {
 	git_tree();
-	exit;
+	goto out;
 } elsif ($action eq "rss") {
 	git_rss();
-	exit;
+	goto out;
 } elsif ($action eq "commit") {
 	git_commit();
-	exit;
+	goto out;
 } elsif ($action eq "log") {
 	git_log();
-	exit;
+	goto out;
 } elsif ($action eq "blobdiff") {
 	git_blobdiff();
-	exit;
+	goto out;
 } elsif ($action eq "blobdiff_plain") {
 	git_blobdiff_plain();
-	exit;
+	goto out;
 } elsif ($action eq "commitdiff") {
 	git_commitdiff();
-	exit;
+	goto out;
 } elsif ($action eq "commitdiff_plain") {
 	git_commitdiff_plain();
-	exit;
+	goto out;
 } elsif ($action eq "history") {
 	git_history();
-	exit;
+	goto out;
 } elsif ($action eq "search") {
 	git_search();
-	exit;
+	goto out;
 } elsif ($action eq "shortlog") {
 	git_shortlog();
-	exit;
+	goto out;
 } elsif ($action eq "tag") {
 	git_tag();
-	exit;
+	goto out;
 } else {
 	undef $action;
 	die_error(undef, "Unknown action.");
-	exit;
 }
 
+$post_dispatch_hook->();
+
 # quote unsafe chars, but keep the slash, even when it's not
 # correct, but quoted slashes look too horrible in bookmarks
 sub esc_param {
@@ -2405,3 +2445,7 @@ sub git_shortlog {
 	print "</table\n>";
 	git_footer_html();
 }
+
+out:
+    exit;
+} until ( $last_request->() );
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Juan Jose ComellasNext: Sam Vilain
Message 2 of 8 in “FastCGI support in gitweb”
  1. Juan Jose ComellasMar 1, 2008
  2. Jakub NarebskiMar 1, 2008
  3. Sam VilainMar 3, 2008
  4. Jakub NarebskiMar 4, 2008
  5. John GoerzenMar 4, 2008
  6. Jakub NarebskiMar 4, 2008
  7. John GoerzenMar 4, 2008
  8. Jakub NarebskiMar 4, 2008

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.