diff --git a/gitweb.pl b/gitweb.pl index dd487c3d88..dd5fbdc2a8 100755 --- a/gitweb.pl +++ b/gitweb.pl @@ -90,7 +90,7 @@ $project =~ s#\/\.+##g; $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/.git/objects"; -sub git_header { +sub git_header_html { print $cgi->header(-type => 'text/html; charset: utf-8'); print < @@ -144,11 +144,19 @@ EOF print "\n"; } -sub git_footer { +sub git_footer_html { print ""; print $cgi->end_html(); } +sub git_head { + open my $fd, "$projectroot/$project/.git/HEAD"; + my $head = <$fd>; + close $fd; + chomp $head; + return $head; +} + sub git_diff { my $old_name = shift || "/dev/null"; my $new_name = shift || "/dev/null"; @@ -217,7 +225,7 @@ if ($project eq "") { opendir(my $fd, "$projectroot/$defaultprojects"); my (@path) = grep(!/^\./, readdir($fd)); closedir($fd); - git_header(); + git_header_html(); print "
\n"; print "

\n"; foreach my $line (@path) { @@ -226,12 +234,12 @@ if ($project eq "") { } } print "

"; - git_footer(); + git_footer_html(); exit; } if ($action eq "blob") { - git_header(); + git_header_html(); print "

\n"; print "
\n";
 	open my $fd, "-|", "$gitbin/cat-file", "blob", $hash;
@@ -243,19 +251,15 @@ if ($action eq "blob") {
 	close $fd;
 	print "
\n"; print "
"; - git_footer(); + git_footer_html(); } elsif ($action eq "tree") { if ($hash eq "") { - open my $fd, "$projectroot/$project/.git/HEAD"; - my $head = <$fd>; - chomp $head; - close $fd; - $hash = $head; + $hash = git_head(); } open my $fd, "-|", "$gitbin/ls-tree", $hash; my (@entries) = map { chomp; $_ } <$fd>; close $fd; - git_header(); + git_header_html(); print "

\n"; print "
\n";
 	foreach my $line (@entries) {
@@ -272,18 +276,14 @@ if ($action eq "blob") {
 	}
 	print "
\n"; print "
"; - git_footer(); + git_footer_html(); } elsif ($action eq "log" || $action eq "rss") { - open my $fd, "$projectroot/$project/.git/HEAD"; - my $head = <$fd>; - chomp $head; - close $fd; - open $fd, "-|", "$gitbin/rev-tree", $head; + open my $fd, "-|", "$gitbin/rev-tree", git_head(); my (@revtree) = reverse sort map { chomp; $_ } <$fd>; close $fd; if ($action eq "log") { - git_header(); + git_header_html(); print "
\n"; print "view "; print $cgi->a({-href => "$myself/$project/log"}, "last day") . " | "; @@ -417,7 +417,7 @@ if ($action eq "blob") { } if ($action eq "log") { print "\n"; - git_footer(); + git_footer_html(); } elsif ($action eq "rss") { print ""; } @@ -439,7 +439,7 @@ if ($action eq "blob") { my (@difftree) = map { chomp; $_ } <$fd>; close $fd; - git_header(); + git_header_html(); print "
\n"; print "view " . $cgi->a({-href => "$myself/$project/commitdiff/$hash"}, "diff") . "


\n"; print "
$shortlog
\n"; @@ -468,15 +468,15 @@ if ($action eq "blob") { } print "\n"; print "
"; - git_footer(); + git_footer_html(); } elsif ($action eq "blobdiff") { - git_header(); + git_header_html(); print "

\n"; print "
\n";
 	git_diff($hash, $hash_parent, $hash, $hash_parent);
 	print "
\n"; print "
"; - git_footer(); + git_footer_html(); } elsif ($action eq "commitdiff") { my $parent = ""; open my $fd, "-|", "$gitbin/cat-file", "commit", $hash; @@ -495,7 +495,7 @@ if ($action eq "blob") { my (@difftree) = map { chomp; $_ } <$fd>; close $fd; - git_header(); + git_header_html(); print "
\n"; print "view " . $cgi->a({-href => "$myself/$project/commit/$hash"}, "commit") . "


\n"; print "
$shortlog
\n"; @@ -521,5 +521,5 @@ if ($action eq "blob") { } print "\n"; print "
"; - git_footer(); + git_footer_html(); }