]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.cgi
v063
[Gitweb] / gitweb.cgi
index e80be7d9159b4deae9033e643c5ed039ae49601a00b64a903612eb87f818afaf..fc1ac0f56c718fa6323c026332936f118722d222340de4bc5c6144078d96a41a 100755 (executable)
@@ -14,18 +14,21 @@ use CGI::Carp qw(fatalsToBrowser);
 
 my $cgi = new CGI;
 
-my $version =          "056";
-my $projectroot =      "/home/kay/public_html/pub/scm";
+my $version =          "063";
+my $projectroot =      "/pub/scm";
 my $defaultprojects =  "linux/kernel/git";
-my $gitbin =           "/home/kay/bin/git";
-my $gittmp =           "/tmp";
+my $gitbin =           "/usr/bin";
+my $gittmp =           "/tmp/gitweb";
+my $giturl =           "/pub/software/scm/cogito";
 my $my_url =           $cgi->url();
 my $my_uri =           $cgi->url(-absolute => 1);
 
+mkdir($gittmp, 0700);
 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";
 
@@ -33,6 +36,9 @@ $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
 if (defined($project) && $project =~ /(^|\/)(|\.|\.\.)($|\/)/) {
        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\.\-]+$/) {
        die_error("", "Invalid action parameter.");
 }
@@ -44,8 +50,6 @@ if (defined($hash_parent) && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
 }
 if (defined($time_back) && !($time_back =~ m/^[0-9]+$/)) {
        die_error("", "Invalid time parameter.");
-} else {
-       $time_back = 1;
 }
 
 sub git_header_html {
@@ -77,6 +81,10 @@ sub git_header_html {
        }
        div.page_footer_text { float:left; color:#888888; font-size:10px;}
        div.page_body { margin:0px 25px; padding:8px; clear:both; border: solid #d9d8d1; border-width:0px 1px; }
+       div.title {
+               display:block; margin:0px 25px; padding:8px; clear:both;
+               font-weight:bold; background-color: #d9d8d1; color:#000000;
+       }
        a.log_title {
                display:block; margin:0px 25px; padding:8px; clear:both;
                font-weight:bold; background-color: #d9d8d1; text-decoration:none; color:#000000;
@@ -107,7 +115,7 @@ sub git_header_html {
 <body>
 EOF
        print "<div class=\"page_header\">\n" .
-             "<a href=\"http://kernel.org/pub/software/scm/git/\">" .
+             "<a href=\"$giturl\">" .
              "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
        if ($defaultprojects ne "") {
                print $cgi->a({-href => "$my_uri"}, "projects") . " / ";
@@ -186,6 +194,28 @@ sub git_commit {
        $co{'comment'} = \@comment;
        $co{'title'} = $comment[0];
        close $fd;
+
+       my $age = time - $co{'committer_epoch'};
+       $co{'age'} = $age;
+       if ($age > 60*60*24*365*2) {
+               $co{'age_string'} = (int $age/60/60/24/365);
+               $co{'age_string'} .= " years ago";
+       } elsif ($age > 60*60*24*365/12*2) {
+               $co{'age_string'} = int $age/60/60/24/365/12;
+               $co{'age_string'} .= " months ago";
+       } elsif ($age > 60*60*24*7*2) {
+               $co{'age_string'} = int $age/60/60/24/7;
+               $co{'age_string'} .= " weeks ago";
+       } elsif ($age > 60*60*24*2) {
+               $co{'age_string'} = int $age/60/60/24;
+               $co{'age_string'} .= " days ago";
+       } elsif ($age > 60*60*2) {
+               $co{'age_string'} = int $age/60/60;
+               $co{'age_string'} .= " hours ago";
+       } elsif ($age > 60*2) {
+               $co{'age_string'} = int $age/60;
+               $co{'age_string'} .= " minutes ago";
+       }
        return %co;
 }
 
@@ -339,12 +369,19 @@ 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_nav\">\n";
+       print "<br/><br/></div>\n";
+       print "<div class=\"title\">$hash</div>\n";
        print "<div class=\"page_body\"><pre><br/><br/>\n";
        open(my $fd, "-|", "$gitbin/cat-file blob $hash");
        my $nr;
@@ -364,6 +401,9 @@ if ($action eq "blob") {
        my (@entries) = map { chomp; $_ } <$fd>;
        close $fd;
        git_header_html();
+       print "<div class=\"page_nav\">\n";
+       print "<br/><br/></div>\n";
+       print "<div class=\"title\">$hash</div>\n";
        print "<div class=\"page_body\">\n";
        print "<br/><pre>\n";
        foreach my $line (@entries) {
@@ -374,9 +414,9 @@ if ($action eq "blob") {
                my $t_hash = $3;
                my $t_name = $4;
                if ($t_type eq "blob") {
-                       print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash"}, $t_name) . "\n";
+                       print mode_str($t_mode). " $t_name (" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash"}, "view") . ")\n";
                } elsif ($t_type eq "tree") {
-                       print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash"}, $t_name) . "\n";
+                       print mode_str($t_mode). " $t_name (" . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash"}, "view") . ")\n";
                }
        }
        print "</pre>\n";
@@ -384,7 +424,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") {
@@ -409,40 +449,19 @@ 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'};
-               my $age_string;
-               if ($age > 60*60*24*365*2) {
-                       $age_string = int $age/60/60/24/365;
-                       $age_string .= " years ago";
-               } elsif ($age > 60*60*24*365/12*2) {
-                       $age_string = int $age/60/60/24/365/12;
-                       $age_string .= " months ago";
-               } elsif ($age > 60*60*24*7*2) {
-                       $age_string = int $age/60/60/24/7;
-                       $age_string .= " weeks ago";
-               } elsif ($age > 60*60*24*2) {
-                       $age_string = int $age/60/60/24;
-                       $age_string .= " days ago";
-               } elsif ($age > 60*60*2) {
-                       $age_string = int $age/60/60;
-                       $age_string .= " hours ago";
-               } elsif ($age > 60*2) {
-                       $age_string = int $age/60;
-                       $age_string .= " minutes ago";
-               }
                if ($action eq "log") {
-               if ($time_back > 0 && $age > $time_back*60*60*24) {
+               if ($time_back > 0 && $co{'age'} > $time_back*60*60*24) {
                                if ($i == 0) {
-                                       print "<div class=\"page_body\"> Last change $age_string.<br/><br/></div>\n";
+                                       print "<div class=\"page_body\"> Last change " . $co{'age_string'} . ".<br/><br/></div>\n";
                                }
                                last;
                        }
                        print "<div><a href=\"$my_uri?p=$project;a=commit;h=$commit\" class=\"log_title\">\n" .
-                             "<span class=\"log_age\">" . $age_string . "</span>\n" . escapeHTML($co{'title'}) . "</a>\n" .
+                             "<span class=\"log_age\">" . $co{'age_string'} . "</span>\n" . escapeHTML($co{'title'}) . "</a>\n" .
                              "</div>\n";
                        print "<div class=\"log_head\">\n" .
                              "<div class=\"log_functions\">\n" .
@@ -466,7 +485,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) {
@@ -492,7 +511,7 @@ if ($action eq "blob") {
        git_header_html();
        print "<div class=\"page_nav\"> view\n" .
              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
-             $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diff") . "\n" .
+             $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . "\n" .
              "<br/><br/></div>\n";
        print "<a class=\"log_title\" href=\"$my_uri?p=$project;a=commitdiff;h=$hash\">$co{'title'}</a>\n";
        print "<div class=\"log_head\">\n";
@@ -537,14 +556,19 @@ if ($action eq "blob") {
                my $modestr = mode_str($1);
                if ($type eq "blob") {
                        if ($op eq "+") {
-                               print "$modestr " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$id"}, $file) . " (new)\n";
+                               print "$modestr $file" . "[new] " .
+                                     "(" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, "view") . ")\n";
                        } elsif ($op eq "-") {
-                               print "$modestr " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;hp=$id"}, $file) . " (removed)\n";
+                               print "$modestr $file" . "[removed] " .
+                                     "(" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, "view") . ")\n";
                        } elsif ($op eq "*") {
                                $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 $file " .
+                                     "(" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to"}, "view") . ")" .
+                                     "(" . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to;hp=$from"}, "diff") . ")" .
+                                     "(" . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . ")\n";
                        }
                }
        }
@@ -553,6 +577,9 @@ if ($action eq "blob") {
        git_footer_html();
 } elsif ($action eq "blobdiff") {
        git_header_html();
+       print "<div class=\"page_nav\">\n";
+       print "<br/><br/></div>\n";
+       print "<div class=\"title\">$hash vs $hash_parent</div>\n";
        print "<div class=\"page_body\"><br/><br/>\n" .
              "<pre>\n";
        git_diff_html($hash_parent, $hash, $hash_parent, $hash);
@@ -568,7 +595,7 @@ if ($action eq "blob") {
        git_header_html();
        print "<div class=\"page_nav\"> view\n" .
              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
-             $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diff") . "\n" .
+             $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . "\n" .
              "<br/><br/></div>\n";
        print $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "log_title"}, $co{'title'}) ."\n";
        print "<div class=\"page_body\">\n" .
@@ -595,6 +622,46 @@ if ($action eq "blob") {
        print "<br/></pre>\n";
        print "</div>";
        git_footer_html();
+} elsif ($action eq "history") {
+       if (!(defined($hash))) {
+               $hash = git_head($project);
+       }
+       open my $fd, "-|", "$gitbin/rev-list $hash";
+       my (@revlist) = map { chomp; $_ } <$fd>;
+       close $fd;
+
+       git_header_html();
+       print "<div class=\"page_nav\">\n";
+       print "<br/><br/></div>\n";
+       print "<div class=\"title\">$file_name</div>\n";
+       print "<div class=\"page_body\">\n" .
+             "<pre>\n";
+       foreach my $rev (@revlist) {
+               my %co = git_commit($rev);
+               my $parents  = $co{'parents'};
+               my $found = 0;
+               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) {
+                                       $found = 1;
+                                       last;
+                               }
+                       }
+               }
+               if ($found) {
+                       print $co{'age_string'} . "\t " . $co{'author_name'} . "  - " . $co{'title'} .
+                             " (" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$rev"}, "view") .")\n";
+               }
+       }
+       print "<br/></pre>\n";
+       print "</div>";
+       git_footer_html();
 } else {
        die_error("", "unknown action");
 }
This page took 0.323013 seconds and 4 git commands to generate.