v154
[git.git] / gitweb.cgi
index 619db53..a7a7edf 100755 (executable)
 use strict;
 use warnings;
 use CGI qw(:standard :escapeHTML);
+use CGI::Util qw(unescape);
 use CGI::Carp qw(fatalsToBrowser);
 use Fcntl ':mode';
 
 my $cgi = new CGI;
-my $version =          "133";
+my $version =          "154";
 my $my_url =           $cgi->url();
 my $my_uri =           $cgi->url(-absolute => 1);
 my $rss_link = "";
@@ -29,12 +30,14 @@ my $gitbin =                "/usr/bin";
 my $gittmp =           "/tmp/gitweb";
 
 # target of the home link on top of all pages
-#my $home_link =               $my_uri;
-my $home_link =                "/git";
+my $home_link =                $my_uri;
+
+# html text to include at home page
+my $home_text =                "indextext.html";
 
 # source of projects list
 #my $projects_list = $projectroot;
-my $projects_list = "index/index.txt";
+my $projects_list = "index/index.aux";
 
 # input validation and dispatch
 my $action = $cgi->param('a');
@@ -48,7 +51,7 @@ if (defined $action) {
                exit;
        }
 } else {
-       $action = "log";
+       $action = "summary";
 }
 
 my $project = $cgi->param('p');
@@ -70,9 +73,10 @@ if (defined $project) {
                die_error(undef, "No such project.");
        }
        $rss_link = "<link rel=\"alternate\" title=\"$project log\" href=\"$my_uri?p=$project;a=rss\" type=\"application/rss+xml\"/>";
+       $ENV{'GIT_OBJECT_DIRECTORY'} = "$projectroot/$project/objects";
        $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
 } else {
-       git_project_list($projects_list);
+       git_project_list();
        exit;
 }
 
@@ -114,7 +118,16 @@ if (defined $time_back) {
        }
 }
 
-if ($action eq "blob") {
+if ($action eq "summary") {
+       git_summary();
+       exit;
+} elsif ($action eq "branches") {
+       git_branches();
+       exit;
+} elsif ($action eq "tags") {
+       git_tags();
+       exit;
+} elsif ($action eq "blob") {
        git_blob();
        exit;
 } elsif ($action eq "tree") {
@@ -183,19 +196,19 @@ div.title, a.title {
 a.title:hover { background-color: #d9d8d1; }
 div.title_text { padding:6px 8px; border: solid #d9d8d1; border-width:0px 0px 1px; }
 div.log_body { padding:8px 8px 8px 150px; }
-span.log_age { position:relative; float:left; width:142px; font-style:italic; }
+span.age { position:relative; float:left; width:142px; font-style:italic; }
 div.log_link {
        font-size:10px; font-family:sans-serif; font-style:normal;
        position:relative; float:left; width:142px;
 }
-div.list { display:block; padding:4px 8px 2px; font-weight:bold; }
+div.list { display:block; padding:4px 8px 2px; }
 div.list_head {
        display:block; padding:6px 6px 4px; border:solid #d9d8d1;
        border-width:0px 0px 1px; font-style:italic;
 }
 div.list a { text-decoration:none; color:#000000; }
 div.list a:hover { color:#880000; }
-div.link {
+div.list_link {
        padding:4px 8px 6px; border:solid #d9d8d1; border-width:0px 0px 1px;
        font-family:sans-serif; font-size:10px;
 }
@@ -205,6 +218,7 @@ td.link { font-family:sans-serif; font-size:10px; }
 td.pre { font-family:monospace; font-size:12px; white-space:pre; padding:2px 15px 0px 0px; }
 div.pre { font-family:monospace; font-size:12px; white-space:pre; }
 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
+div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
 a.rss_logo { float:right; padding:3px 0px; width:35px; line-height:10px;
        border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
        color:#ffffff; background-color:#ff6600;
@@ -217,11 +231,11 @@ a.rss_logo:hover { background-color:#ee5500; }
 <body>
 EOF
        print "<div class=\"page_header\">\n" .
-             "<a href=\"http://kernel.org/pub/software/scm/cogito\">" .
+             "<a href=\"http://kernel.org/pub/software/scm/git/docs/\">" .
              "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
        print $cgi->a({-href => $home_link}, "projects") . " / ";
        if (defined $project) {
-               print $cgi->a({-href => "$my_uri?p=$project;a=log"}, escapeHTML($project));
+               print $cgi->a({-href => "$my_uri?p=$project;a=summary"}, escapeHTML($project));
                if (defined $action) {
                        print " / $action";
                }
@@ -266,17 +280,15 @@ sub git_get_type {
        return $type;
 }
 
-sub git_read_head {
+sub git_read_hash {
        my $path = shift;
 
-       open my $fd, "$projectroot/$path/HEAD" || return undef;
+       open my $fd, "$projectroot/$path" || return undef;
        my $head = <$fd>;
        close $fd;
        chomp $head;
        if ($head =~ m/^[0-9a-fA-F]{40}$/) {
                return $head;
-       } else {
-               return undef;
        }
 }
 
@@ -290,6 +302,28 @@ sub git_read_description {
        return $descr;
 }
 
+sub git_read_tag {
+       my $tag_id = shift;
+       my %tag;
+
+       open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" || return;
+       while (my $line = <$fd>) {
+               chomp $line;
+               if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
+                       $tag{'object'} = $1;
+               } elsif ($line =~ m/^type (.*)$/) {
+                       $tag{'type'} = $1;
+               } elsif ($line =~ m/^tag (.*)$/) {
+                       $tag{'name'} = $1;
+               }
+       }
+       close $fd || return;
+       if (!defined $tag{'name'}) {
+               return
+       };
+       return %tag
+}
+
 sub git_read_commit {
        my $commit = shift;
        my %co;
@@ -317,27 +351,28 @@ sub git_read_commit {
                        $co{'committer_name'} =~ s/ <.*//;
                }
        }
+       if (!defined $co{'tree'}) {
+               close $fd;
+               return undef
+       };
        $co{'parents'} = \@parents;
        $co{'parent'} = $parents[0];
        my (@comment) = map { chomp; $_ } <$fd>;
        $co{'comment'} = \@comment;
-       $comment[0] =~ m/^(.{0,60}[^ ]*)/;
+       $comment[0] =~ m/^(.{0,60}[^ \/]*)/;
        $co{'title'} = $1;
        if ($comment[0] ne $co{'title'}) {
-               $co{'title'} .= " [...]";
+               $co{'title'} .= " ...";
        }
        close $fd || return;
-       if (!defined $co{'tree'}) {
-               return undef
-       };
 
        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;
+       } 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;
@@ -350,10 +385,10 @@ sub git_read_commit {
                $co{'age_string'} .= " hours ago";
        } elsif ($age > 60*2) {
                $co{'age_string'} = int $age/60;
-               $co{'age_string'} .= " minutes ago";
+               $co{'age_string'} .= " min ago";
        } elsif ($age > 2) {
                $co{'age_string'} = int $age;
-               $co{'age_string'} .= " seconds ago";
+               $co{'age_string'} .= " sec ago";
        } else {
                $co{'age_string'} .= " right now";
        }
@@ -510,12 +545,11 @@ sub get_file_owner {
 }
 
 sub git_project_list {
-       my $project_list = shift;
        my @list;
 
-       if (-d $project_list) {
+       if (-d $projects_list) {
                # search in directory
-               my $dir = $project_list;
+               my $dir = $projects_list;
                opendir my $dh, $dir || return undef;
                while (my $dir = readdir($dh)) {
                        if (-e "$projectroot/$dir/HEAD") {
@@ -526,14 +560,16 @@ sub git_project_list {
                        }
                }
                closedir($dh);
-       } elsif (-e $project_list) {
-               # read from file
+       } elsif (-f $projects_list) {
+               # read from file:
                # 'git/git.git:Linus Torvalds'
                # 'linux/hotplug/udev.git'
-               open my $fd , $project_list || return undef;
+               open my $fd , $projects_list || return undef;
                while (my $line = <$fd>) {
                        chomp $line;
-                       my ($path, $owner) = split ':', $line;
+                       my ($path, $owner) = split ' ', $line;
+                       $path = unescape($path);
+                       $owner = unescape($owner);
                        if (!defined $path) {
                                next;
                        }
@@ -554,20 +590,29 @@ sub git_project_list {
        @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
 
        git_header_html();
-       print "<div class=\"page_body\"><br/>\n";
-       print "<table cellspacing=\"0\">\n";
-       print "<tr>\n" .
+       if (-f $home_text) {
+               print "<div class=\"index_include\">\n";
+               open (my $fd, $home_text);
+               print <$fd>;
+               close $fd;
+               print "</div>\n";
+       }
+       print "<div class=\"page_body\"><br/>\n" .
+             "<table cellspacing=\"0\">\n" .
+             "<tr>\n" .
              "<th>Project</th>\n" .
              "<th>Description</th>\n" .
              "<th>Owner</th>\n" .
              "<th>last change</th>\n" .
+             "<th></th>\n" .
              "</tr>\n";
        foreach my $pr (@list) {
                my %proj = %$pr;
-               my $head = git_read_head($proj{'path'});
+               my $head = git_read_hash("$proj{'path'}/HEAD");
                if (!defined $head) {
                        next;
                }
+               $ENV{'GIT_OBJECT_DIRECTORY'} = "$projectroot/$proj{'path'}/objects";
                $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$proj{'path'}/objects";
                my %co = git_read_commit($head);
                if (!%co) {
@@ -579,17 +624,24 @@ sub git_project_list {
                        $proj{'owner'} = get_file_owner("$projectroot/$proj{'path'}") || "";
                }
                print "<tr>\n" .
-                     "<td>" . $cgi->a({-href => "$my_uri?p=" . $proj{'path'} . ";a=log"}, escapeHTML($proj{'path'})) . "</td>\n" .
+                     "<td>" . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary"}, escapeHTML($proj{'path'})) . "</td>\n" .
                      "<td>$descr</td>\n" .
                      "<td><i>$proj{'owner'}</i></td>\n";
+               my $colored_age;
                if ($co{'age'} < 60*60*2) {
-                       print "<td><span style =\"color: #009900;\"><b><i>$co{'age_string'}</i></b></span></td>\n";
+                       $colored_age = "<span style =\"color: #009900;\"><b><i>$co{'age_string'}</i></b></span>";
                } elsif ($co{'age'} < 60*60*24*2) {
-                       print "<td><span style =\"color: #009900;\"><i>$co{'age_string'}</i></span></td>\n";
+                       $colored_age = "<span style =\"color: #009900;\"><i>$co{'age_string'}</i></span>";
                } else {
-                       print "<td><i>$co{'age_string'}</i></td>\n";
+                       $colored_age = "<i>$co{'age_string'}</i>";
                }
-               print "</tr>\n";
+               print "<td>$colored_age</td>\n" .
+                     "<td class=\"link\">" .
+                     $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary"}, "summary") .
+                     " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=log"}, "log") .
+                     " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=tree"}, "tree") .
+                     "</td>\n" .
+                     "</tr>\n";
        }
        print "</table>\n" .
              "<br/>\n" .
@@ -597,6 +649,219 @@ sub git_project_list {
        git_footer_html();
 }
 
+sub git_read_refs {
+       my $ref_dir = shift;
+       my @reflist;
+
+       opendir my $dh, "$projectroot/$project/$ref_dir";
+       my @refs = grep !m/^\./, readdir $dh;
+       closedir($dh);
+       foreach my $ref_file (@refs) {
+               my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
+               my $type = git_get_type($ref_id) || next;
+               my %ref_item;
+               my %co;
+               if ($type eq "tag") {
+                       my %tag = git_read_tag($ref_id);
+                       if ($tag{'type'} eq "commit") {
+                               %co = git_read_commit($tag{'object'});
+                       }
+                       $ref_item{'type'} = $tag{'type'};
+                       $ref_item{'name'} = $tag{'name'};
+                       $ref_item{'id'} = $tag{'object'};
+               } elsif ($type eq "commit"){
+                       %co = git_read_commit($ref_id);
+                       $ref_item{'type'} = "commit";
+                       $ref_item{'name'} = $ref_file;
+                       $ref_item{'title'} = $co{'title'};
+                       $ref_item{'id'} = $ref_id;
+               }
+               $ref_item{'epoch'} = $co{'committer_epoch'} || 0;
+               $ref_item{'age'} = $co{'age_string'} || "unknown";
+
+               push @reflist, \%ref_item;
+       }
+       # sort tags by age
+       @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
+       return \@reflist;
+}
+
+sub git_summary {
+       my $descr = git_read_description($project) || "none";
+       my $head = git_read_hash("$project/HEAD");
+       $ENV{'GIT_OBJECT_DIRECTORY'} = "$projectroot/$project/objects";
+       $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
+       my %co = git_read_commit($head);
+       my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
+
+       my $owner;
+       if (-f $projects_list) {
+               open (my $fd , $projects_list);
+               while (my $line = <$fd>) {
+                       chomp $line;
+                       my ($pr, $ow) = split ' ', $line;
+                       $pr = unescape($pr);
+                       $ow = unescape($ow);
+                       if ($pr eq $project) {
+                               $owner = $ow;
+                               last;
+                       }
+               }
+               close $fd;
+       }
+       if (!defined $owner) {
+               $owner = get_file_owner("$projectroot/$project");
+       }
+
+       git_header_html();
+       print "<div class=\"page_nav\">\n" .
+             $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
+             " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree"}, "tree") .
+             "<br/><br/>\n" .
+             "</div>\n";
+       print "<div class=\"title\">project</div>\n";
+       print "<div class=\"page_body\">\n" .
+             "<table cellspacing=\"0\">\n" .
+             "<tr><td>description</td><td>" . escapeHTML($descr) . "</td></tr>\n" .
+             "<tr><td>owner</td><td>$owner</td></tr>\n" .
+             "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
+             "</table>\n" .
+             "<br/></div>\n";
+       open my $fd, "-|", "$gitbin/git-rev-list --max-count=11 " . git_read_hash("$project/HEAD") || die_error(undef, "Open failed.");
+       my (@revlist) = map { chomp; $_ } <$fd>;
+       close $fd;
+       print "<div>\n" .
+             $cgi->a({-href => "$my_uri?p=$project;a=log", -class => "title"}, "commits") .
+             "</div>\n";
+       my $i = 10;
+       print  "<div class=\"page_body\">\n" .
+              "<table cellspacing=\"0\">\n";
+       foreach my $commit (@revlist) {
+               my %co = git_read_commit($commit);
+               my %ad = date_str($co{'author_epoch'});
+               print "<tr>\n";
+               if (--$i > 0) {
+                       print "<td>$co{'age_string'}</td>\n" .
+                             "<td>$co{'author_name'}</td>\n" .
+                             "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, escapeHTML($co{'title'})) . "</td>\n" .
+                             "<td class=\"link\">" .
+                             $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
+                             " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
+                             "</td>\n" .
+                             "</tr>";
+               } else {
+                       print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "...") . "</td>\n" .
+                       "</tr>";
+                       last;
+               }
+       }
+       print "</table\n>" .
+             "</div>\n";
+
+       my $taglist = git_read_refs("refs/tags");
+       if (defined @$taglist) {
+               print "<div>\n" .
+                     $cgi->a({-href => "$my_uri?p=$project;a=tags", -class => "title"}, "tags") .
+                     "</div>\n";
+               my $i = 10;
+               print  "<div class=\"page_body\">\n" .
+                      "<table cellspacing=\"0\">\n";
+               foreach my $entry (@$taglist) {
+                       my %tag = %$entry;
+                       print "<tr>\n";
+                       if (--$i > 0) {
+                               print "<td>$tag{'age'}</td>\n" .
+                                     "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, escapeHTML($tag{'name'})) . "</td>\n" .
+                                     "</tr>";
+                       } else {
+                               print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=tags"}, "...") . "</td>\n" .
+                               "</tr>";
+                               last;
+                       }
+               }
+               print "</table\n>" .
+                     "</div>\n";
+       }
+
+       my $branchlist = git_read_refs("refs/heads");
+       if (defined @$branchlist) {
+               print "<div>\n" .
+                     $cgi->a({-href => "$my_uri?p=$project;a=branches", -class => "title"}, "branches") .
+                     "</div>\n";
+               my $i = 10;
+               print  "<div class=\"page_body\">\n" .
+                      "<table cellspacing=\"0\">\n";
+               foreach my $entry (@$branchlist) {
+                       my %tag = %$entry;
+                       print "<tr>\n";
+                       if (--$i > 0) {
+                               print "<td>$tag{'age'}</td>\n" .
+                                     "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, escapeHTML($tag{'name'})) . "</td>\n" .
+                                     "</tr>";
+                       } else {
+                               print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=branches"}, "...") . "</td>\n" .
+                               "</tr>";
+                               last;
+                       }
+               }
+               print "</table\n>" .
+                     "</div>\n";
+       }
+       git_footer_html();
+}
+
+sub git_tags {
+       my $head = git_read_hash("$project/HEAD");
+       git_header_html();
+       print "<div class=\"page_nav\">\n" .
+             $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
+             " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
+             " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree"}, "tree") .
+             "<br/><br/>\n" .
+             "</div>\n";
+       my $taglist = git_read_refs("refs/tags");
+       print "<div>\n" .
+             $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "tags") .
+             "</div>\n";
+       if (defined @$taglist) {
+               foreach my $entry (@$taglist) {
+                       my %tag = %$entry;
+                       print "<div class=\"list\">\n" .
+                             $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"},
+                             "<span class=\"age\">$tag{'age'}</span>" .  escapeHTML($tag{'name'})) . "\n" .
+                             "</div>\n";
+               }
+       }
+       print "<div class=\"list\"><br/></div>\n";
+       git_footer_html();
+}
+
+sub git_branches {
+       my $head = git_read_hash("$project/HEAD");
+       git_header_html();
+       print "<div class=\"page_nav\">\n" .
+             $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
+             " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
+             " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree"}, "tree") .
+             "<br/><br/>\n" .
+             "</div>\n";
+       my $taglist = git_read_refs("refs/heads");
+       print "<div>\n" .
+             $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "branches") .
+             "</div>\n";
+       if (defined @$taglist) {
+               foreach my $entry (@$taglist) {
+                       my %tag = %$entry;
+                       print "<div class=\"list\">\n" .
+                             $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"},
+                             "<span class=\"age\">$tag{'age'}</span>" .  escapeHTML($tag{'name'})) . "\n" .
+                             "</div>\n";
+               }
+       }
+       print "<div class=\"list\"><br/></div>\n";
+       git_footer_html();
+}
+
 sub git_get_hash_by_path {
        my $base = shift;
        my $path = shift;
@@ -629,7 +894,7 @@ sub git_get_hash_by_path {
 
 sub git_blob {
        if (!defined $hash && defined $file_name) {
-               my $base = $hash_base || git_read_head($project);
+               my $base = $hash_base || git_read_hash("$project/HEAD");
                $hash = git_get_hash_by_path($base, $file_name, "blob");
        }
        open my $fd, "-|", "$gitbin/git-cat-file blob $hash" || die_error(undef, "Open failed.");
@@ -639,7 +904,7 @@ sub git_blob {
                print "<div class=\"page_nav\">\n" .
                      $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");
+                     " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree");
                if (defined $file_name) {
                        print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base;f=$file_name"}, "history");
                }
@@ -672,12 +937,15 @@ sub git_blob {
 
 sub git_tree {
        if (!defined $hash) {
-               $hash = git_read_head($project);
+               $hash = git_read_hash("$project/HEAD");
                if (defined $file_name) {
-                       my $base = $hash_base || git_read_head($project);
+                       my $base = $hash_base || git_read_hash("$project/HEAD");
                        $hash = git_get_hash_by_path($base, $file_name, "tree");
                }
        }
+       if (!defined $hash_base) {
+               $hash_base = git_read_hash("$project/HEAD");
+       }
        open my $fd, "-|", "$gitbin/git-ls-tree $hash" || die_error(undef, "Open git-ls-tree failed.");
        my (@entries) = map { chomp; $_ } <$fd>;
        close $fd || die_error(undef, "Reading tree failed.");
@@ -689,9 +957,10 @@ sub git_tree {
        if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
                $base_key = ";hb=$hash_base";
                print "<div class=\"page_nav\">\n" .
-                     $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") .
+                     $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
+                     " | " . $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") .
                      "<br/><br/>\n" .
                      "</div>\n";
                print "<div>\n" .
@@ -739,7 +1008,7 @@ sub git_tree {
 }
 
 sub git_rss {
-       open my $fd, "-|", "$gitbin/git-rev-list --max-count=20 " . git_read_head($project) || die_error(undef, "Open failed.");
+       open my $fd, "-|", "$gitbin/git-rev-list --max-count=20 " . git_read_hash("$project/HEAD") || die_error(undef, "Open failed.");
        my (@revlist) = map { chomp; $_ } <$fd>;
        close $fd || die_error(undef, "Reading rev-list failed.");
 
@@ -748,7 +1017,7 @@ sub git_rss {
              "<rss version=\"0.91\">\n";
        print "<channel>\n";
        print "<title>$project</title>\n".
-             "<link> " . $my_url . "/$project/log</link>\n".
+             "<link> $my_url/$project/log</link>\n".
              "<description>$project log</description>\n".
              "<language>en</language>\n";
 
@@ -757,7 +1026,7 @@ sub git_rss {
                my %ad = date_str($co{'author_epoch'});
                print "<item>\n" .
                      "\t<title>" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'minute'}) . " - " . 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) {
@@ -770,7 +1039,9 @@ sub git_rss {
 }
 
 sub git_log {
-       my $head = git_read_head($project);
+       if (!defined $hash) {
+               $hash = git_read_hash("$project/HEAD");
+       }
        my $limit_option = "";
        if (!defined $time_back) {
                $limit_option = "--max-count=10";
@@ -778,7 +1049,7 @@ sub git_log {
                my $date = time - $time_back*24*60*60;
                $limit_option = "--max-age=$date";
        }
-       open my $fd, "-|", "$gitbin/git-rev-list $limit_option $head" || die_error(undef, "Open failed.");
+       open my $fd, "-|", "$gitbin/git-rev-list $limit_option $hash" || die_error(undef, "Open failed.");
        my (@revlist) = map { chomp; $_ } <$fd>;
        close $fd || die_error(undef, "Reading rev-list failed.");
 
@@ -790,12 +1061,12 @@ sub git_log {
              $cgi->a({-href => "$my_uri?p=$project;a=log;t=31"}, "month") . " | " .
              $cgi->a({-href => "$my_uri?p=$project;a=log;t=365"}, "year") . " | " .
              $cgi->a({-href => "$my_uri?p=$project;a=log;t=0"}, "all") . "<br/>\n";
-       print "<br/><br/>\n" .
+       print "<br/>\n" .
              "</div>\n";
 
        if (!@revlist) {
-               my %co = git_read_commit($head);
-               print "<div class=\"page_body\"> Last change " . $co{'age_string'} . ".<br/><br/></div>\n";
+               my %co = git_read_commit($hash);
+               print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
        }
 
        foreach my $commit (@revlist) {
@@ -804,7 +1075,7 @@ sub git_log {
                my %ad = date_str($co{'author_epoch'});
                print "<div>\n" .
                      $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
-                     "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
+                     "<span class=\"age\">$co{'age_string'}</span>" . escapeHTML($co{'title'})) . "\n" .
                      "</div>\n";
                print "<div class=\"title_text\">\n" .
                      "<div class=\"log_link\">\n" .
@@ -812,13 +1083,13 @@ sub git_log {
                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
                      "<br/>\n" .
                      "</div>\n" .
-                     "<i>" . escapeHTML($co{'author_name'}) .  " [" . $ad{'rfc2822'} . "]</i><br/>\n" .
+                     "<i>" . escapeHTML($co{'author_name'}) .  " [$ad{'rfc2822'}]</i><br/>\n" .
                      "</div>\n" .
                      "<div class=\"log_body\">\n";
                my $comment = $co{'comment'};
                my $empty = 0;
                foreach my $line (@$comment) {
-                       if ($line =~ m/^(signed[ \-]off[\-]by[ :]|acked[\-]by[ \:]|cc[ :])/i) {
+                       if ($line =~ m/^(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
                                next;
                        }
                        if ($line eq "") {
@@ -849,7 +1120,7 @@ sub git_commit {
 
        my @difftree;
        if (defined $co{'parent'}) {
-               open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash" || die_error(undef, "Open failed.");
+               open my $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $hash" || die_error(undef, "Open failed.");
                @difftree = map { chomp; $_ } <$fd>;
                close $fd || die_error(undef, "Reading diff-tree failed.");
        } else {
@@ -860,11 +1131,12 @@ sub git_commit {
        }
        git_header_html();
        print "<div class=\"page_nav\">\n" .
-             $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit");
+             $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
+             " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit");
        if (defined $co{'parent'}) {
                print " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff");
        }
-       print " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash"}, "tree") . "\n" .
+       print " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "\n" .
              "<br/><br/></div>\n";
        if (defined $co{'parent'}) {
                print "<div>\n" .
@@ -872,13 +1144,13 @@ sub git_commit {
                      "</div>\n";
        } else {
                print "<div>\n" .
-                     $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
+                     $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
                      "</div>\n";
        }
        print "<div class=\"title_text\">\n" .
              "<table cellspacing=\"0\">\n";
        print "<tr><td>author</td><td>" . escapeHTML($co{'author'}) . "</td></tr>\n".
-             "<tr><td></td><td> " . $ad{'rfc2822'};
+             "<tr><td></td><td> $ad{'rfc2822'}";
        if ($ad{'hour_local'} < 6) {
                printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
        } else {
@@ -886,10 +1158,10 @@ sub git_commit {
        }
        print "</td></tr>\n";
        print "<tr><td>committer</td><td>" . escapeHTML($co{'committer'}) . "</td></tr>\n";
-       print "<tr><td></td><td> " . $cd{'rfc2822'} . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
+       print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
        print "<tr><td>commit</td><td style=\"font-family: monospace;\">$hash</td></tr>\n";
        print "<tr><td>tree</td><td style=\"font-family: monospace;\">" .
-             $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=" . $hash}, $co{'tree'}) . "</td></tr>\n";
+             $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, $co{'tree'}) . "</td></tr>\n";
        my $parents  = $co{'parents'};
        foreach my $par (@$parents) {
                print "<tr><td>parent</td><td style=\"font-family: monospace;\">" .
@@ -911,7 +1183,7 @@ sub git_commit {
                } else {
                        $empty = 0;
                }
-               if ($line =~ m/^(signed[ \-]off[\-]by[ :]|acked[\-]by[ \:]|cc[ :])/i) {
+               if ($line =~ m/^(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
                        $signed = 1;
                        print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
                } else {
@@ -944,9 +1216,9 @@ sub git_commit {
                                }
                                print "<div class=\"list\">\n" .
                                      $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"},
-                                     escapeHTML($file) . " <span style=\"color: #008000;\">[new " . file_type($mode) . $mode_chng . "]</span>") . "\n" .
+                                     escapeHTML($file) . " <span style=\"color: #008000;\">[new " . file_type($mode) . "$mode_chng]</span>") . "\n" .
                                      "</div>\n";
-                               print "<div class=\"link\">\n" .
+                               print "<div class=\"list_link\">\n" .
                                      $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, "blob") . "\n" .
                                      "</div>\n";
                        } elsif ($op eq "-") {
@@ -954,7 +1226,7 @@ sub git_commit {
                                      $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"},
                                      escapeHTML($file) .  " <span style=\"color: #c00000;\">[deleted " . file_type($mode) . "]</span>") . "\n" .
                                      "</div>";
-                               print "<div class=\"link\">\n" .
+                               print "<div class=\"list_link\">\n" .
                                      $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, "blob") . " | " .
                                      $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "\n" .
                                      "</div>\n";
@@ -967,7 +1239,7 @@ sub git_commit {
                                my $to_mode = $2;
                                my $mode_chnge = "";
                                if ($from_mode != $to_mode) {
-                                       $mode_chnge = " <span style=\"color: #888888;\">[changed";
+                                       $mode_chnge = " <span style=\"color: #777777;\">[changed";
                                        if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
                                                $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
                                        }
@@ -990,7 +1262,7 @@ sub git_commit {
                                              escapeHTML($file) . $mode_chnge) . "\n" .
                                              "</div>\n";
                                }
-                               print "<div class=\"link\">\n";
+                               print "<div class=\"list_link\">\n";
                                if ($to_id ne $from_id) {
                                        print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"}, "diff") . " | ";
                                }
@@ -1008,9 +1280,10 @@ sub git_blobdiff {
        git_header_html();
        if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
                print "<div class=\"page_nav\">\n" .
-                     $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
+                     $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
+                     " | " . $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");
+                     " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree");
                        if (defined $file_name) {
                                print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base;f=$file_name"}, "history");
                        }
@@ -1046,20 +1319,45 @@ sub git_commitdiff {
        if (!%co) {
                die_error(undef, "Unknown commit object.");
        }
-       open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash" || die_error(undef, "Open failed.");
+       open my $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $hash" || die_error(undef, "Open failed.");
        my (@difftree) = map { chomp; $_ } <$fd>;
        close $fd || die_error(undef, "Reading diff-tree failed.");
 
        git_header_html();
        print "<div class=\"page_nav\">\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"}, "commitdiff") . " | \n" .
-             $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" .  $co{'tree'} . ";hb=$hash"}, "tree") . "\n" .
+             $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
+             " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
+             " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
+             " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" .  $co{'tree'} . ";hb=$hash"}, "tree") .
              "<br/><br/></div>\n";
        print "<div>\n" .
              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
              "</div>\n";
        print "<div class=\"page_body\">\n";
+       my $comment = $co{'comment'};
+       my $empty = 0;
+       my $signed = 0;
+       my @log = @$comment;
+       # remove first and empty lines after that
+       shift @log;
+       while (defined $log[0] && $log[0] eq "") {
+               shift @log;
+       }
+       foreach my $line (@log) {
+               if ($line =~ m/^(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
+                       next;
+               }
+               if ($line eq "") {
+                       if ($empty) {
+                               next;
+                       }
+                       $empty = 1;
+               } else {
+                       $empty = 0;
+               }
+               print escapeHTML($line) . "<br/>\n";
+       }
+       print "<br/>\n";
        foreach my $line (@difftree) {
                # '*100644->100644      blob    8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154      Makefile'
                $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
@@ -1104,7 +1402,7 @@ sub git_commitdiff {
 
 sub git_history {
        if (!defined $hash) {
-               $hash = git_read_head($project);
+               $hash = git_read_hash("$project/HEAD");
        }
        my %co = git_read_commit($hash);
        if (!%co) {
@@ -1114,7 +1412,7 @@ sub git_history {
        print "<div class=\"page_nav\">\n" .
              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | " .
              $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") . " | " .
-             $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash"}, "tree") .
+             $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
              "<br/><br/>\n" .
              "</div>\n";
        print "<div>\n" .
@@ -1142,16 +1440,16 @@ sub git_history {
                        }
                        print "<div class=\"list\">\n" .
                              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"},
-                             "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
+                             "<span class=\"age\">$co{'age_string'}</span>" . escapeHTML($co{'title'})) . "\n" .
                              "</div>\n";
-                       print "<div class=\"link\">\n" .
+                       print "<div class=\"list_link\">\n" .
                              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
                              " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" .  $co{'tree'} . ";hb=$commit"}, "tree") .
-                             " | " . $cgi->a({-href => "$my_uri?p=$project;a=blob;hb=$commit;f=" . $file}, "blob");
+                             " | " . $cgi->a({-href => "$my_uri?p=$project;a=blob;hb=$commit;f=$file"}, "blob");
                        my $blob = git_get_hash_by_path($hash, $file_name);
                        my $blob_parent = git_get_hash_by_path($commit, $file_name);
                        if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
-                               print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=" . $file}, "diff");
+                               print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file"}, "diff");
                        }
                        print "<br/>\n" .
                              "</div>\n";