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