From b65910fec21db070ac40521e4b375fca76d27c90 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 29 Sep 2008 15:07:42 +0200 Subject: [PATCH 1/4] gitweb: remove PATH_INFO from $my_url and $my_uri This patch fixes PATH_INFO handling by removing the relevant part from $my_url and $my_uri, thus making it unnecessary to specify them by hand in the gitweb configuration. Signed-off-by: Giuseppe Bilotta Acked-by: Jakub Narebski Acked-by: Petr Baudis Signed-off-by: Shawn O. Pearce --- gitweb/gitweb.perl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 269f1125d9..f1ab5725c0 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -27,6 +27,13 @@ our $version = "++GIT_VERSION++"; our $my_url = $cgi->url(); our $my_uri = $cgi->url(-absolute => 1); +# if we're called with PATH_INFO, we have to strip that +# from the URL to find our real URL +if (my $path_info = $ENV{"PATH_INFO"}) { + $my_url =~ s,\Q$path_info\E$,,; + $my_uri =~ s,\Q$path_info\E$,,; +} + # core git executable to use # this can just be "git" if your webserver has a sensible PATH our $GIT = "++GIT_BINDIR++/git"; From 6e2dfb1631b3c40574e6f940498f3889607c3ef8 Mon Sep 17 00:00:00 2001 From: David Soria Parra Date: Thu, 2 Oct 2008 02:08:47 +0200 Subject: [PATCH 2/4] Solaris: Use OLD_ICONV to avoid compile warnings Solaris systems use the old styled iconv(3) call and therefore the OLD_ICONV variable should be set. Otherwise we get annoying compile warnings. Signed-off-by: David Soria Parra Acked-by: Jeff King Signed-off-by: Shawn O. Pearce --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 8d81095765..7fad9f7ff6 100644 --- a/Makefile +++ b/Makefile @@ -637,6 +637,7 @@ ifeq ($(uname_S),SunOS) NO_MEMMEM = YesPlease NO_HSTRERROR = YesPlease NO_MKDTEMP = YesPlease + OLD_ICONV = UnfortunatelyYes ifeq ($(uname_R),5.8) NEEDS_LIBICONV = YesPlease NO_UNSETENV = YesPlease From 2d7a3532c78bace2f3631ab0e594f713dcab9916 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Thu, 2 Oct 2008 16:50:04 +0200 Subject: [PATCH 3/4] gitweb: Fix two 'uninitialized value' warnings in git_tree() If we did try to access nonexistent directory or file, which means that git_get_hash_by_path() returns `undef`, uninitialized $hash variable was passed to 'open' call. Now we fail early with "404 Not Found - No such tree" error. (If we try to access something which does not resolve to tree-ish, for example a file / 'blob' object, the error will be caught later, as "404 Not Found - Reading tree failed" error). If we tried to use 'tree' action without $file_name ('f' parameter) set, which means either tree given by hash or a top tree (and we currently cannot distinguish between those two cases), we cannot print path breadcrumbs with git_print_page_path(). Fix this by moving call to git_print_page_path() inside conditional. Signed-off-by: Jakub Narebski Acked-by: Petr Baudis Signed-off-by: Shawn O. Pearce --- gitweb/gitweb.perl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index f1ab5725c0..eae5084c66 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -4421,6 +4421,7 @@ sub git_tree { $hash = $hash_base; } } + die_error(404, "No such tree") unless defined($hash); $/ = "\0"; open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash or die_error(500, "Open git-ls-tree failed"); @@ -4461,8 +4462,8 @@ sub git_tree { if ($basedir ne '' && substr($basedir, -1) ne '/') { $basedir .= '/'; } + git_print_page_path($file_name, 'tree', $hash_base); } - git_print_page_path($file_name, 'tree', $hash_base); print "
\n"; print "\n"; my $alternate = 1; From 9a1fd653b13b6cc136bfa5b9563f629b2af1a6c8 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Thu, 2 Oct 2008 16:52:20 +0200 Subject: [PATCH 4/4] gitweb: Add path_info tests to t/t9500-gitweb-standalone-no-errors.sh Note that those tests only check that there are no errors nor warnings from Perl; they do not check for example if gitweb doesn't use ARRAY(0x8e3cc20) instead of correct value in links, etc. Signed-off-by: Jakub Narebski Acked-by: Petr Baudis Signed-off-by: Shawn O. Pearce --- t/t9500-gitweb-standalone-no-errors.sh | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh index ae7082be1d..d8f278ffee 100755 --- a/t/t9500-gitweb-standalone-no-errors.sh +++ b/t/t9500-gitweb-standalone-no-errors.sh @@ -502,6 +502,55 @@ test_expect_success \ gitweb_run "p=.git;a=history;f=deleted_file"' test_debug 'cat gitweb.log' +# ---------------------------------------------------------------------- +# path_info links +test_expect_success \ + 'path_info: project' \ + 'gitweb_run "" "/.git"' +test_debug 'cat gitweb.log' + +test_expect_success \ + 'path_info: project/branch' \ + 'gitweb_run "" "/.git/b"' +test_debug 'cat gitweb.log' + +test_expect_success \ + 'path_info: project/branch:file' \ + 'gitweb_run "" "/.git/master:file"' +test_debug 'cat gitweb.log' + +test_expect_success \ + 'path_info: project/branch:dir/' \ + 'gitweb_run "" "/.git/master:foo/"' +test_debug 'cat gitweb.log' + +test_expect_success \ + 'path_info: project/branch:file (non-existent)' \ + 'gitweb_run "" "/.git/master:non-existent"' +test_debug 'cat gitweb.log' + +test_expect_success \ + 'path_info: project/branch:dir/ (non-existent)' \ + 'gitweb_run "" "/.git/master:non-existent/"' +test_debug 'cat gitweb.log' + + +test_expect_success \ + 'path_info: project/branch:/file' \ + 'gitweb_run "" "/.git/master:/file"' +test_debug 'cat gitweb.log' + +test_expect_success \ + 'path_info: project/:/file (implicit HEAD)' \ + 'gitweb_run "" "/.git/:/file"' +test_debug 'cat gitweb.log' + +test_expect_success \ + 'path_info: project/:/ (implicit HEAD, top tree)' \ + 'gitweb_run "" "/.git/:/"' +test_debug 'cat gitweb.log' + + # ---------------------------------------------------------------------- # feed generation