From 8ff76f4c3b4e72ac8259465bdf6e33f4da19170d Mon Sep 17 00:00:00 2001
From: Jakub Narebski <jnareb@gmail.com>
Date: Sun, 26 Sep 2010 13:34:56 +0200
Subject: [PATCH 1/4] gitweb: Move call to evaluate_git_version after
 evaluate_gitweb_config

Now evaluate_git_version() is inside run_request() to be called for each
request, instead of once per starting gitweb; this currently matters only
when using FastCGI interface (gitweb.fcgi).

This change was done because evaluate_git_version() uses $GIT variable,
which can be set / modified by gitweb config file, but the variable is
modified this way by gitweb config file used in gitweb tests.  Without
this change there is spurious extra output from t9500 test when tests are
run with '--debug' option.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 gitweb/gitweb.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index a85e2f6319..d521b4cf88 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1061,6 +1061,7 @@ sub run_request {
 
 	evaluate_uri();
 	evaluate_gitweb_config();
+	evaluate_git_version();
 	check_loadavg();
 
 	# $projectroot and $projects_list might be set in gitweb config file
@@ -1113,7 +1114,6 @@ sub evaluate_argv {
 
 sub run {
 	evaluate_argv();
-	evaluate_git_version();
 
 	$pre_listen_hook->()
 		if $pre_listen_hook;

From 929909375034eb609f855fe51b2ffc57123e6dd4 Mon Sep 17 00:00:00 2001
From: Jakub Narebski <jnareb@gmail.com>
Date: Sun, 26 Sep 2010 15:02:25 +0200
Subject: [PATCH 2/4] t/gitweb-lib.sh: Add support for GITWEB_TEST_INSTALLED

You can set the GITWEB_TEST_INSTALLED environment variable to the
gitwebdir (the directory where gitweb is installed / deployed to) of
an existing gitweb instalation, or to the pathname of installed gitweb
script, to test that installation.

This change is intended to make it possible to test that process of
installing gitweb and the modules it depends on works correctly (after
splitting gitweb).

If GITWEB_TEST_INSTALLED is used, print what script are we testing
to make it easy to spot that we test installed gitweb.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/gitweb-lib.sh | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh
index 8c490c8707..8b5b987f45 100644
--- a/t/gitweb-lib.sh
+++ b/t/gitweb-lib.sh
@@ -32,17 +32,34 @@ EOF
 	cat >.git/description <<EOF
 $0 test repository
 EOF
+
+	# You can set the GITWEB_TEST_INSTALLED environment variable to
+	# the gitwebdir (the directory where gitweb is installed / deployed to)
+	# of an existing gitweb instalation to test that installation,
+	# or simply to pathname of installed gitweb script.
+	if test -n "$GITWEB_TEST_INSTALLED" ; then
+		if test -d $GITWEB_TEST_INSTALLED; then
+			SCRIPT_NAME="$GITWEB_TEST_INSTALLED/gitweb.cgi"
+		else
+			SCRIPT_NAME="$GITWEB_TEST_INSTALLED"
+		fi
+		test -f "$SCRIPT_NAME" ||
+		error "Cannot find gitweb at $GITWEB_TEST_INSTALLED."
+		say "# Testing $SCRIPT_NAME"
+	else # normal case, use source version of gitweb
+		SCRIPT_NAME="$GIT_BUILD_DIR/gitweb/gitweb.perl"
+	fi
+	export SCRIPT_NAME
 }
 
 gitweb_run () {
 	GATEWAY_INTERFACE='CGI/1.1'
 	HTTP_ACCEPT='*/*'
 	REQUEST_METHOD='GET'
-	SCRIPT_NAME="$GIT_BUILD_DIR/gitweb/gitweb.perl"
 	QUERY_STRING=""$1""
 	PATH_INFO=""$2""
 	export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \
-		SCRIPT_NAME QUERY_STRING PATH_INFO
+		QUERY_STRING PATH_INFO
 
 	GITWEB_CONFIG=$(pwd)/gitweb_config.perl
 	export GITWEB_CONFIG

From 958a8467216ca607ca6a24059d5c641347927333 Mon Sep 17 00:00:00 2001
From: Jakub Narebski <jnareb@gmail.com>
Date: Sun, 26 Sep 2010 15:02:26 +0200
Subject: [PATCH 3/4] gitweb/Makefile: Add 'test' and 'test-installed' targets

The 'test-installed' target in gitweb/Makefile tests installed gitweb,
using the same destination directory that 'install' target uses.

The 'test' target is just a convenience wrapper invoking 'gitweb-test'
target of t/Makefile.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 gitweb/Makefile | 11 ++++++++++-
 t/Makefile      |  4 ++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gitweb/Makefile b/gitweb/Makefile
index 2fb7c2d77b..f2180741fc 100644
--- a/gitweb/Makefile
+++ b/gitweb/Makefile
@@ -143,6 +143,15 @@ gitweb.cgi: gitweb.perl GITWEB-BUILD-OPTIONS
 	chmod +x $@+ && \
 	mv $@+ $@
 
+### Testing rules
+
+test:
+	$(MAKE) -C ../t gitweb-test
+
+test-installed:
+	GITWEB_TEST_INSTALLED='$(DESTDIR_SQ)$(gitwebdir_SQ)' \
+		$(MAKE) -C ../t gitweb-test
+
 ### Installation rules
 
 install: all
@@ -156,5 +165,5 @@ install: all
 clean:
 	$(RM) gitweb.cgi static/gitweb.min.js static/gitweb.min.css GITWEB-BUILD-OPTIONS
 
-.PHONY: all clean install .FORCE-GIT-VERSION-FILE FORCE
+.PHONY: all clean install test test-installed .FORCE-GIT-VERSION-FILE FORCE
 
diff --git a/t/Makefile b/t/Makefile
index c7baefb7ea..7aa409ab64 100644
--- a/t/Makefile
+++ b/t/Makefile
@@ -17,6 +17,7 @@ SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 
 T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
 TSVN = $(wildcard t91[0-9][0-9]-*.sh)
+TGITWEB = $(wildcard t95[0-9][0-9]-*.sh)
 
 all: pre-clean
 	$(MAKE) aggregate-results-and-cleanup
@@ -46,6 +47,9 @@ full-svn-test:
 	$(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=1 LC_ALL=C
 	$(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=0 LC_ALL=en_US.UTF-8
 
+gitweb-test:
+	$(MAKE) $(TGITWEB)
+
 valgrind:
 	GIT_TEST_OPTS=--valgrind $(MAKE)
 

From 9b93aeb29cea16880926bc150ac31cfb31475a44 Mon Sep 17 00:00:00 2001
From: Jakub Narebski <jnareb@gmail.com>
Date: Sun, 26 Sep 2010 15:02:24 +0200
Subject: [PATCH 4/4] gitweb/Makefile: Include gitweb/config.mak

Allow for gitweb-specific Makefile config to reside in config.mak file
in the 'gitweb/' subdirectory.  This means that gitweb-specific
build-time configuration variable can reside in gitweb-specific
gitweb/config.mak

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 gitweb/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gitweb/Makefile b/gitweb/Makefile
index f2180741fc..df908a18eb 100644
--- a/gitweb/Makefile
+++ b/gitweb/Makefile
@@ -39,6 +39,7 @@ GITWEB_SITE_FOOTER =
 # include user config
 -include ../config.mak.autogen
 -include ../config.mak
+-include config.mak
 
 # determine version
 ../GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE