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