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