X-Git-Url: https://git.ladys.computer/Gitweb/blobdiff_plain/4f48f215852d2a9af970a2f5af1aba929dd4322d28355a4c42d5ca970cb33cf4..0a1a83a8cb26c96d778fa6b91109744a274d41650f10fa4bc7e97eef57e588f9:/gitweb.cgi diff --git a/gitweb.cgi b/gitweb.cgi index a54fa4c..d097f6b 100755 --- a/gitweb.cgi +++ b/gitweb.cgi @@ -5,7 +5,7 @@ # (C) 2005, Kay Sievers # (C) 2005, Christian Gierke # -# This program is licensed under the GPL v2, or a later version +# This program is licensed under the GPLv2 use strict; use warnings; @@ -15,7 +15,7 @@ use CGI::Carp qw(fatalsToBrowser); use Fcntl ':mode'; my $cgi = new CGI; -my $version = "246"; +my $version = "248"; my $my_url = $cgi->url(); my $my_uri = $cgi->url(-absolute => 1); my $rss_link = ""; @@ -152,8 +152,8 @@ sub validate_input { if (!defined $action || $action eq "summary") { git_summary(); exit; -} elsif ($action eq "branches") { - git_branches(); +} elsif ($action eq "heads") { + git_heads(); exit; } elsif ($action eq "tags") { git_tags(); @@ -208,6 +208,7 @@ if (!defined $action || $action eq "summary") { sub git_header_html { my $status = shift || "200 OK"; + my $expires = shift; my $title = "git"; if (defined $project) { @@ -216,7 +217,7 @@ sub git_header_html { $title .= "/$action"; } } - print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status); + print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires); print < @@ -1067,15 +1068,15 @@ sub git_summary { print ""; } - my $branchlist = git_read_refs("refs/heads"); - if (defined @$branchlist) { + my $headlist = git_read_refs("refs/heads"); + if (defined @$headlist) { print "
\n" . - $cgi->a({-href => "$my_uri?p=$project;a=branches", -class => "title"}, "branches") . + $cgi->a({-href => "$my_uri?p=$project;a=heads", -class => "title"}, "heads") . "
\n"; my $i = 16; print "\n"; my $alternate = 0; - foreach my $entry (@$branchlist) { + foreach my $entry (@$headlist) { my %tag = %$entry; if ($alternate) { print "\n"; @@ -1095,7 +1096,7 @@ sub git_summary { "\n" . ""; } else { - print "\n" . + print "\n" . ""; last; } @@ -1203,7 +1204,7 @@ sub git_tags { git_footer_html(); } -sub git_branches { +sub git_heads { my $head = git_read_hash("$project/HEAD"); git_header_html(); print "
\n" . @@ -1281,7 +1282,6 @@ sub git_blob { $hash = git_get_hash_by_path($base, $file_name, "blob"); } open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed."); - my $base = $file_name || ""; git_header_html(); if (defined $hash_base && (my %co = git_read_commit($hash_base))) { print "
\n" . @@ -1291,9 +1291,13 @@ sub git_blob { " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") . " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") . " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") . "
\n"; - print $cgi->a({-href => "$my_uri?p=$project;a=blob_plain;h=$hash"}, "plain") . "
\n" . - "
\n"; - print "
" . + if (defined $file_name) { + print $cgi->a({-href => "$my_uri?p=$project;a=blob_plain;h=$hash;f=$file_name"}, "plain") . "
\n"; + } else { + print $cgi->a({-href => "$my_uri?p=$project;a=blob_plain;h=$hash"}, "plain") . "
\n"; + } + print "
\n". + "
" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "
\n"; } else { @@ -1323,7 +1327,11 @@ sub git_blob { } sub git_blob_plain { - print $cgi->header(-type => "text/plain", -charset => 'utf-8'); + my $save_as = "$hash.txt"; + if (defined $file_name) { + $save_as = $file_name; + } + print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"$save_as\""); open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return; undef $/; print <$fd>; @@ -1613,7 +1621,13 @@ sub git_commit { open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed."); @difftree = map { chomp; $_ } <$fd>; close $fd or die_error(undef, "Reading diff-tree failed."); - git_header_html(); + + # non-textual hash id's can be cached + my $expires; + if ($hash =~ m/^[0-9a-fA-F]{40}$/) { + $expires = "+1d"; + } + git_header_html(undef, $expires); print "
\n" . $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") . " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") . @@ -1845,7 +1859,12 @@ sub git_commitdiff { my (@difftree) = map { chomp; $_ } <$fd>; close $fd or die_error(undef, "Reading diff-tree failed."); - git_header_html(); + # non-textual hash id's can be cached + my $expires; + if ($hash =~ m/^[0-9a-fA-F]{40}$/) { + $expires = "+1d"; + } + git_header_html(undef, $expires); print "
\n" . $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") . " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") . @@ -1945,7 +1964,7 @@ sub git_commitdiff_plain { } close $fd; - print $cgi->header(-type => "text/plain", -charset => 'utf-8'); + print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\""); my %co = git_read_commit($hash); my %ad = date_str($co{'author_epoch'}, $co{'author_tz'}); my $comment = $co{'comment'};
" . $cgi->a({-href => "$my_uri?p=$project;a=branches"}, "...") . "" . $cgi->a({-href => "$my_uri?p=$project;a=heads"}, "...") . "