v025
authorKay Sievers <kay.sievers@suse.de>
Sun, 7 Aug 2005 18:05:15 +0000 (20:05 +0200)
committerKay Sievers <kay.sievers@suse.de>
Sun, 7 Aug 2005 18:05:15 +0000 (20:05 +0200)
gitweb.pl

index 284a158..a2ec30d 100755 (executable)
--- a/gitweb.pl
+++ b/gitweb.pl
@@ -2,7 +2,7 @@
 
 # gitweb.pl - simple web interface to track changes in git repositories
 #
-# Version 021
+# Version 025
 #
 # (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
 # (C) 2005, Christian Gierke <ch@gierke.de>
@@ -14,57 +14,59 @@ use warnings;
 use CGI qw(:standard :escapeHTML);
 use CGI::Carp qw(fatalsToBrowser);
 
+my $cgi = new CGI;
+
 my $projectroot =      "/home/kay/public_html";
 my $defaultprojects =  ".";
 my $gitbin =           "/home/kay/bin/git";
 my $gittmp =           "/tmp";
+my $my_url =           $cgi->url();
+my $my_uri =           $cgi->url(-absolute => 1);
+my $my_url_parm =      $cgi->url(-path => 1);
+$my_url_parm =~ s/.*$my_uri//;
 
-my $cgi = new CGI;
 my $project = "";
 my $action = "";
 my $hash = "";
 my $hash_parent = "";
-my $view_back;
-my $myself = $cgi->url(-absolute => 1);
-my $url_parm = $cgi->url(-path => 1);
-$url_parm =~ s/.*$myself//;
+my $view_back = 1;
 
 # get values from url
-if ($url_parm =~ m#/(.+)/commit/([0-9a-fA-F]+)$#) {
+if ($my_url_parm =~ m#/(.+)/commit/([0-9a-fA-F]+)$#) {
        $project = $1;
        $action = "commit";
        $hash = $2;
-} elsif ($url_parm =~ m#/(.+)/commitdiff/([0-9a-fA-F]+)$#) {
+} elsif ($my_url_parm =~ m#/(.+)/commitdiff/([0-9a-fA-F]+)$#) {
        $project = $1;
        $action = "commitdiff";
        $hash = $2;
-} elsif ($url_parm =~ m#/(.+)/blobdiff/([0-9a-fA-F]+)/([0-9a-fA-F]+)$#) {
+} elsif ($my_url_parm =~ m#/(.+)/blobdiff/([0-9a-fA-F]+)/([0-9a-fA-F]+)$#) {
        $project = $1;
        $action = "blobdiff";
        $hash = $2;
        $hash_parent = $3;
-} elsif ($url_parm =~ m#/(.+)/blob/([0-9a-fA-F]+)$#) {
+} elsif ($my_url_parm =~ m#/(.+)/blob/([0-9a-fA-F]+)$#) {
        $project = $1;
        $action = "blob";
        $hash = $2;
-} elsif ($url_parm =~ m#/(.+)/tree/([0-9a-fA-F]+)$#) {
+} elsif ($my_url_parm =~ m#/(.+)/tree/([0-9a-fA-F]+)$#) {
        $project = $1;
        $action = "tree";
        $hash = $2;
-} elsif ($url_parm =~ m#/(.+)/log/([0-9]+)$#) {
+} elsif ($my_url_parm =~ m#/(.+)/log/([0-9]+)$#) {
        $project = $1;
        $action = "log";
        $view_back = $2;
-} elsif ($url_parm =~ m#/(.+)/log$#) {
+} elsif ($my_url_parm =~ m#/(.+)/log$#) {
        $project = $1;
        $action = "log";
        $view_back = 1;
-} elsif ($url_parm =~ m#/(.+)/rss$#) {
+} elsif ($my_url_parm =~ m#/(.+)/rss$#) {
        $project = $1;
        $action = "rss";
        $view_back = 1;
-} elsif ($url_parm =~ m#/git-logo.png$#) {
-       print $cgi->header(-type => 'image/png');
+} elsif ($my_url_parm =~ m#/git-logo.png$#) {
+       print $cgi->header(-type => 'image/png', -expires => '+1d');
        print   "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
                "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
                "\055\000\000\000\030\120\114\124\105\377\377\377\140\140\135\260".
@@ -79,7 +81,7 @@ if ($url_parm =~ m#/(.+)/commit/([0-9a-fA-F]+)$#) {
                "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305".
                "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202";
        exit;
-} elsif ($url_parm =~ m#/(.+)$#) {
+} elsif ($my_url_parm =~ m#/(.+)$#) {
        $project = $1;
        $action = "log";
        $view_back = 1;
@@ -91,13 +93,13 @@ $project =~ s#\/\.+##g;
 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/.git/objects";
 
 sub git_header_html {
-       print $cgi->header(-type => 'text/html; charset: utf-8');
+       print $cgi->header(-type => 'text/html', -charset => 'utf-8');
 print <<EOF;
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html>
 <head>
        <title>git - $project $action</title>
-  <link rel="alternate" title="$project log" href="$myself/$project/rss" type="application/rss+xml">
+       <link rel="alternate" title="$project log" href="$my_uri/$project/rss" type="application/rss+xml"/>
        <style type="text/css">
                body { font-family: sans-serif; font-size: 12px; margin:25px; }
                div.body { border-width:1px; border-style:solid; border-color:#D9D8D1; }
@@ -110,6 +112,9 @@ print <<EOF;
                div.head2 a:hover { color:#880000; }
                div.head2 a:active { color:#880000; }
                div.title { padding:8px; background-color: #D9D8D1; font-weight:bold; }
+               div.title a { color:#000000; text-decoration:none; }
+               div.title a:hover { color:#880000; text-decoration:underline; }
+               div.title a:visited { color:#000000; }
                table { padding:0px; margin:0px; width:100%; }
                tr { vertical-align:top; }
                td { padding:8px; margin:0px; font-family: sans-serif; font-size: 12px; }
@@ -131,12 +136,13 @@ print <<EOF;
 EOF
        print "<div class=\"body\">\n";
        print "<div class=\"head1\">";
-       print "<a href=\"http://kernel.org/pub/software/scm/git/\"><img src=\"$myself/git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
+       print "<a href=\"http://kernel.org/pub/software/scm/git/\">" .
+             "<img src=\"$my_uri/git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
        if ($defaultprojects ne "") {
-               print $cgi->a({-href => "$myself"}, "projects") . " / ";
+               print $cgi->a({-href => "$my_uri"}, "projects") . " / ";
        }
        if ($project ne "") {
-               print $cgi->a({-href => "$myself/$project/log"}, $project);
+               print $cgi->a({-href => "$my_uri/$project/log"}, $project);
        }
        if ($action ne "") {
                print " / $action";
@@ -181,6 +187,7 @@ sub git_commit {
                }
        }
        $co{'parents'} = \@parents;
+       $co{'parent'} = $parents[0];
        my (@comment) = map { chomp; $_ } <$fd>;
        $co{'comment'} = \@comment;
        $co{'title'} = $comment[0];
@@ -228,13 +235,13 @@ sub git_diff {
        open my $fd, "-|", "/usr/bin/diff", "-L", $old_label, "-L", $new_label, "-u", "-p", $tmp_old, $tmp_new;
        print "<span style =\"color: #000099;\">===== ";
        if ($old ne "") {
-               print $cgi->a({-href => "$myself/$project/blob/$old"}, $old);
+               print $cgi->a({-href => "$my_uri/$project/blob/$old"}, $old);
        } else {
                print $old_name;
        }
        print " vs ";
        if ($new ne "") {
-               print $cgi->a({-href => "$myself/$project/blob/$new"}, $new);
+               print $cgi->a({-href => "$my_uri/$project/blob/$new"}, $new);
        } else {
                print $new_name;
        }
@@ -261,7 +268,7 @@ if ($project eq "") {
        print "<br/><br/>\n";
        foreach my $line (@path) {
                if (-e "$projectroot/$defaultprojects/$line/.git/HEAD") {
-                       print $cgi->a({-href => "$myself/$defaultprojects/$line/log"}, $line) . "<br/>\n";
+                       print $cgi->a({-href => "$my_uri/$defaultprojects/$line/log"}, $line) . "<br/>\n";
                }
        }
        print "</div><br/>";
@@ -300,9 +307,9 @@ if ($action eq "blob") {
                my $t_hash = $3;
                my $t_name = $4;
                if ($t_type eq "blob") {
-                       print "BLOB\t" . $cgi->a({-href => "$myself/$project/blob/$3"}, $4) . "\n";
+                       print "BLOB\t" . $cgi->a({-href => "$my_uri/$project/blob/$3"}, $4) . "\n";
                } elsif ($t_type eq "tree") {
-                       print "TREE\t" . $cgi->a({-href => "$myself/$project/tree/$3"}, $4) . "\n";
+                       print "TREE\t" . $cgi->a({-href => "$my_uri/$project/tree/$3"}, $4) . "\n";
                }
        }
        print "</pre>\n";
@@ -317,28 +324,27 @@ if ($action eq "blob") {
                git_header_html();
                print "<div class=\"head2\">\n";
                print "view  ";
-               print $cgi->a({-href => "$myself/$project/log"}, "last day") . " | ";
-               print $cgi->a({-href => "$myself/$project/log/7"}, "week") . " | ";
-               print $cgi->a({-href => "$myself/$project/log/31"}, "month") . " | ";
-               print $cgi->a({-href => "$myself/$project/log/365"}, "year") . " | ";
-               print $cgi->a({-href => "$myself/$project/log/0"}, "all") . "<br/>\n";
+               print $cgi->a({-href => "$my_uri/$project/log"}, "last day") . " | ";
+               print $cgi->a({-href => "$my_uri/$project/log/7"}, "week") . " | ";
+               print $cgi->a({-href => "$my_uri/$project/log/31"}, "month") . " | ";
+               print $cgi->a({-href => "$my_uri/$project/log/365"}, "year") . " | ";
+               print $cgi->a({-href => "$my_uri/$project/log/0"}, "all") . "<br/>\n";
                print "<br/><br/>\n";
                print "</div>\n";
                print "<table cellspacing=\"0\" class=\"log\">\n";
        } elsif ($action eq "rss") {
-               print $cgi->header(-type => 'text/xml; charset: utf-8');
+               print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
                print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
                      "<rss version=\"0.91\">\n";
                print "<channel>\n";
                print "<title>$project</title>\n".
-                     "<link> " . $cgi->url() . "/$project/log</link>\n".
+                     "<link> " . $my_url . "/$project/log</link>\n".
                      "<description>$project log</description>\n".
                      "<language>en</language>\n";
        }
 
        for (my $i = 0; $i <= $#revtree; $i++) {
                my $rev = $revtree[$i];
-               #foreach my $rev (@revtree) {
                # '1114106118 755e3010ee10dadf42a8a80770e1b115fb038d9b:1 2af17b4854036a1c2ec6c101d93c8dd1ed80d24e:1'
                last if !($rev =~ m/^([0-9]+) ([0-9a-fA-F]+).* ([0-9a-fA-F]+)/);
                my $time = $1;
@@ -378,23 +384,16 @@ if ($action eq "blob") {
                        }
                        print "<tr>\n";
                        print "<td class=\"head1\">" . $age_string . "</td>\n";
-                       print "<td class=\"head1\">" . $cgi->a({-href => "$myself/$project/commit/$commit"}, $co{'title'}) . "</td>";
+                       print "<td class=\"head1\">" . $cgi->a({-href => "$my_uri/$project/commit/$commit"}, $co{'title'}) . "</td>";
                        print "</tr>\n";
                        print "<tr>\n";
                        print "<td class=\"head3\">";
-                       print $cgi->a({-href => "$myself/$project/commitdiff/$commit"}, "view diff") . "<br/>\n";
-                       print $cgi->a({-href => "$myself/$project/commit/$commit"}, "view commit") . "<br/>\n";
-                       print $cgi->a({-href => "$myself/$project/tree/$co{'tree'}"}, "view tree") . "<br/>\n";
+                       print $cgi->a({-href => "$my_uri/$project/commit/$commit"}, "view commit") . "<br/>\n";
+                       print $cgi->a({-href => "$my_uri/$project/commitdiff/$commit"}, "view diff") . "<br/>\n";
                        print "</td>\n";
                        print "<td class=\"head2\">\n";
                        print "author &nbsp; &nbsp;" . escapeHTML($co{'author'}) . " [" . gmtime($co{'author_time'}) . " " . $co{'author_timezone'} . "]<br/>\n";
                        print "committer " . escapeHTML($co{'committer'}) . " [" . gmtime($co{'committer_time'}) . " " . $co{'committer_timezone'} . "]<br/>\n";
-                       print "commit &nbsp; &nbsp;$commit<br/>\n";
-                       print "tree &nbsp; &nbsp; &nbsp;$co{'tree'}<br/>\n";
-                       my $parents  = $co{'parents'};
-                       foreach my $par (@$parents) {
-                               print "parent &nbsp; &nbsp;$par<br/>\n";
-                       }
                        print "</td>";
                        print "</tr>\n";
                        print "<tr>\n";
@@ -412,9 +411,19 @@ if ($action eq "blob") {
                        print "</td>";
                        print "</tr>\n";
                } elsif ($action eq "rss") {
-                       last if ($i >= 12);
-                       print "<item>\n\t<title>$age_string: " . escapeHTML($co{'title'}) . "</title>\n";
-                       print "\t<link> " . $cgi->url() . "/$project/commit/$commit</link>\n";
+                       last if ($i >= 20);
+                       my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime($co{'author_time'});
+                       my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
+                       print "<item>\n\t<title>";
+                       printf("%s %02d, %02d:%02d - ", $months[$mon], $mday, $hour, $min);
+                       print escapeHTML($co{'title'}) . "</title>\n";
+                       print "\t<link> " . $my_url . "/$project/commit/$commit</link>\n";
+                       print "\t<description>";
+                       my $comment = $co{'comment'};
+                       foreach my $line (@$comment) {
+                               print escapeHTML($line) . "\n";
+                       }
+                       print "\t</description>\n";
                        print "</item>\n";
                }
        }
@@ -425,27 +434,45 @@ if ($action eq "blob") {
                print "</channel></rss>";
        }
 } elsif ($action eq "commit") {
-       my $parent = "";
-       open my $fd, "-|", "$gitbin/cat-file", "commit", $hash;
-       while (my $line = <$fd>) {
-               chomp($line);
-               last if $line eq "";
-               if ($line =~ m/^parent (.*)$/ && $parent eq "") {
-                       $parent = $1;
-               }
-       }
-       my $title = <$fd>;
-       $title = escapeHTML($title);
-       close $fd;
-
-       open $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash;
+       my %co = git_commit($hash);
+       open my $fd, "-|", "$gitbin/diff-tree", "-r", $co{'parent'}, $hash;
        my (@difftree) = map { chomp; $_ } <$fd>;
        close $fd;
 
        git_header_html();
-       print "<div class=\"head2\">\n";
-       print "view " . $cgi->a({-href => "$myself/$project/commitdiff/$hash"}, "diff") . "</div><br/><br/>\n";
-       print "<div class=\"title\">$title<br/></div>\n";
+       print "<div class=\"head2\"> view\n";
+       print $cgi->a({-href => "$my_uri/$project/commit/$hash"}, "commit") . " | ";
+       print $cgi->a({-href => "$my_uri/$project/commitdiff/$hash"}, "diff");
+       print "</div><br/><br/>\n";
+       print "<div class=\"title\">" . $cgi->a({-href => "$my_uri/$project/commitdiff/$hash"}, $co{'title'}) . "<br/></div>\n";
+       print "<table cellspacing=\"0\" class=\"log\">\n";
+       print "<tr>\n";
+       print "<td class=\"head2\">";
+       print "author &nbsp; &nbsp;" . escapeHTML($co{'author'}) . " [" . gmtime($co{'author_time'}) . " " . $co{'author_timezone'} . "]<br/>\n";
+       print "committer " . escapeHTML($co{'committer'}) . " [" . gmtime($co{'committer_time'}) . " " . $co{'committer_timezone'} . "]<br/>\n";
+       print "commit &nbsp; &nbsp;$hash<br/>\n";
+       print "tree &nbsp; &nbsp; &nbsp;" . $cgi->a({-href => "$my_uri/$project/tree/$co{'tree'}"}, $co{'tree'}) . "<br/>\n";
+       my $parents  = $co{'parents'};
+       foreach my $par (@$parents) {
+               print "parent &nbsp; &nbsp;" . $cgi->a({-href => "$my_uri/$project/tree/$par"}, $par) . "<br/>\n";
+       }
+       print "</td>";
+       print "</tr>\n";
+       print "<tr>\n";
+       print "<td>\n";
+       my $comment = $co{'comment'};
+       foreach my $line (@$comment) {
+               if ($line =~ m/signed-off-by:/i) {
+                       print '<div class="signed_off">' . escapeHTML($line) . "<br/></div>\n";
+               } else {
+                       print escapeHTML($line) . "<br/>\n";
+               }
+       }
+       print "<br/><br/>\n";
+       print "</td>";
+       print "</tr>\n";
+       print "</table>";
+
        print "<pre>\n";
        foreach my $line (@difftree) {
                # '*100644->100644      blob    9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596      net/ipv4/route.c'
@@ -458,14 +485,14 @@ if ($action eq "blob") {
                my $file = $5;
                if ($type eq "blob") {
                        if ($op eq "+") {
-                               print "added\t" . $cgi->a({-href => "$myself/$project/blob/$id"}, $file) . "\n";
+                               print "added\t" . $cgi->a({-href => "$my_uri/$project/blob/$id"}, $file) . "\n";
                        } elsif ($op eq "-") {
-                               print "removed\t" . $cgi->a({-href => "$myself/$project/blob/$id"}, $file) . "\n";
+                               print "removed\t" . $cgi->a({-href => "$my_uri/$project/blob/$id"}, $file) . "\n";
                        } elsif ($op eq "*") {
                                $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
                                my $old = $1;
                                my $new = $2;
-                               print "changed\t" . $cgi->a({-href => "$myself/$project/blobdiff/$old/$new"}, $file) . "\n";
+                               print "changed\t" . $cgi->a({-href => "$my_uri/$project/blobdiff/$old/$new"}, $file) . "\n";
                        }
                }
        }
@@ -481,27 +508,17 @@ if ($action eq "blob") {
        print "<br/>";
        git_footer_html();
 } elsif ($action eq "commitdiff") {
-       my $parent = "";
-       open my $fd, "-|", "$gitbin/cat-file", "commit", $hash;
-       while (my $line = <$fd>) {
-               chomp($line);
-               last if $line eq "";
-               if ($line =~ m/^parent (.*)$/ && $parent eq "") {
-                       $parent = $1;
-               }
-       }
-       my $title = <$fd>;
-       $title = escapeHTML($title);
-       close $fd;
-
-       open $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash;
+       my %co = git_commit($hash);
+       open my $fd, "-|", "$gitbin/diff-tree", "-r", $co{'parent'}, $hash;
        my (@difftree) = map { chomp; $_ } <$fd>;
        close $fd;
 
        git_header_html();
-       print "<div class=\"head2\">\n";
-       print "view " . $cgi->a({-href => "$myself/$project/commit/$hash"}, "commit") . "</div><br/><br/>\n";
-       print "<div class=\"title\">$title<br/></div>\n";
+       print "<div class=\"head2\"> view\n";
+       print $cgi->a({-href => "$my_uri/$project/commit/$hash"}, "commit") . " | ";
+       print $cgi->a({-href => "$my_uri/$project/commitdiff/$hash"}, "diff");
+       print "</div><br/><br/>\n";
+       print "<div class=\"title\">" . $cgi->a({-href => "$my_uri/$project/commit/$hash"}, $co{'title'}) . "<br/></div>\n";
        print "<pre>\n";
        foreach my $line (@difftree) {
                # '*100644->100644      blob    8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154      Makefile'