gitweb.cgion commit v063 (b51103f)
   1#!/usr/bin/perl
   2
   3# gitweb.pl - simple web interface to track changes in git repositories
   4#
   5# (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
   6# (C) 2005, Christian Gierke <ch@gierke.de>
   7#
   8# This file is licensed under the GPL v2, or a later version
   9
  10use strict;
  11use warnings;
  12use CGI qw(:standard :escapeHTML);
  13use CGI::Carp qw(fatalsToBrowser);
  14
  15my $cgi = new CGI;
  16
  17my $version =           "063";
  18my $projectroot =       "/pub/scm";
  19my $defaultprojects =   "linux/kernel/git";
  20my $gitbin =            "/usr/bin";
  21my $gittmp =            "/tmp/gitweb";
  22my $giturl =            "/pub/software/scm/cogito";
  23my $my_url =            $cgi->url();
  24my $my_uri =            $cgi->url(-absolute => 1);
  25
  26mkdir($gittmp, 0700);
  27my $project = $cgi->param('p');
  28my $action = $cgi->param('a');
  29my $hash = $cgi->param('h');
  30my $hash_parent = $cgi->param('hp');
  31my $file_name = $cgi->param('f');
  32my $time_back = $cgi->param('t');
  33$ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
  34
  35# validate input
  36if (defined($project) && $project =~ /(^|\/)(|\.|\.\.)($|\/)/) {
  37        die_error("", "Invalid project parameter.");
  38}
  39if (defined($file_name) && $file_name =~ /(^|\/)(|\.|\.\.)($|\/)/) {
  40        die_error("", "Invalid file parameter.");
  41}
  42if (defined($action) && !$action =~ m/^[0-9a-zA-Z\.\-]+$/) {
  43        die_error("", "Invalid action parameter.");
  44}
  45if (defined($hash) && !($hash =~ m/^[0-9a-fA-F]{40}$/)) {
  46        die_error("", "Invalid hash parameter.");
  47}
  48if (defined($hash_parent) && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
  49        die_error("", "Invalid parent hash parameter.");
  50}
  51if (defined($time_back) && !($time_back =~ m/^[0-9]+$/)) {
  52        die_error("", "Invalid time parameter.");
  53}
  54
  55sub git_header_html {
  56        my $status = shift || "200 OK";
  57
  58        print $cgi->header(-type=>'text/html',  -charset => 'utf-8', -status=> $status);
  59        print <<EOF;
  60<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  61<html>
  62<head>
  63        <title>git - $project $action</title>
  64        <link rel="alternate" title="$project log" href="$my_uri?p=$project;a=rss" type="application/rss+xml"/>
  65        <style type="text/css">
  66        body { font-family: sans-serif; font-size: 12px; margin:0px; }
  67        a { color:#0000cc; }
  68        a:hover { color:#880000; }
  69        a:visited { color:#880000; }
  70        a:active { color:#880000; }
  71        div.page_header {
  72                margin:15px 25px 0px; height:25px; padding:8px;
  73                font-size:18px; clear:both; font-weight:bold; background-color: #d9d8d1;
  74        }
  75        div.page_header a:visited { color:#0000cc; }
  76        div.page_nav { margin:0px 25px; padding:8px; clear:both; border:solid #d9d8d1; border-width:0px 1px; }
  77        div.page_nav a:visited { color:#0000cc; }
  78        div.page_footer {
  79                margin:0px 25px 15px; height:17px; padding:4px; padding-left:8px;
  80                clear:both; background-color: #d9d8d1;
  81        }
  82        div.page_footer_text { float:left; color:#888888; font-size:10px;}
  83        div.page_body { margin:0px 25px; padding:8px; clear:both; border: solid #d9d8d1; border-width:0px 1px; }
  84        div.title {
  85                display:block; margin:0px 25px; padding:8px; clear:both;
  86                font-weight:bold; background-color: #d9d8d1; color:#000000;
  87        }
  88        a.log_title {
  89                display:block; margin:0px 25px; padding:8px; clear:both;
  90                font-weight:bold; background-color: #d9d8d1; text-decoration:none; color:#000000;
  91        }
  92        a.log_title:hover { background-color: #c9c8c1; }
  93        a.xml_logo { float:right; border:1px solid;
  94                line-height:15px;
  95                border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e; width:35px;
  96                color:#ffffff; background-color:#ff6600;
  97                font-weight:bold; font-family:sans-serif; text-align:center;
  98                font-size:11px; display:block; text-decoration:none;
  99        }
 100        a.xml_logo:hover { background-color:#ee5500; }
 101        div.log_head {
 102                margin:0px 25px; min-height: 30px; padding:8px; clear:both;
 103                border: solid #d9d8d1; border-width:0px 1px; font-family:monospace;
 104                background-color: #edece6;
 105        }
 106        div.log_body {
 107                margin:0px 25px; padding:8px; padding-left:150px; clear:both;
 108                border:solid #d9d8d1; border-width:0px 1px;
 109        }
 110        span.log_age { position:relative; float:left; width:142px; }
 111        div.log_functions { font-size:10px; font-family:sans-serif; position:relative; float:left; width:142px; }
 112        div.signed_off { color: #a9a8a1; }
 113        </style>
 114</head>
 115<body>
 116EOF
 117        print "<div class=\"page_header\">\n" .
 118              "<a href=\"$giturl\">" .
 119              "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
 120        if ($defaultprojects ne "") {
 121                print $cgi->a({-href => "$my_uri"}, "projects") . " / ";
 122        }
 123        if ($project ne "") {
 124                print $cgi->a({-href => "$my_uri?p=$project;a=log"}, $project);
 125        }
 126        if ($action ne "") {
 127                print " / $action";
 128        }
 129        print "</div>\n";
 130}
 131
 132sub git_footer_html {
 133        print "<div class=\"page_footer\">";
 134        print "<div class=\"page_footer_text\">version $version</div>";
 135        if ($project ne '') {
 136                print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "xml_logo"}, "XML") . "\n";
 137        }
 138        print "</div>";
 139        print "</body>\n</html>";
 140}
 141
 142sub die_error {
 143        my $status = shift || "403 Forbidden";
 144        my $error = shift || "Malformed query, file missing or permission denied"; 
 145        git_header_html($status);
 146        print "<div class=\"page_body\">\n" .
 147              "<br/><br/>\n";
 148        print "$error\n";
 149        print "<br/></div>\n";
 150        git_footer_html();
 151        exit 0;
 152}
 153
 154sub git_head {
 155        my $path = shift;
 156        open(my $fd, "$projectroot/$path/HEAD") || die_error("", "Invalid project directory.");;
 157        my $head = <$fd>;
 158        close $fd;
 159        chomp $head;
 160        return $head;
 161}
 162
 163sub git_commit {
 164        my $commit = shift;
 165        my %co;
 166        my @parents;
 167
 168        open my $fd, "-|", "$gitbin/cat-file commit $commit";
 169        while (my $line = <$fd>) {
 170                chomp($line);
 171                last if $line eq "";
 172                if ($line =~ m/^tree (.*)$/) {
 173                        $co{'tree'} = $1;
 174                } elsif ($line =~ m/^parent (.*)$/) {
 175                        push @parents, $1;
 176                } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
 177                        $co{'author'} = $1;
 178                        $co{'author_epoch'} = $2;
 179                        $co{'author_tz'} = $3;
 180                        $co{'author_name'} = $co{'author'};
 181                        $co{'author_name'} =~ s/ <.*//;
 182                } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
 183                        $co{'committer'} = $1;
 184                        $co{'committer_epoch'} = $2;
 185                        $co{'committer_tz'} = $3;
 186                        $co{'committer_name'} = $co{'committer'};
 187                        $co{'committer_name'} =~ s/ <.*//;
 188                }
 189        }
 190        if (!defined($co{'tree'})) { die_error("", "Invalid commit object."); }
 191        $co{'parents'} = \@parents;
 192        $co{'parent'} = $parents[0];
 193        my (@comment) = map { chomp; $_ } <$fd>;
 194        $co{'comment'} = \@comment;
 195        $co{'title'} = $comment[0];
 196        close $fd;
 197
 198        my $age = time - $co{'committer_epoch'};
 199        $co{'age'} = $age;
 200        if ($age > 60*60*24*365*2) {
 201                $co{'age_string'} = (int $age/60/60/24/365);
 202                $co{'age_string'} .= " years ago";
 203        } elsif ($age > 60*60*24*365/12*2) {
 204                $co{'age_string'} = int $age/60/60/24/365/12;
 205                $co{'age_string'} .= " months ago";
 206        } elsif ($age > 60*60*24*7*2) {
 207                $co{'age_string'} = int $age/60/60/24/7;
 208                $co{'age_string'} .= " weeks ago";
 209        } elsif ($age > 60*60*24*2) {
 210                $co{'age_string'} = int $age/60/60/24;
 211                $co{'age_string'} .= " days ago";
 212        } elsif ($age > 60*60*2) {
 213                $co{'age_string'} = int $age/60/60;
 214                $co{'age_string'} .= " hours ago";
 215        } elsif ($age > 60*2) {
 216                $co{'age_string'} = int $age/60;
 217                $co{'age_string'} .= " minutes ago";
 218        }
 219        return %co;
 220}
 221
 222sub git_diff_html {
 223        my $from_name = shift || "/dev/null";
 224        my $to_name = shift || "/dev/null";
 225        my $from = shift;
 226        my $to = shift;
 227
 228        my $from_tmp = "/dev/null";
 229        my $to_tmp = "/dev/null";
 230        my $from_label = "/dev/null";
 231        my $to_label = "/dev/null";
 232        my $pid = $$;
 233
 234        # create tmp from-file
 235        if ($from ne "") {
 236                $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
 237                open(my $fd2, "> $from_tmp");
 238                open my $fd, "-|", "$gitbin/cat-file blob $from";
 239                my @file = <$fd>;
 240                print $fd2 @file;
 241                close $fd2;
 242                close $fd;
 243                $from_label = "a/$from_name";
 244        }
 245
 246        # create tmp to-file
 247        if ($to ne "") {
 248                $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
 249                open my $fd2, "> $to_tmp";
 250                open my $fd, "-|", "$gitbin/cat-file blob $to";
 251                my @file = <$fd>;
 252                print $fd2 @file;
 253                close $fd2;
 254                close $fd;
 255                $to_label = "b/$to_name";
 256        }
 257
 258        open my $fd, "-|", "/usr/bin/diff -u -p -L $from_label -L $to_label $from_tmp $to_tmp";
 259        print "<span style=\"color: #000099;\">===== ";
 260        if ($from ne "") {
 261                print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from"}, $from);
 262        } else {
 263                print $from_name;
 264        }
 265        print " vs ";
 266        if ($to ne "") {
 267                print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to"}, $to);
 268        } else {
 269                print $to_name;
 270        }
 271        print " =====</span>\n";
 272        while (my $line = <$fd>) {
 273                my $char = substr($line,0,1);
 274                print '<span style="color: #008800;">' if $char eq '+';
 275                print '<span style="color: #CC0000;">' if $char eq '-';
 276                print '<span style="color: #990099;">' if $char eq '@';
 277                print escapeHTML($line);
 278                print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
 279        }
 280        close $fd;
 281
 282        if ($from ne "") {
 283                unlink("$from_tmp");
 284        }
 285        if ($to ne "") {
 286                unlink("$to_tmp");
 287        }
 288}
 289
 290sub mode_str {
 291        my $perms = oct shift;
 292        my $modestr;
 293        if ($perms & 040000) {
 294                $modestr .= 'drwxrwxr-x';
 295        } else {
 296                # git cares only about the executable bit
 297                if ($perms & 0100) {
 298                        $modestr .= '-rwxrwxr-x';
 299                } else {
 300                        $modestr .= '-rw-rw-r--';
 301                };
 302        }
 303        return $modestr;
 304}
 305
 306sub date_str {
 307        my $epoch = shift;
 308        my $tz = shift || "-0000";
 309
 310        my %date;
 311        my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
 312        my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
 313        my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
 314        $date{'hour'} = $hour;
 315        $date{'minute'} = $min;
 316        $date{'mday'} = $mday;
 317        $date{'day'} = $days[$wday];
 318        $date{'month'} = $months[$mon];
 319        $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
 320        $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
 321
 322        $tz =~ m/((-|\+)[0-9][0-9])([0-9][0-9])/;
 323        my $local = $epoch + (($1 + ($2/60)) * 3600);
 324        ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
 325        $date{'hour_local'} = $hour;
 326        $date{'minute_local'} = $min;
 327        $date{'tz_local'} = $tz;
 328        return %date;
 329}
 330
 331if ($action eq "git-logo.png") {
 332        print $cgi->header(-type => 'image/png', -expires => '+1d');
 333        print   "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
 334                "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
 335                "\055\000\000\000\030\120\114\124\105\377\377\377\140\140\135\260".
 336                "\257\252\000\200\000\316\315\307\300\000\000\350\350\346\367\367".
 337                "\366\225\014\247\107\000\000\000\163\111\104\101\124\050\317\143".
 338                "\110\147\040\004\112\134\030\012\010\052\142\123\141\040\002\010".
 339                "\015\151\105\254\241\241\001\060\014\223\140\066\046\122\221\261".
 340                "\001\021\326\341\125\144\154\154\314\154\154\014\242\014\160\052".
 341                "\142\006\052\301\142\035\263\001\002\123\244\010\350\000\003\030".
 342                "\046\126\021\324\341\040\227\033\340\264\016\065\044\161\051\202".
 343                "\231\060\270\223\012\021\271\105\210\301\215\240\242\104\041\006".
 344                "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305".
 345                "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202";
 346        exit;
 347}
 348
 349# show list of default projects
 350if ($project eq "") {
 351        opendir(my $fd, "$projectroot/$defaultprojects") || die_error("", "No projects found.");
 352        my (@users) = sort grep(!/^\./, readdir($fd));
 353        closedir($fd);
 354        git_header_html();
 355        print "<div class=\"page_body\">\n";
 356        print "<br/><br/>\n";
 357        foreach my $user (@users) {
 358                opendir($fd, "$projectroot/$defaultprojects/$user");
 359                my (@repos) = sort grep(/\.git$/, readdir($fd));
 360                closedir($fd);
 361                foreach my $repo (@repos) {
 362                        if (-e "$projectroot/$defaultprojects/$user/$repo/HEAD") {
 363                                print $cgi->a({-href => "$my_uri?p=$defaultprojects/$user/$repo;a=log"}, "$defaultprojects/$user/$repo") . "<br/>\n";
 364                        }
 365                }
 366        }
 367        print "<br/></div>";
 368        git_footer_html();
 369        exit;
 370}
 371
 372if (!defined($action)) {
 373        $action = "log";
 374}
 375
 376if (!defined($time_back)) {
 377        $time_back = 1;
 378}
 379
 380if ($action eq "blob") {
 381        git_header_html();
 382        print "<div class=\"page_nav\">\n";
 383        print "<br/><br/></div>\n";
 384        print "<div class=\"title\">$hash</div>\n";
 385        print "<div class=\"page_body\"><pre><br/><br/>\n";
 386        open(my $fd, "-|", "$gitbin/cat-file blob $hash");
 387        my $nr;
 388        while (my $line = <$fd>) {
 389                $nr++;
 390                printf "<span style =\"color: #999999;\">%4i\t</span>%s", $nr, escapeHTML($line);;
 391        }
 392        close $fd;
 393        print "<br/><br/></pre>\n";
 394        print "</div>";
 395        git_footer_html();
 396} elsif ($action eq "tree") {
 397        if ($hash eq "") {
 398                $hash = git_head($project);
 399        }
 400        open my $fd, "-|", "$gitbin/ls-tree $hash";
 401        my (@entries) = map { chomp; $_ } <$fd>;
 402        close $fd;
 403        git_header_html();
 404        print "<div class=\"page_nav\">\n";
 405        print "<br/><br/></div>\n";
 406        print "<div class=\"title\">$hash</div>\n";
 407        print "<div class=\"page_body\">\n";
 408        print "<br/><pre>\n";
 409        foreach my $line (@entries) {
 410                #'100644        blob    0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa        panic.c'
 411                $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
 412                my $t_mode = $1;
 413                my $t_type = $2;
 414                my $t_hash = $3;
 415                my $t_name = $4;
 416                if ($t_type eq "blob") {
 417                        print mode_str($t_mode). " $t_name (" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash"}, "view") . ")\n";
 418                } elsif ($t_type eq "tree") {
 419                        print mode_str($t_mode). " $t_name (" . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash"}, "view") . ")\n";
 420                }
 421        }
 422        print "</pre>\n";
 423        print "<br/></div>";
 424        git_footer_html();
 425} elsif ($action eq "log" || $action eq "rss") {
 426        open my $fd, "-|", "$gitbin/rev-list " . git_head($project);
 427        my (@revlist) = map { chomp; $_ } <$fd>;
 428        close $fd;
 429
 430        if ($action eq "log") {
 431                git_header_html();
 432                print "<div class=\"page_nav\">\n";
 433                print "view  ";
 434                print $cgi->a({-href => "$my_uri?p=$project;a=log"}, "last day") . " | \n" .
 435                      $cgi->a({-href => "$my_uri?p=$project;a=log;t=7"}, "week") . " | \n" .
 436                      $cgi->a({-href => "$my_uri?p=$project;a=log;t=31"}, "month") . " | \n" .
 437                      $cgi->a({-href => "$my_uri?p=$project;a=log;t=365"}, "year") . " | \n" .
 438                      $cgi->a({-href => "$my_uri?p=$project;a=log;t=0"}, "all") . "<br/>\n";
 439                print "<br/><br/>\n" .
 440                      "</div>\n";
 441        } elsif ($action eq "rss") {
 442                print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
 443                print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
 444                      "<rss version=\"0.91\">\n";
 445                print "<channel>\n";
 446                print "<title>$project</title>\n".
 447                      "<link> " . $my_url . "/$project/log</link>\n".
 448                      "<description>$project log</description>\n".
 449                      "<language>en</language>\n";
 450        }
 451
 452        for (my $i = 0; $i <= $#revlist; $i++) {
 453                my $commit = $revlist[$i];
 454                my %co = git_commit($commit);
 455                my %ad = date_str($co{'author_epoch'});
 456                if ($action eq "log") {
 457                if ($time_back > 0 && $co{'age'} > $time_back*60*60*24) {
 458                                if ($i == 0) {
 459                                        print "<div class=\"page_body\"> Last change " . $co{'age_string'} . ".<br/><br/></div>\n";
 460                                }
 461                                last;
 462                        }
 463                        print "<div><a href=\"$my_uri?p=$project;a=commit;h=$commit\" class=\"log_title\">\n" .
 464                              "<span class=\"log_age\">" . $co{'age_string'} . "</span>\n" . escapeHTML($co{'title'}) . "</a>\n" .
 465                              "</div>\n";
 466                        print "<div class=\"log_head\">\n" .
 467                              "<div class=\"log_functions\">\n" .
 468                              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "view commit") . "<br/>\n" .
 469                              $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "view diff") . "<br/>\n" .
 470                              "</div>\n" .
 471                              escapeHTML($co{'author_name'}) .  " [" . $ad{'rfc2822'} . "]<br/>\n" .
 472                              "</div>\n" .
 473                              "<div class=\"log_body\">\n";
 474                        my $comment = $co{'comment'};
 475                        foreach my $line (@$comment) {
 476                                if ($line =~ m/^(signed-off|acked)-by:/i) {
 477                                        print '<div class="signed_off">' . escapeHTML($line) . "<br/></div>\n";
 478                                } else {
 479                                        print escapeHTML($line) . "<br/>\n";
 480                                }
 481                        }
 482                        print "<br/><br/>\n" .
 483                              "</div>\n";
 484                } elsif ($action eq "rss") {
 485                        last if ($i >= 20);
 486                        print "<item>\n" .
 487                              "\t<title>" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'min'}) . " - " . escapeHTML($co{'title'}) . "</title>\n" .
 488                              "\t<link> " . $my_url . "?p=$project;a=commit;h=$commit</link>\n" .
 489                              "\t<description>";
 490                        my $comment = $co{'comment'};
 491                        foreach my $line (@$comment) {
 492                                print escapeHTML($line) . "\n";
 493                        }
 494                        print "\t</description>\n" .
 495                              "</item>\n";
 496                }
 497        }
 498        if ($action eq "log") {
 499                git_footer_html();
 500        } elsif ($action eq "rss") {
 501                print "</channel></rss>";
 502        }
 503} elsif ($action eq "commit") {
 504        my %co = git_commit($hash);
 505        my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
 506        my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
 507        open my $fd, "-|", "$gitbin/diff-tree -r " . $co{'parent'} . " $hash";
 508        my (@difftree) = map { chomp; $_ } <$fd>;
 509        close $fd;
 510
 511        git_header_html();
 512        print "<div class=\"page_nav\"> view\n" .
 513              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
 514              $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . "\n" .
 515              "<br/><br/></div>\n";
 516        print "<a class=\"log_title\" href=\"$my_uri?p=$project;a=commitdiff;h=$hash\">$co{'title'}</a>\n";
 517        print "<div class=\"log_head\">\n";
 518        print "author &nbsp; &nbsp; &nbsp;" . escapeHTML($co{'author'}) . "<br/>\n";
 519        print "author-time " . $ad{'rfc2822'};
 520        if ($ad{'hour_local'} < 6) { print "<span style=\"color: #cc0000;\">"; }
 521        printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
 522        if ($ad{'hour_local'} < 6 ) { print "</span>"; }
 523        print "<br/>\n";
 524        print "committer &nbsp; " . escapeHTML($co{'committer'}) . "<br/>\n";
 525        print "commit-time " . $ad{'rfc2822'};
 526        printf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'});
 527        print "<br/>\n";
 528        print "commit &nbsp &nbsp; &nbsp;$hash<br/>\n";
 529        print "tree &nbsp; &nbsp; &nbsp; &nbsp" . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'}"}, $co{'tree'}) . "<br/>\n";
 530        my $parents  = $co{'parents'};
 531        foreach my $par (@$parents) {
 532                print "parent &nbsp; &nbsp &nbsp" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, $par) . "<br/>\n";
 533        }
 534        print "</div>\n";
 535        print "<div class=\"page_body\">\n";
 536        my $comment = $co{'comment'};
 537        foreach my $line (@$comment) {
 538                if ($line =~ m/(signed-off|acked)-by:/i) {
 539                        print '<div class="signed_off">' . escapeHTML($line) . "<br/></div>\n";
 540                } else {
 541                        print escapeHTML($line) . "<br/>\n";
 542                }
 543        }
 544        print "<br/><br/>\n";
 545        print "<pre>\n";
 546        foreach my $line (@difftree) {
 547                # '*100644->100644      blob    9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596      net/ipv4/route.c'
 548                # '+100644      blob    4a83ab6cd565d21ab0385bac6643826b83c2fcd4        arch/arm/lib/bitops.h'
 549                $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
 550                my $op = $1;
 551                my $mode = $2;
 552                my $type = $3;
 553                my $id = $4;
 554                my $file = $5;
 555                $mode =~ m/^([0-7]{6})/;
 556                my $modestr = mode_str($1);
 557                if ($type eq "blob") {
 558                        if ($op eq "+") {
 559                                print "$modestr $file" . "[new] " .
 560                                      "(" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, "view") . ")\n";
 561                        } elsif ($op eq "-") {
 562                                print "$modestr $file" . "[removed] " .
 563                                      "(" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, "view") . ")\n";
 564                        } elsif ($op eq "*") {
 565                                $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
 566                                my $from = $1;
 567                                my $to = $2;
 568                                print "$modestr $file " .
 569                                      "(" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to"}, "view") . ")" .
 570                                      "(" . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to;hp=$from"}, "diff") . ")" .
 571                                      "(" . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . ")\n";
 572                        }
 573                }
 574        }
 575        print "</pre>\n" .
 576              "<br/></div>\n";
 577        git_footer_html();
 578} elsif ($action eq "blobdiff") {
 579        git_header_html();
 580        print "<div class=\"page_nav\">\n";
 581        print "<br/><br/></div>\n";
 582        print "<div class=\"title\">$hash vs $hash_parent</div>\n";
 583        print "<div class=\"page_body\"><br/><br/>\n" .
 584              "<pre>\n";
 585        git_diff_html($hash_parent, $hash, $hash_parent, $hash);
 586        print "</pre>\n" .
 587              "<br/></div>";
 588        git_footer_html();
 589} elsif ($action eq "commitdiff") {
 590        my %co = git_commit($hash);
 591        open my $fd, "-|", "$gitbin/diff-tree -r " . $co{'parent'} . " $hash";
 592        my (@difftree) = map { chomp; $_ } <$fd>;
 593        close $fd;
 594
 595        git_header_html();
 596        print "<div class=\"page_nav\"> view\n" .
 597              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
 598              $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . "\n" .
 599              "<br/><br/></div>\n";
 600        print $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "log_title"}, $co{'title'}) ."\n";
 601        print "<div class=\"page_body\">\n" .
 602              "<pre>\n";
 603        foreach my $line (@difftree) {
 604                # '*100644->100644      blob    8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154      Makefile'
 605                $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
 606                my $op = $1;
 607                my $mode = $2;
 608                my $type = $3;
 609                my $id = $4;
 610                my $file = $5;
 611                if ($type eq "blob") {
 612                        if ($op eq "+") {
 613                                git_diff_html("", $file, "", $id);
 614                        } elsif ($op eq "-") {
 615                                git_diff_html($file, "", $id, "");
 616                        } elsif ($op eq "*") {
 617                                $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
 618                                git_diff_html($file, $file, $1, $2);
 619                        }
 620                }
 621        }
 622        print "<br/></pre>\n";
 623        print "</div>";
 624        git_footer_html();
 625} elsif ($action eq "history") {
 626        if (!(defined($hash))) {
 627                $hash = git_head($project);
 628        }
 629        open my $fd, "-|", "$gitbin/rev-list $hash";
 630        my (@revlist) = map { chomp; $_ } <$fd>;
 631        close $fd;
 632
 633        git_header_html();
 634        print "<div class=\"page_nav\">\n";
 635        print "<br/><br/></div>\n";
 636        print "<div class=\"title\">$file_name</div>\n";
 637        print "<div class=\"page_body\">\n" .
 638              "<pre>\n";
 639        foreach my $rev (@revlist) {
 640                my %co = git_commit($rev);
 641                my $parents  = $co{'parents'};
 642                my $found = 0;
 643                foreach my $parent (@$parents) {
 644                        open $fd, "-|", "$gitbin/diff-tree -r $parent $rev $file_name";
 645                        my (@difftree) = map { chomp; $_ } <$fd>;
 646                        close $fd;
 647
 648                        foreach my $line (@difftree) {
 649                                $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
 650                                my $file = $5;
 651                                if ($file eq $file_name) {
 652                                        $found = 1;
 653                                        last;
 654                                }
 655                        }
 656                }
 657                if ($found) {
 658                        print $co{'age_string'} . "\t " . $co{'author_name'} . "  - " . $co{'title'} .
 659                              " (" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$rev"}, "view") .")\n";
 660                }
 661        }
 662        print "<br/></pre>\n";
 663        print "</div>";
 664        git_footer_html();
 665} else {
 666        die_error("", "unknown action");
 667}