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