]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.cgi
v057
[Gitweb] / gitweb.cgi
index b52e05328f497c3a329fa42bdd4e7699bcab66f588bfc5c16fd337ee5f140f1e..d426342bc3b7ea9eb1bec4f8e5f21419da7435d10d6949eb18cbb69e7cd992ef 100755 (executable)
@@ -14,7 +14,7 @@ use CGI::Carp qw(fatalsToBrowser);
 
 my $cgi = new CGI;
 
-my $version =          "055";
+my $version =          "057";
 my $projectroot =      "/home/kay/public_html/pub/scm";
 my $defaultprojects =  "linux/kernel/git";
 my $gitbin =           "/home/kay/bin/git";
@@ -26,26 +26,28 @@ my $project = $cgi->param('p');
 my $action = $cgi->param('a');
 my $hash = $cgi->param('h');
 my $hash_parent = $cgi->param('hp');
+my $file_name = $cgi->param('f');
 my $time_back = $cgi->param('t');
 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
 
 # validate input
 if (defined($project) && $project =~ /(^|\/)(|\.|\.\.)($|\/)/) {
-       error_page("403 Permission denied", "Invalid project parameter.");
+       die_error("", "Invalid project parameter.");
+}
+if (defined($file_name) && $file_name =~ /(^|\/)(|\.|\.\.)($|\/)/) {
+       die_error("", "Invalid file parameter.");
 }
 if (defined($action) && !$action =~ m/^[0-9a-zA-Z\.\-]+$/) {
-       error_page("403 Permission denied", "Invalid action parameter.");
+       die_error("", "Invalid action parameter.");
 }
 if (defined($hash) && !($hash =~ m/^[0-9a-fA-F]{40}$/)) {
-       error_page("403 Permission denied", "Invalid hash parameter.");
+       die_error("", "Invalid hash parameter.");
 }
 if (defined($hash_parent) && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
-       error_page("403 Permission denied", "Invalid parent hash parameter.");
+       die_error("", "Invalid parent hash parameter.");
 }
 if (defined($time_back) && !($time_back =~ m/^[0-9]+$/)) {
-       error_page("403 Permission denied", "Invalid time parameter.");
-} else {
-       $time_back = 1;
+       die_error("", "Invalid time parameter.");
 }
 
 sub git_header_html {
@@ -131,8 +133,8 @@ sub git_footer_html {
        print "</body>\n</html>";
 }
 
-sub error_page {
-       my $status = shift || "403 Permission denied";
+sub die_error {
+       my $status = shift || "403 Forbidden";
        my $error = shift || "Malformed query, file missing or permission denied"; 
        git_header_html($status);
        print "<div class=\"page_body\">\n" .
@@ -145,7 +147,7 @@ sub error_page {
 
 sub git_head {
        my $path = shift;
-       open my $fd, "$projectroot/$path/HEAD";
+       open(my $fd, "$projectroot/$path/HEAD") || die_error("", "Invalid project directory.");;
        my $head = <$fd>;
        close $fd;
        chomp $head;
@@ -179,6 +181,7 @@ sub git_commit {
                        $co{'committer_name'} =~ s/ <.*//;
                }
        }
+       if (!defined($co{'tree'})) { die_error("", "Invalid commit object."); }
        $co{'parents'} = \@parents;
        $co{'parent'} = $parents[0];
        my (@comment) = map { chomp; $_ } <$fd>;
@@ -203,7 +206,7 @@ sub git_diff_html {
        # create tmp from-file
        if ($from ne "") {
                $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
-               open my $fd2, "> $from_tmp";
+               open(my $fd2, "> $from_tmp");
                open my $fd, "-|", "$gitbin/cat-file blob $from";
                my @file = <$fd>;
                print $fd2 @file;
@@ -317,7 +320,7 @@ if ($action eq "git-logo.png") {
 
 # show list of default projects
 if ($project eq "") {
-       opendir(my $fd, "$projectroot/$defaultprojects");
+       opendir(my $fd, "$projectroot/$defaultprojects") || die_error("", "No projects found.");
        my (@users) = sort grep(!/^\./, readdir($fd));
        closedir($fd);
        git_header_html();
@@ -338,14 +341,18 @@ if ($project eq "") {
        exit;
 }
 
-if ($action eq "") {
+if (!defined($action)) {
        $action = "log";
 }
 
+if (!defined($time_back)) {
+       $time_back = 1;
+}
+
 if ($action eq "blob") {
        git_header_html();
        print "<div class=\"page_body\"><pre><br/><br/>\n";
-       open my $fd, "-|", "$gitbin/cat-file blob $hash";
+       open(my $fd, "-|", "$gitbin/cat-file blob $hash");
        my $nr;
        while (my $line = <$fd>) {
                $nr++;
@@ -383,7 +390,7 @@ if ($action eq "blob") {
        git_footer_html();
 } elsif ($action eq "log" || $action eq "rss") {
        open my $fd, "-|", "$gitbin/rev-list " . git_head($project);
-       my (@revtree) = map { chomp; $_ } <$fd>;
+       my (@revlist) = map { chomp; $_ } <$fd>;
        close $fd;
 
        if ($action eq "log") {
@@ -408,8 +415,8 @@ if ($action eq "blob") {
                      "<language>en</language>\n";
        }
 
-       for (my $i = 0; $i <= $#revtree; $i++) {
-               my $commit = $revtree[$i];
+       for (my $i = 0; $i <= $#revlist; $i++) {
+               my $commit = $revlist[$i];
                my %co = git_commit($commit);
                my %ad = date_str($co{'author_epoch'});
                my $age = time - $co{'committer_epoch'};
@@ -465,7 +472,7 @@ if ($action eq "blob") {
                        last if ($i >= 20);
                        print "<item>\n" .
                              "\t<title>" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'min'}) . " - " . escapeHTML($co{'title'}) . "</title>\n" .
-                             "\t<link> " . $my_url . "?p=$project;a==commit;h=$commit</link>\n" .
+                             "\t<link> " . $my_url . "?p=$project;a=commit;h=$commit</link>\n" .
                              "\t<description>";
                        my $comment = $co{'comment'};
                        foreach my $line (@$comment) {
@@ -543,7 +550,8 @@ if ($action eq "blob") {
                                $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
                                my $from = $1;
                                my $to = $2;
-                               print "$modestr " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to;hp=$from"}, $file) . "\n";
+                               print "$modestr " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to;hp=$from"}, $file) . " (" .
+                                     $cgi->a({-href => "$my_uri?p=$project;a=filerevision;h=$hash;f=$file"}, "history") . ")\n";
                        }
                }
        }
@@ -594,6 +602,35 @@ if ($action eq "blob") {
        print "<br/></pre>\n";
        print "</div>";
        git_footer_html();
+} elsif ($action eq "filerevision") {
+       open my $fd, "-|", "$gitbin/rev-list $hash";
+       my (@revlist) = map { chomp; $_ } <$fd>;
+       close $fd;
+
+       git_header_html();
+       print "<div class=\"page_body\">\n" .
+             "<pre>\n";
+       foreach my $rev (@revlist) {
+               my %co = git_commit($rev);
+               my $parents  = $co{'parents'};
+               foreach my $parent (@$parents) {
+                       open $fd, "-|", "$gitbin/diff-tree -r $parent $rev $file_name";
+                       my (@difftree) = map { chomp; $_ } <$fd>;
+                       close $fd;
+
+                       foreach my $line (@difftree) {
+                               $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
+                               my $file = $5;
+                               if ($file eq $file_name) {
+                                       print $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$rev"}, $rev) . " (" . $co{'title'} .")\n";
+                                       last;
+                               }
+                       }
+               }
+       }
+       print "<br/></pre>\n";
+       print "</div>";
+       git_footer_html();
 } else {
-       error_page("403 Forbidden", "unknown action");
+       die_error("", "unknown action");
 }
This page took 0.210583 seconds and 4 git commands to generate.