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