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