gitweb.cgion commit v229 (d05c19e)
   1#!/usr/bin/perl
   2
   3# gitweb - 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 program is licensed under the GPL v2, or a later version
   9
  10use strict;
  11use warnings;
  12use CGI qw(:standard :escapeHTML -nosticky);
  13use CGI::Util qw(unescape);
  14use CGI::Carp qw(fatalsToBrowser);
  15use Fcntl ':mode';
  16
  17my $cgi = new CGI;
  18my $version =           "229";
  19my $my_url =            $cgi->url();
  20my $my_uri =            $cgi->url(-absolute => 1);
  21my $rss_link = "";
  22
  23# absolute fs-path which will be prepended to the project path
  24my $projectroot =       "/pub/scm";
  25
  26# location of the git-core binaries
  27my $gitbin =            "/usr/bin";
  28
  29# location for temporary files needed for diffs
  30my $git_temp =          "/tmp/gitweb";
  31
  32# target of the home link on top of all pages
  33my $home_link =         $my_uri;
  34
  35# html text to include at home page
  36my $home_text =         "indextext.html";
  37
  38# source of projects list
  39#my $projects_list = $projectroot;
  40my $projects_list = "index/index.aux";
  41
  42# input validation and dispatch
  43my $action = $cgi->param('a');
  44if (defined $action) {
  45        if ($action =~ m/[^0-9a-zA-Z\.\-_]+/) {
  46                undef $action;
  47                die_error(undef, "Invalid action parameter.");
  48        }
  49        if ($action eq "git-logo.png") {
  50                git_logo();
  51                exit;
  52        } elsif ($action eq "opml") {
  53                git_opml();
  54                exit;
  55        }
  56}
  57
  58my $project = $cgi->param('p');
  59if (defined $project) {
  60        if ($project =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
  61                undef $project;
  62                die_error(undef, "Non-canonical project parameter.");
  63        }
  64        if ($project =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~]/) {
  65                undef $project;
  66                die_error(undef, "Invalid character in project parameter.");
  67        }
  68        if (!(-d "$projectroot/$project")) {
  69                undef $project;
  70                die_error(undef, "No such directory.");
  71        }
  72        if (!(-e "$projectroot/$project/HEAD")) {
  73                undef $project;
  74                die_error(undef, "No such project.");
  75        }
  76        $rss_link = "<link rel=\"alternate\" title=\"$project log\" href=\"$my_uri?p=$project;a=rss\" type=\"application/rss+xml\"/>";
  77        $ENV{'GIT_DIR'} = "$projectroot/$project";
  78} else {
  79        git_project_list();
  80        exit;
  81}
  82
  83my $file_name = $cgi->param('f');
  84if (defined $file_name) {
  85        if ($file_name =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
  86                undef $file_name;
  87                die_error(undef, "Non-canonical file parameter.");
  88        }
  89        if ($file_name =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~\:\!]/) {
  90                undef $file_name;
  91                die_error(undef, "Invalid character in file parameter.");
  92        }
  93}
  94
  95my $hash = $cgi->param('h');
  96if (defined $hash) {
  97        if (!($hash =~ m/^[0-9a-fA-F]{40}$/)) {
  98                if ($hash =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
  99                        undef $hash;
 100                        die_error(undef, "Non-canonical hash parameter.");
 101                }
 102                if ($hash =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~\:\!]/) {
 103                        undef $hash;
 104                        die_error(undef, "Invalid character in hash parameter.");
 105                }
 106                # replace branch-name with hash
 107                my $branchlist = git_read_refs("refs/heads");
 108                foreach my $entry (@$branchlist) {
 109                        my %branch = %$entry;
 110                        if ($branch{'name'} eq $hash) {
 111                                $hash = $branch{'id'};
 112                                last;
 113                        }
 114                }
 115        }
 116}
 117
 118my $hash_parent = $cgi->param('hp');
 119if (defined $hash_parent && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
 120        undef $hash_parent;
 121        die_error(undef, "Invalid hash_parent parameter.");
 122}
 123
 124my $hash_base = $cgi->param('hb');
 125if (defined $hash_base && !($hash_base =~ m/^[0-9a-fA-F]{40}$/)) {
 126        undef $hash_base;
 127        die_error(undef, "Invalid parent hash parameter.");
 128}
 129
 130my $page = $cgi->param('pg');
 131if (defined $page) {
 132        if ($page =~ m/^[^0-9]+$/) {
 133                undef $page;
 134                die_error(undef, "Invalid page parameter.");
 135        }
 136}
 137
 138my $searchtext = $cgi->param('s');
 139if (defined $searchtext) {
 140        if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
 141                undef $searchtext;
 142                die_error(undef, "Invalid search parameter.");
 143        }
 144        $searchtext = quotemeta $searchtext;
 145}
 146
 147if (!defined $action || $action eq "summary") {
 148        git_summary();
 149        exit;
 150} elsif ($action eq "branches") {
 151        git_branches();
 152        exit;
 153} elsif ($action eq "tags") {
 154        git_tags();
 155        exit;
 156} elsif ($action eq "blob") {
 157        git_blob();
 158        exit;
 159} elsif ($action eq "blob_plain") {
 160        git_blob_plain();
 161        exit;
 162} elsif ($action eq "tree") {
 163        git_tree();
 164        exit;
 165} elsif ($action eq "rss") {
 166        git_rss();
 167        exit;
 168} elsif ($action eq "commit") {
 169        git_commit();
 170        exit;
 171} elsif ($action eq "log") {
 172        git_log();
 173        exit;
 174} elsif ($action eq "blobdiff") {
 175        git_blobdiff();
 176        exit;
 177} elsif ($action eq "blobdiff_plain") {
 178        git_blobdiff_plain();
 179        exit;
 180} elsif ($action eq "commitdiff") {
 181        git_commitdiff();
 182        exit;
 183} elsif ($action eq "commitdiff_plain") {
 184        git_commitdiff_plain();
 185        exit;
 186} elsif ($action eq "history") {
 187        git_history();
 188        exit;
 189} elsif ($action eq "search") {
 190        git_search();
 191        exit;
 192} elsif ($action eq "shortlog") {
 193        git_shortlog();
 194        exit;
 195} else {
 196        undef $action;
 197        die_error(undef, "Unknown action.");
 198        exit;
 199}
 200
 201sub git_header_html {
 202        my $status = shift || "200 OK";
 203
 204        my $title = "git";
 205        if (defined $project) {
 206                $title .= " - $project";
 207                if (defined $action) {
 208                        $title .= "/$action";
 209                }
 210        }
 211        print $cgi->header(-type=>'text/html',  -charset => 'utf-8', -status=> $status);
 212        print <<EOF;
 213<?xml version="1.0" encoding="utf-8"?>
 214<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 215<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
 216<!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
 217<head>
 218<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
 219<meta name="robots" content="index, nofollow"/>
 220<title>$title</title>
 221$rss_link
 222<style type="text/css">
 223body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
 224a { color:#0000cc; }
 225a:hover, a:visited, a:active { color:#880000; }
 226div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; }
 227div.page_header a:visited { color:#0000cc; }
 228div.page_header a:hover { color:#880000; }
 229div.page_nav { padding:8px; }
 230div.page_nav a:visited { color:#0000cc; }
 231div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
 232div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
 233div.page_footer_text { float:left; color:#555555; font-style:italic; }
 234div.page_body { padding:8px; }
 235div.title, a.title {
 236        display:block; padding:6px 8px;
 237        font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
 238}
 239a.title:hover { background-color: #d9d8d1; }
 240div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; }
 241div.log_body { padding:8px 8px 8px 150px; }
 242span.age { position:relative; float:left; width:142px; font-style:italic; }
 243div.log_link {
 244        padding:0px 8px;
 245        font-size:10px; font-family:sans-serif; font-style:normal;
 246        position:relative; float:left; width:136px;
 247}
 248div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; }
 249a.list { text-decoration:none; color:#000000; }
 250a.list:hover { text-decoration:underline; color:#880000; }
 251table { padding:8px 4px; }
 252th { padding:2px 5px; font-size:12px; text-align:left; }
 253tr.light:hover { background-color:#edece6; }
 254tr.dark { background-color:#f6f6f0; }
 255tr.dark:hover { background-color:#edece6; }
 256td { padding:2px 5px; font-size:12px; vertical-align:top; }
 257td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; }
 258div.pre { font-family:monospace; font-size:12px; white-space:pre; }
 259div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
 260div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
 261div.search { margin:4px 8px; position:absolute; top:56px; right:12px }
 262a.linenr { color:#999999; text-decoration:none }
 263a.rss_logo {
 264        float:right; padding:3px 0px; width:35px; line-height:10px;
 265        border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
 266        color:#ffffff; background-color:#ff6600;
 267        font-weight:bold; font-family:sans-serif; font-size:10px;
 268        text-align:center; text-decoration:none;
 269}
 270a.rss_logo:hover { background-color:#ee5500; }
 271</style>
 272</head>
 273<body>
 274EOF
 275        print "<div class=\"page_header\">\n" .
 276              "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
 277              "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
 278              "</a>\n";
 279        print $cgi->a({-href => $home_link}, "projects") . " / ";
 280        if (defined $project) {
 281                print $cgi->a({-href => "$my_uri?p=$project;a=summary"}, escapeHTML($project));
 282                if (defined $action) {
 283                        print " / $action";
 284                }
 285                print "\n";
 286                if (!defined $searchtext) {
 287                        $searchtext = "";
 288                }
 289                $cgi->param("a", "search");
 290                print $cgi->startform(-method => "get", -action => "$my_uri") .
 291                      "<div class=\"search\">\n" .
 292                      $cgi->hidden(-name => "p") . "\n" .
 293                      $cgi->hidden(-name => "a") . "\n" .
 294                      $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
 295                      "</div>" .
 296                      $cgi->end_form() . "\n";
 297        }
 298        print "</div>\n";
 299}
 300
 301sub git_footer_html {
 302        print "<div class=\"page_footer\">\n";
 303        if (defined $project) {
 304                my $descr = git_read_description($project);
 305                if (defined $descr) {
 306                        print "<div class=\"page_footer_text\">" . escapeHTML($descr) . "</div>\n";
 307                }
 308                print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
 309        } else {
 310                print $cgi->a({-href => "$my_uri?a=opml", -class => "rss_logo"}, "RSS") . "\n";
 311        }
 312        print "</div>\n" .
 313              "</body>\n" .
 314              "</html>";
 315}
 316
 317sub die_error {
 318        my $status = shift || "403 Forbidden";
 319        my $error = shift || "Malformed query, file missing or permission denied"; 
 320
 321        git_header_html($status);
 322        print "<div class=\"page_body\">\n" .
 323              "<br/><br/>\n" .
 324              "$status - $error\n" .
 325              "<br/>\n" .
 326              "</div>\n";
 327        git_footer_html();
 328        exit;
 329}
 330
 331sub git_get_type {
 332        my $hash = shift;
 333
 334        open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
 335        my $type = <$fd>;
 336        close $fd;
 337        chomp $type;
 338        return $type;
 339}
 340
 341sub git_read_hash {
 342        my $path = shift;
 343
 344        open my $fd, "$projectroot/$path" or return undef;
 345        my $head = <$fd>;
 346        close $fd;
 347        chomp $head;
 348        if ($head =~ m/^[0-9a-fA-F]{40}$/) {
 349                return $head;
 350        }
 351}
 352
 353sub git_read_description {
 354        my $path = shift;
 355
 356        open my $fd, "$projectroot/$path/description" or return undef;
 357        my $descr = <$fd>;
 358        close $fd;
 359        chomp $descr;
 360        return $descr;
 361}
 362
 363sub git_read_tag {
 364        my $tag_id = shift;
 365        my %tag;
 366
 367        open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
 368        while (my $line = <$fd>) {
 369                chomp $line;
 370                if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
 371                        $tag{'object'} = $1;
 372                } elsif ($line =~ m/^type (.+)$/) {
 373                        $tag{'type'} = $1;
 374                } elsif ($line =~ m/^tag (.+)$/) {
 375                        $tag{'name'} = $1;
 376                }
 377        }
 378        close $fd or return;
 379        if (!defined $tag{'name'}) {
 380                return
 381        };
 382        return %tag
 383}
 384
 385sub git_read_commit {
 386        my $commit_id = shift;
 387        my $commit_text = shift;
 388
 389        my @commit_lines;
 390        my %co;
 391        my @parents;
 392
 393        if (defined $commit_text) {
 394                @commit_lines = @$commit_text;
 395        } else {
 396                open my $fd, "-|", "$gitbin/git-cat-file commit $commit_id" or return;
 397                @commit_lines = map { chomp; $_ } <$fd>;
 398                close $fd or return;
 399        }
 400        while (my $line = shift @commit_lines) {
 401                last if $line eq "\n";
 402                if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
 403                        $co{'tree'} = $1;
 404                } elsif ($line =~ m/^parent ([0-9a-fA-F]{40})$/) {
 405                        push @parents, $1;
 406                } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
 407                        $co{'author'} = $1;
 408                        $co{'author_epoch'} = $2;
 409                        $co{'author_tz'} = $3;
 410                        if ($co{'author'} =~ m/^([^<]+) </) {
 411                                $co{'author_name'} = $1;
 412                        } else {
 413                                $co{'author_name'} = $co{'author'};
 414                        }
 415                } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
 416                        $co{'committer'} = $1;
 417                        $co{'committer_epoch'} = $2;
 418                        $co{'committer_tz'} = $3;
 419                        $co{'committer_name'} = $co{'committer'};
 420                        $co{'committer_name'} =~ s/ <.*//;
 421                }
 422        }
 423        if (!defined $co{'tree'}) {
 424                return undef
 425        };
 426        $co{'id'} = $commit_id;
 427        $co{'parents'} = \@parents;
 428        $co{'parent'} = $parents[0];
 429        $co{'comment'} = \@commit_lines;
 430        foreach my $title (@commit_lines) {
 431                if ($title ne "") {
 432                        $co{'title'} = chop_str($title, 80);
 433                        # remove leading stuff of merges to make the interesting part visible
 434                        if (length($title) > 50) {
 435                                $title =~ s/^Automatic //;
 436                                $title =~ s/^merge (of|with) /Merge ... /i;
 437                                if (length($title) > 50) {
 438                                        $title =~ s/(http|rsync):\/\///;
 439                                }
 440                                if (length($title) > 50) {
 441                                        $title =~ s/(master|www|rsync)\.//;
 442                                }
 443                                if (length($title) > 50) {
 444                                        $title =~ s/kernel.org:?//;
 445                                }
 446                                if (length($title) > 50) {
 447                                        $title =~ s/\/pub\/scm//;
 448                                }
 449                        }
 450                        $co{'title_short'} = chop_str($title, 50);
 451                        last;
 452                }
 453        }
 454
 455        my $age = time - $co{'committer_epoch'};
 456        $co{'age'} = $age;
 457        if ($age > 60*60*24*365*2) {
 458                $co{'age_string'} = (int $age/60/60/24/365);
 459                $co{'age_string'} .= " years ago";
 460        } elsif ($age > 60*60*24*(365/12)*2) {
 461                $co{'age_string'} = int $age/60/60/24/(365/12);
 462                $co{'age_string'} .= " months ago";
 463        } elsif ($age > 60*60*24*7*2) {
 464                $co{'age_string'} = int $age/60/60/24/7;
 465                $co{'age_string'} .= " weeks ago";
 466        } elsif ($age > 60*60*24*2) {
 467                $co{'age_string'} = int $age/60/60/24;
 468                $co{'age_string'} .= " days ago";
 469        } elsif ($age > 60*60*2) {
 470                $co{'age_string'} = int $age/60/60;
 471                $co{'age_string'} .= " hours ago";
 472        } elsif ($age > 60*2) {
 473                $co{'age_string'} = int $age/60;
 474                $co{'age_string'} .= " min ago";
 475        } elsif ($age > 2) {
 476                $co{'age_string'} = int $age;
 477                $co{'age_string'} .= " sec ago";
 478        } else {
 479                $co{'age_string'} .= " right now";
 480        }
 481        my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
 482        if ($age > 60*60*24*7*2) {
 483                $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon, $mday;
 484                $co{'age_string_age'} = $co{'age_string'};
 485        } else {
 486                $co{'age_string_date'} = $co{'age_string'};
 487                $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon, $mday;
 488        }
 489        return %co;
 490}
 491
 492sub git_diff_print {
 493        my $from = shift;
 494        my $from_name = shift;
 495        my $to = shift;
 496        my $to_name = shift;
 497        my $format = shift || "html";
 498
 499        my $from_tmp = "/dev/null";
 500        my $to_tmp = "/dev/null";
 501        my $pid = $$;
 502
 503        # create tmp from-file
 504        if (defined $from) {
 505                $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
 506                open my $fd2, "> $from_tmp";
 507                open my $fd, "-|", "$gitbin/git-cat-file blob $from";
 508                my @file = <$fd>;
 509                print $fd2 @file;
 510                close $fd2;
 511                close $fd;
 512        }
 513
 514        # create tmp to-file
 515        if (defined $to) {
 516                $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
 517                open my $fd2, "> $to_tmp";
 518                open my $fd, "-|", "$gitbin/git-cat-file blob $to";
 519                my @file = <$fd>;
 520                print $fd2 @file;
 521                close $fd2;
 522                close $fd;
 523        }
 524
 525        open my $fd, "-|", "/usr/bin/diff -u -p -L $from_name -L $to_name $from_tmp $to_tmp";
 526        if ($format eq "plain") {
 527                undef $/;
 528                print <$fd>;
 529                $/ = "\n";
 530        } else {
 531                while (my $line = <$fd>) {
 532                        chomp($line);
 533                        my $char = substr($line, 0, 1);
 534                        my $color = "";
 535                        if ($char eq '+') {
 536                                $color = " style=\"color:#008800;\"";
 537                        } elsif ($char eq "-") {
 538                                $color = " style=\"color:#cc0000;\"";
 539                        } elsif ($char eq "@") {
 540                                $color = " style=\"color:#990099;\"";
 541                        } elsif ($char eq "\\") {
 542                                # skip errors
 543                                next;
 544                        }
 545                        while ((my $pos = index($line, "\t")) != -1) {
 546                                if (my $count = (8 - (($pos-1) % 8))) {
 547                                        my $spaces = ' ' x $count;
 548                                        $line =~ s/\t/$spaces/;
 549                                }
 550                        }
 551                        print "<div class=\"pre\"$color>" . escapeHTML($line) . "</div>\n";
 552                }
 553        }
 554        close $fd;
 555
 556        if (defined $from) {
 557                unlink($from_tmp);
 558        }
 559        if (defined $to) {
 560                unlink($to_tmp);
 561        }
 562}
 563
 564sub mode_str {
 565        my $mode = oct shift;
 566
 567        if (S_ISDIR($mode & S_IFMT)) {
 568                return 'drwxr-xr-x';
 569        } elsif (S_ISLNK($mode)) {
 570                return 'lrwxrwxrwx';
 571        } elsif (S_ISREG($mode)) {
 572                # git cares only about the executable bit
 573                if ($mode & S_IXUSR) {
 574                        return '-rwxr-xr-x';
 575                } else {
 576                        return '-rw-r--r--';
 577                };
 578        } else {
 579                return '----------';
 580        }
 581}
 582
 583sub chop_str {
 584        my $str = shift;
 585        my $len = shift;
 586        my $add_len = shift || 10;
 587
 588        $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})/;
 589        my $chopped = $1;
 590        if ($chopped ne $str) {
 591                $chopped .= " ...";
 592        }
 593        return $chopped;
 594}
 595
 596sub file_type {
 597        my $mode = oct shift;
 598
 599        if (S_ISDIR($mode & S_IFMT)) {
 600                return "directory";
 601        } elsif (S_ISLNK($mode)) {
 602                return "symlink";
 603        } elsif (S_ISREG($mode)) {
 604                return "file";
 605        } else {
 606                return "unknown";
 607        }
 608}
 609
 610sub date_str {
 611        my $epoch = shift;
 612        my $tz = shift || "-0000";
 613
 614        my %date;
 615        my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
 616        my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
 617        my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
 618        $date{'hour'} = $hour;
 619        $date{'minute'} = $min;
 620        $date{'mday'} = $mday;
 621        $date{'day'} = $days[$wday];
 622        $date{'month'} = $months[$mon];
 623        $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
 624        $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
 625
 626        $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
 627        my $local = $epoch + ((int $1 + ($2/60)) * 3600);
 628        ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
 629        $date{'hour_local'} = $hour;
 630        $date{'minute_local'} = $min;
 631        $date{'tz_local'} = $tz;
 632        return %date;
 633}
 634
 635# git-logo (cached in browser for one day)
 636sub git_logo {
 637        print $cgi->header(-type => 'image/png', -expires => '+1d');
 638        # cat git-logo.png | hexdump -e '16/1 " %02x"  "\n"' | sed 's/ /\\x/g'
 639        print   "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
 640                "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
 641                "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
 642                "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
 643                "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
 644                "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
 645                "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
 646                "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
 647                "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
 648                "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
 649                "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
 650                "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
 651                "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
 652}
 653
 654sub get_file_owner {
 655        my $path = shift;
 656
 657        my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
 658        my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
 659        if (!defined $gcos) {
 660                return undef;
 661        }
 662        my $owner = $gcos;
 663        $owner =~ s/[,;].*$//;
 664        return $owner;
 665}
 666
 667sub git_read_projects {
 668        my @list;
 669
 670        if (-d $projects_list) {
 671                # search in directory
 672                my $dir = $projects_list;
 673                opendir my $dh, $dir or return undef;
 674                while (my $dir = readdir($dh)) {
 675                        if (-e "$projectroot/$dir/HEAD") {
 676                                my $pr = {
 677                                        path => $dir,
 678                                };
 679                                push @list, $pr
 680                        }
 681                }
 682                closedir($dh);
 683        } elsif (-f $projects_list) {
 684                # read from file(url-encoded):
 685                # 'git%2Fgit.git Linus+Torvalds'
 686                # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
 687                # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
 688                open my $fd , $projects_list or return undef;
 689                while (my $line = <$fd>) {
 690                        chomp $line;
 691                        my ($path, $owner) = split ' ', $line;
 692                        $path = unescape($path);
 693                        $owner = unescape($owner);
 694                        if (!defined $path) {
 695                                next;
 696                        }
 697                        if (-e "$projectroot/$path/HEAD") {
 698                                my $pr = {
 699                                        path => $path,
 700                                        owner => $owner,
 701                                };
 702                                push @list, $pr
 703                        }
 704                }
 705                close $fd;
 706        }
 707        @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
 708        return @list;
 709}
 710
 711sub git_project_list {
 712        my @list = git_read_projects();
 713        if (!@list) {
 714                die_error(undef, "No project found.");
 715        }
 716        git_header_html();
 717        if (-f $home_text) {
 718                print "<div class=\"index_include\">\n";
 719                open (my $fd, $home_text);
 720                print <$fd>;
 721                close $fd;
 722                print "</div>\n";
 723        }
 724        print "<table cellspacing=\"0\">\n" .
 725              "<tr>\n" .
 726              "<th>Project</th>\n" .
 727              "<th>Description</th>\n" .
 728              "<th>Owner</th>\n" .
 729              "<th>last change</th>\n" .
 730              "<th></th>\n" .
 731              "</tr>\n";
 732        my $alternate = 0;
 733        foreach my $pr (@list) {
 734                my %proj = %$pr;
 735                my $head = git_read_hash("$proj{'path'}/HEAD");
 736                if (!defined $head) {
 737                        next;
 738                }
 739                $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
 740                my %co = git_read_commit($head);
 741                if (!%co) {
 742                        next;
 743                }
 744                my $descr = git_read_description($proj{'path'}) || "";
 745                $descr = chop_str($descr, 25, 5);
 746                # get directory owner if not already specified
 747                if (!defined $proj{'owner'}) {
 748                        $proj{'owner'} = get_file_owner("$projectroot/$proj{'path'}") || "";
 749                }
 750                if ($alternate) {
 751                        print "<tr class=\"dark\">\n";
 752                } else {
 753                        print "<tr class=\"light\">\n";
 754                }
 755                $alternate ^= 1;
 756                print "<td>" . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary", -class => "list"}, escapeHTML($proj{'path'})) . "</td>\n" .
 757                      "<td>$descr</td>\n" .
 758                      "<td><i>" . chop_str($proj{'owner'}, 15) . "</i></td>\n";
 759                my $colored_age;
 760                if ($co{'age'} < 60*60*2) {
 761                        $colored_age = "<span style =\"color: #009900;\"><b><i>$co{'age_string'}</i></b></span>";
 762                } elsif ($co{'age'} < 60*60*24*2) {
 763                        $colored_age = "<span style =\"color: #009900;\"><i>$co{'age_string'}</i></span>";
 764                } else {
 765                        $colored_age = "<i>$co{'age_string'}</i>";
 766                }
 767                print "<td>$colored_age</td>\n" .
 768                      "<td class=\"link\">" .
 769                      $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary"}, "summary") .
 770                      " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=shortlog"}, "shortlog") .
 771                      " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=log"}, "log") .
 772                      "</td>\n" .
 773                      "</tr>\n";
 774        }
 775        print "</table>\n";
 776        git_footer_html();
 777}
 778
 779sub git_read_refs {
 780        my $ref_dir = shift;
 781        my @reflist;
 782
 783        my @refs;
 784        opendir my $dh, "$projectroot/$project/$ref_dir";
 785        while (my $dir = readdir($dh)) {
 786                if ($dir =~ m/^\./) {
 787                        next;
 788                }
 789                if (-d "$projectroot/$project/$ref_dir/$dir") {
 790                        opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
 791                        my @subdirs = grep !m/^\./, readdir $dh2;
 792                        closedir($dh2);
 793                        foreach my $subdir (@subdirs) {
 794                                push @refs, "$dir/$subdir"
 795                        }
 796                        next;
 797                }
 798                push @refs, $dir;
 799        }
 800        closedir($dh);
 801        foreach my $ref_file (@refs) {
 802                my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
 803                my $type = git_get_type($ref_id) || next;
 804                my %ref_item;
 805                my %co;
 806                if ($type eq "tag") {
 807                        my %tag = git_read_tag($ref_id);
 808                        if ($tag{'type'} eq "commit") {
 809                                %co = git_read_commit($tag{'object'});
 810                        }
 811                        $ref_item{'type'} = $tag{'type'};
 812                        $ref_item{'name'} = $tag{'name'};
 813                        $ref_item{'id'} = $tag{'object'};
 814                } elsif ($type eq "commit"){
 815                        %co = git_read_commit($ref_id);
 816                        $ref_item{'type'} = "commit";
 817                        $ref_item{'name'} = $ref_file;
 818                        $ref_item{'title'} = $co{'title'};
 819                        $ref_item{'id'} = $ref_id;
 820                }
 821                $ref_item{'epoch'} = $co{'committer_epoch'} || 0;
 822                $ref_item{'age'} = $co{'age_string'} || "unknown";
 823
 824                push @reflist, \%ref_item;
 825        }
 826        # sort tags by age
 827        @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
 828        return \@reflist;
 829}
 830
 831sub git_summary {
 832        my $descr = git_read_description($project) || "none";
 833        my $head = git_read_hash("$project/HEAD");
 834        my %co = git_read_commit($head);
 835        my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
 836
 837        my $owner;
 838        if (-f $projects_list) {
 839                open (my $fd , $projects_list);
 840                while (my $line = <$fd>) {
 841                        chomp $line;
 842                        my ($pr, $ow) = split ' ', $line;
 843                        $pr = unescape($pr);
 844                        $ow = unescape($ow);
 845                        if ($pr eq $project) {
 846                                $owner = $ow;
 847                                last;
 848                        }
 849                }
 850                close $fd;
 851        }
 852        if (!defined $owner) {
 853                $owner = get_file_owner("$projectroot/$project");
 854        }
 855
 856        git_header_html();
 857        print "<div class=\"page_nav\">\n" .
 858              "summary".
 859              " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
 860              " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
 861              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
 862              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
 863              " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree"}, "tree") .
 864              "<br/><br/>\n" .
 865              "</div>\n";
 866        print "<div class=\"title\">&nbsp;</div>\n";
 867        print "<table cellspacing=\"0\">\n" .
 868              "<tr><td>description</td><td>" . escapeHTML($descr) . "</td></tr>\n" .
 869              "<tr><td>owner</td><td>$owner</td></tr>\n" .
 870              "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
 871              "</table>\n";
 872        open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
 873        my (@revlist) = map { chomp; $_ } <$fd>;
 874        close $fd;
 875        print "<div>\n" .
 876              $cgi->a({-href => "$my_uri?p=$project;a=shortlog", -class => "title"}, "shortlog") .
 877              "</div>\n";
 878        my $i = 16;
 879        print "<table cellspacing=\"0\">\n";
 880        my $alternate = 0;
 881        foreach my $commit (@revlist) {
 882                my %co = git_read_commit($commit);
 883                my %ad = date_str($co{'author_epoch'});
 884                if ($alternate) {
 885                        print "<tr class=\"dark\">\n";
 886                } else {
 887                        print "<tr class=\"light\">\n";
 888                }
 889                $alternate ^= 1;
 890                if ($i-- > 0) {
 891                        print "<td><i>$co{'age_string'}</i></td>\n" .
 892                              "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
 893                              "<td>" .
 894                              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"},
 895                              "<b>" . escapeHTML($co{'title_short'}) . "</b>") .
 896                              "</td>\n" .
 897                              "<td class=\"link\">" .
 898                              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
 899                              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
 900                              "</td>\n" .
 901                              "</tr>";
 902                } else {
 903                        print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "...") . "</td>\n" .
 904                        "</tr>";
 905                        last;
 906                }
 907        }
 908        print "</table\n>";
 909
 910        my $taglist = git_read_refs("refs/tags");
 911        if (defined @$taglist) {
 912                print "<div>\n" .
 913                      $cgi->a({-href => "$my_uri?p=$project;a=tags", -class => "title"}, "tags") .
 914                      "</div>\n";
 915                my $i = 16;
 916                print "<table cellspacing=\"0\">\n";
 917                my $alternate = 0;
 918                foreach my $entry (@$taglist) {
 919                        my %tag = %$entry;
 920                        if ($alternate) {
 921                                print "<tr class=\"dark\">\n";
 922                        } else {
 923                                print "<tr class=\"light\">\n";
 924                        }
 925                        $alternate ^= 1;
 926                        if ($i-- > 0) {
 927                                print "<td><i>$tag{'age'}</i></td>\n" .
 928                                      "<td>" .
 929                                      $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}", -class => "list"}, "<b>" .
 930                                      escapeHTML($tag{'name'}) . "</b>") .
 931                                      "</td>\n" .
 932                                      "<td class=\"link\">" .
 933                                      $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, $tag{'type'});
 934                                if ($tag{'type'} eq "commit") {
 935                                      print " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}"}, "shortlog") .
 936                                            " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log");
 937                                }
 938                                print "</td>\n" .
 939                                      "</tr>";
 940                        } else {
 941                                print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=tags"}, "...") . "</td>\n" .
 942                                "</tr>";
 943                                last;
 944                        }
 945                }
 946                print "</table\n>";
 947        }
 948
 949        my $branchlist = git_read_refs("refs/heads");
 950        if (defined @$branchlist) {
 951                print "<div>\n" .
 952                      $cgi->a({-href => "$my_uri?p=$project;a=branches", -class => "title"}, "branches") .
 953                      "</div>\n";
 954                my $i = 16;
 955                print "<table cellspacing=\"0\">\n";
 956                my $alternate = 0;
 957                foreach my $entry (@$branchlist) {
 958                        my %tag = %$entry;
 959                        if ($alternate) {
 960                                print "<tr class=\"dark\">\n";
 961                        } else {
 962                                print "<tr class=\"light\">\n";
 963                        }
 964                        $alternate ^= 1;
 965                        if ($i-- > 0) {
 966                                print "<td><i>$tag{'age'}</i></td>\n" .
 967                                      "<td>" .
 968                                      $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}", -class => "list"},
 969                                      "<b>" . escapeHTML($tag{'name'}) . "</b>") .
 970                                      "</td>\n" .
 971                                      "<td class=\"link\">" .
 972                                      $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
 973                                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'name'}"}, "log") .
 974                                      "</td>\n" .
 975                                      "</tr>";
 976                        } else {
 977                                print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=branches"}, "...") . "</td>\n" .
 978                                "</tr>";
 979                                last;
 980                        }
 981                }
 982                print "</table\n>";
 983        }
 984        git_footer_html();
 985}
 986
 987sub git_tags {
 988        my $head = git_read_hash("$project/HEAD");
 989        git_header_html();
 990        print "<div class=\"page_nav\">\n" .
 991              $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
 992              " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
 993              " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
 994              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
 995              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
 996              " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;hb=$head"}, "tree") . "<br/>\n" .
 997              "<br/>\n" .
 998              "</div>\n";
 999        my $taglist = git_read_refs("refs/tags");
1000        print "<div>\n" .
1001              $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "&nbsp;") .
1002              "</div>\n";
1003        print "<table cellspacing=\"0\">\n";
1004        my $alternate = 0;
1005        if (defined @$taglist) {
1006                foreach my $entry (@$taglist) {
1007                        my %tag = %$entry;
1008                        if ($alternate) {
1009                                print "<tr class=\"dark\">\n";
1010                        } else {
1011                                print "<tr class=\"light\">\n";
1012                        }
1013                        $alternate ^= 1;
1014                        print "<td><i>$tag{'age'}</i></td>\n" .
1015                              "<td>" .
1016                              $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}", -class => "list"},
1017                              "<b>" . escapeHTML($tag{'name'}) . "</b>") .
1018                              "</td>\n" .
1019                              "<td class=\"link\">" .
1020                              $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, $tag{'type'});
1021                        if ($tag{'type'} eq "commit") {
1022                              print " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
1023                                    " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log");
1024                        }
1025                        print "</td>\n" .
1026                              "</tr>";
1027                }
1028        }
1029        print "</table\n>";
1030        git_footer_html();
1031}
1032
1033sub git_branches {
1034        my $head = git_read_hash("$project/HEAD");
1035        git_header_html();
1036        print "<div class=\"page_nav\">\n" .
1037              $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1038              " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1039              " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1040              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
1041              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
1042              " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;hb=$head"}, "tree") . "<br/>\n" .
1043              "<br/>\n" .
1044              "</div>\n";
1045        my $taglist = git_read_refs("refs/heads");
1046        print "<div>\n" .
1047              $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "&nbsp;") .
1048              "</div>\n";
1049        print "<table cellspacing=\"0\">\n";
1050        my $alternate = 0;
1051        if (defined @$taglist) {
1052                foreach my $entry (@$taglist) {
1053                        my %tag = %$entry;
1054                        if ($alternate) {
1055                                print "<tr class=\"dark\">\n";
1056                        } else {
1057                                print "<tr class=\"light\">\n";
1058                        }
1059                        $alternate ^= 1;
1060                        print "<td><i>$tag{'age'}</i></td>\n" .
1061                              "<td>" .
1062                              $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}", -class => "list"}, "<b>" . escapeHTML($tag{'name'}) . "</b>") .
1063                              "</td>\n" .
1064                              "<td class=\"link\">" .
1065                              $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
1066                              " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'name'}"}, "log") .
1067                              "</td>\n" .
1068                              "</tr>";
1069                }
1070        }
1071        print "</table\n>";
1072        git_footer_html();
1073}
1074
1075sub git_get_hash_by_path {
1076        my $base = shift;
1077        my $path = shift || return undef;
1078
1079        my $tree = $base;
1080        my @parts = split '/', $path;
1081        while (my $part = shift @parts) {
1082                open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1083                my (@entries) = map { chomp; $_ } <$fd>;
1084                close $fd or return undef;
1085                foreach my $line (@entries) {
1086                        #'100644        blob    0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa        panic.c'
1087                        $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1088                        my $t_mode = $1;
1089                        my $t_type = $2;
1090                        my $t_hash = $3;
1091                        my $t_name = $4;
1092                        if ($t_name eq $part) {
1093                                if (!(@parts)) {
1094                                        return $t_hash;
1095                                }
1096                                if ($t_type eq "tree") {
1097                                        $tree = $t_hash;
1098                                }
1099                                last;
1100                        }
1101                }
1102        }
1103}
1104
1105sub git_blob {
1106        if (!defined $hash && defined $file_name) {
1107                my $base = $hash_base || git_read_hash("$project/HEAD");
1108                $hash = git_get_hash_by_path($base, $file_name, "blob");
1109        }
1110        open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1111        my $base = $file_name || "";
1112        git_header_html();
1113        if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1114                print "<div class=\"page_nav\">\n" .
1115                      $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1116                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1117                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1118                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1119                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1120                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") . "<br/>\n";
1121                print $cgi->a({-href => "$my_uri?p=$project;a=blob_plain;h=$hash"}, "plain") . "<br/>\n" .
1122                      "</div>\n";
1123                print "<div>" .
1124                      $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) .
1125                      "</div>\n";
1126        } else {
1127                print "<div class=\"page_nav\">\n" .
1128                      "<br/><br/></div>\n" .
1129                      "<div class=\"title\">$hash</div>\n";
1130        }
1131        if (defined $file_name) {
1132                print "<div class=\"page_path\"><b>$file_name</b></div>\n";
1133        }
1134        print "<div class=\"page_body\">\n";
1135        my $nr;
1136        while (my $line = <$fd>) {
1137                chomp $line;
1138                $nr++;
1139                while ((my $pos = index($line, "\t")) != -1) {
1140                        if (my $count = (8 - ($pos % 8))) {
1141                                my $spaces = ' ' x $count;
1142                                $line =~ s/\t/$spaces/;
1143                        }
1144                }
1145                printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, escapeHTML($line);
1146        }
1147        close $fd or print "Reading blob failed.\n";
1148        print "</div>";
1149        git_footer_html();
1150}
1151
1152sub git_blob_plain {
1153        print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1154        open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1155        undef $/;
1156        print <$fd>;
1157        $/ = "\n";
1158        close $fd;
1159}
1160
1161sub git_tree {
1162        if (!defined $hash) {
1163                $hash = git_read_hash("$project/HEAD");
1164                if (defined $file_name) {
1165                        my $base = $hash_base || git_read_hash("$project/HEAD");
1166                        $hash = git_get_hash_by_path($base, $file_name, "tree");
1167                }
1168                if (!defined $hash_base) {
1169                        $hash_base = git_read_hash("$project/HEAD");
1170                }
1171        }
1172        open my $fd, "-|", "$gitbin/git-ls-tree $hash" or die_error(undef, "Open git-ls-tree failed.");
1173        my (@entries) = map { chomp; $_ } <$fd>;
1174        close $fd or die_error(undef, "Reading tree failed.");
1175
1176        git_header_html();
1177        my $base_key = "";
1178        my $file_key = "";
1179        my $base = "";
1180        if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1181                $base_key = ";hb=$hash_base";
1182                print "<div class=\"page_nav\">\n" .
1183                      $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1184                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash_base"}, "shortlog") .
1185                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash_base"}, "log") .
1186                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1187                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1188                      " | tree" .
1189                      "<br/><br/>\n" .
1190                      "</div>\n";
1191                print "<div>\n" .
1192                      $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1193                      "</div>\n";
1194        } else {
1195                print "<div class=\"page_nav\">\n";
1196                print "<br/><br/></div>\n";
1197                print "<div class=\"title\">$hash</div>\n";
1198        }
1199        if (defined $file_name) {
1200                $base = "$file_name/";
1201                print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1202        } else {
1203                print "<div class=\"page_path\"><b>/</b></div>\n";
1204        }
1205        print "<div class=\"page_body\">\n";
1206        print "<table cellspacing=\"0\">\n";
1207        my $alternate = 0;
1208        foreach my $line (@entries) {
1209                #'100644        blob    0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa        panic.c'
1210                $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1211                my $t_mode = $1;
1212                my $t_type = $2;
1213                my $t_hash = $3;
1214                my $t_name = $4;
1215                $file_key = ";f=$base$t_name";
1216                if ($alternate) {
1217                        print "<tr class=\"dark\">\n";
1218                } else {
1219                        print "<tr class=\"light\">\n";
1220                }
1221                $alternate ^= 1;
1222                print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n";
1223                if ($t_type eq "blob") {
1224                        print "<td class=\"list\">" .
1225                              $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key, -class => "list"}, $t_name) .
1226                              "</td>\n" .
1227                              "<td class=\"link\">" .
1228                              $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key}, "blob") .
1229                              " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base" . $file_key}, "history") .
1230                              "</td>\n";
1231                } elsif ($t_type eq "tree") {
1232                        print "<td class=\"list\">" .
1233                              $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key}, $t_name) .
1234                              "</td>\n" .
1235                              "<td class=\"link\">" .
1236                              $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key}, "tree") .
1237                              "</td>\n";
1238                }
1239                print "</tr>\n";
1240        }
1241        print "</table>\n" .
1242              "</div>";
1243        git_footer_html();
1244}
1245
1246sub git_rss {
1247        # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1248        open my $fd, "-|", "$gitbin/git-rev-list --max-count=20 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
1249        my (@revlist) = map { chomp; $_ } <$fd>;
1250        close $fd or die_error(undef, "Reading rev-list failed.");
1251
1252        print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1253        print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1254              "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1255        print "<channel>\n";
1256        print "<title>$project</title>\n".
1257              "<link>" . escapeHTML("$my_url?p=$project;a=summary") . "</link>\n".
1258              "<description>$project log</description>\n".
1259              "<language>en</language>\n";
1260
1261        foreach my $commit (@revlist) {
1262                my %co = git_read_commit($commit);
1263                my %cd = date_str($co{'committer_epoch'});
1264                print "<item>\n" .
1265                      "<title>" .
1266                      sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . escapeHTML($co{'title'}) .
1267                      "</title>\n" .
1268                      "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1269                      "<link>" . escapeHTML("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1270                      "<description>" . escapeHTML($co{'title'}) . "</description>\n" .
1271                      "<content:encoded>" .
1272                      "<![CDATA[\n";
1273                my $comment = $co{'comment'};
1274                foreach my $line (@$comment) {
1275                        print "$line<br/>\n";
1276                }
1277                print "]]>\n" .
1278                      "</content:encoded>\n" .
1279                      "</item>\n";
1280        }
1281        print "</channel></rss>";
1282}
1283
1284sub git_opml {
1285        my @list = git_read_projects();
1286
1287        print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1288        print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1289              "<opml version=\"1.0\">\n".
1290              "<head>".
1291              "  <title>Git OPML Export</title>\n".
1292              "</head>\n".
1293              "<body>\n".
1294              "<outline text=\"git RSS feeds\">\n";
1295
1296        foreach my $pr (@list) {
1297                my %proj = %$pr;
1298                my $head = git_read_hash("$proj{'path'}/HEAD");
1299                if (!defined $head) {
1300                        next;
1301                }
1302                $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1303                my %co = git_read_commit($head);
1304                if (!%co) {
1305                        next;
1306                }
1307
1308                my $path = escapeHTML(chop_str($proj{'path'}, 25, 5));
1309                my $rss =  "$my_url?p=$proj{'path'};a=rss";
1310                my $html =  "$my_url?p=$proj{'path'};a=summary";
1311                print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1312        }
1313        print "</outline>\n".
1314              "</body>\n".
1315              "</opml>\n";
1316}
1317
1318sub git_log {
1319        my $head = git_read_hash("$project/HEAD");
1320        if (!defined $hash) {
1321                $hash = $head;
1322        }
1323        if (!defined $page) {
1324                $page = 0;
1325        }
1326        git_header_html();
1327        print "<div class=\"page_nav\">\n";
1328        print $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1329              " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1330              " | log" .
1331              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1332              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1333              " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
1334
1335        my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1336        open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1337        my (@revlist) = map { chomp; $_ } <$fd>;
1338        close $fd;
1339
1340        if ($hash ne $head || $page) {
1341                print $cgi->a({-href => "$my_uri?p=$project;a=log"}, "HEAD");
1342        } else {
1343                print "HEAD";
1344        }
1345        if ($page > 0) {
1346                print " &sdot; " .
1347                $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash;pg=" . ($page-1), -accesskey => "p", -title => "Alt-p"}, "prev");
1348        } else {
1349                print " &sdot; prev";
1350        }
1351        if ($#revlist >= (100 * ($page+1)-1)) {
1352                print " &sdot; " .
1353                $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash;pg=" . ($page+1), -accesskey => "n", -title => "Alt-n"}, "next");
1354        } else {
1355                print " &sdot; next";
1356        }
1357        print "<br/>\n" .
1358              "</div>\n";
1359        if (!@revlist) {
1360                print "<div>\n" .
1361                      $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "&nbsp;") .
1362                      "</div>\n";
1363                my %co = git_read_commit($hash);
1364                print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1365        }
1366        for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1367                my $commit = $revlist[$i];
1368                my %co = git_read_commit($commit);
1369                next if !%co;
1370                my %ad = date_str($co{'author_epoch'});
1371                print "<div>\n" .
1372                      $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
1373                      "<span class=\"age\">$co{'age_string'}</span>" . escapeHTML($co{'title'})) . "\n" .
1374                      "</div>\n";
1375                print "<div class=\"title_text\">\n" .
1376                      "<div class=\"log_link\">\n" .
1377                      $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1378                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
1379                      "<br/>\n" .
1380                      "</div>\n" .
1381                      "<i>" . escapeHTML($co{'author_name'}) .  " [$ad{'rfc2822'}]</i><br/>\n" .
1382                      "</div>\n" .
1383                      "<div class=\"log_body\">\n";
1384                my $comment = $co{'comment'};
1385                my $empty = 0;
1386                foreach my $line (@$comment) {
1387                        if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1388                                next;
1389                        }
1390                        if ($line eq "") {
1391                                if ($empty) {
1392                                        next;
1393                                }
1394                                $empty = 1;
1395                        } else {
1396                                $empty = 0;
1397                        }
1398                        print escapeHTML($line) . "<br/>\n";
1399                }
1400                if (!$empty) {
1401                        print "<br/>\n";
1402                }
1403                print "</div>\n";
1404        }
1405        git_footer_html();
1406}
1407
1408sub git_commit {
1409        my %co = git_read_commit($hash);
1410        if (!%co) {
1411                die_error(undef, "Unknown commit object.");
1412        }
1413        my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1414        my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1415
1416        my @difftree;
1417        my $root = "";
1418        if (!defined $co{'parent'}) {
1419                $root = " --root";
1420        }
1421        open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $co{'parent'} $hash" or die_error(undef, "Open failed.");
1422        @difftree = map { chomp; $_ } <$fd>;
1423        close $fd or die_error(undef, "Reading diff-tree failed.");
1424        git_header_html();
1425        print "<div class=\"page_nav\">\n" .
1426              $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1427              " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1428              " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1429              " | commit";
1430        if (defined $co{'parent'}) {
1431                print " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff");
1432        }
1433        print " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "\n" .
1434              "<br/><br/></div>\n";
1435        if (defined $co{'parent'}) {
1436                print "<div>\n" .
1437                      $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1438                      "</div>\n";
1439        } else {
1440                print "<div>\n" .
1441                      $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1442                      "</div>\n";
1443        }
1444        print "<div class=\"title_text\">\n" .
1445              "<table cellspacing=\"0\">\n";
1446        print "<tr><td>author</td><td>" . escapeHTML($co{'author'}) . "</td></tr>\n".
1447              "<tr>" .
1448              "<td></td><td> $ad{'rfc2822'}";
1449        if ($ad{'hour_local'} < 6) {
1450                printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1451        } else {
1452                printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1453        }
1454        print "</td>" .
1455              "</tr>\n";
1456        print "<tr><td>committer</td><td>" . escapeHTML($co{'committer'}) . "</td></tr>\n";
1457        print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1458        print "<tr><td>commit</td><td style=\"font-family:monospace\">$hash</td></tr>\n";
1459        print "<tr>" .
1460              "<td>tree</td>" .
1461              "<td style=\"font-family:monospace\">" .
1462              $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", class => "list"}, $co{'tree'}) .
1463              "</td>" .
1464              "<td class=\"link\">" . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1465              "</td>" .
1466              "</tr>\n";
1467        my $parents  = $co{'parents'};
1468        foreach my $par (@$parents) {
1469                print "<tr>" .
1470                      "<td>parent</td>" .
1471                      "<td style=\"font-family:monospace\">" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par", class => "list"}, $par) . "</td>" .
1472                      "<td class=\"link\">" .
1473                      $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, "commit") .
1474                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash;hp=$par"}, "commitdiff") .
1475                      "</td>" .
1476                      "</tr>\n";
1477        }
1478        print "</table>". 
1479              "</div>\n";
1480        print "<div class=\"page_body\">\n";
1481        my $comment = $co{'comment'};
1482        my $empty = 0;
1483        my $signed = 0;
1484        foreach my $line (@$comment) {
1485                # print only one empty line
1486                if ($line eq "") {
1487                        if ($empty || $signed) {
1488                                next;
1489                        }
1490                        $empty = 1;
1491                } else {
1492                        $empty = 0;
1493                }
1494                if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1495                        $signed = 1;
1496                        print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
1497                } else {
1498                        $signed = 0;
1499                        print escapeHTML($line) . "<br/>\n";
1500                }
1501        }
1502        print "</div>\n";
1503        print "<div class=\"list_head\">\n";
1504        if ($#difftree > 10) {
1505                print(($#difftree + 1) . " files changed:\n");
1506        }
1507        print "</div>\n";
1508        print "<table cellspacing=\"0\">\n";
1509        my $alternate = 0;
1510        foreach my $line (@difftree) {
1511                # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M      ls-files.c'
1512                # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M      rev-tree.c'
1513                $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/;
1514                my $from_mode = $1;
1515                my $to_mode = $2;
1516                my $from_id = $3;
1517                my $to_id = $4;
1518                my $status = $5;
1519                my $similarity = $6;
1520                my $file = $7;
1521                #print "$line ($status)<br/>\n";
1522                if ($alternate) {
1523                        print "<tr class=\"dark\">\n";
1524                } else {
1525                        print "<tr class=\"light\">\n";
1526                }
1527                $alternate ^= 1;
1528                if ($status eq "N") {
1529                        my $mode_chng = "";
1530                        if (S_ISREG(oct $to_mode)) {
1531                                $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1532                        }
1533                        print "<td>" .
1534                              $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hp=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "</td>\n" .
1535                              "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1536                              "<td class=\"link\">" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob") . "</td>\n";
1537                } elsif ($status eq "D") {
1538                        print "<td>" .
1539                              $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "</td>\n" .
1540                              "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1541                              "<td class=\"link\">" .
1542                              $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, "blob") .
1543                              " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") .
1544                              "</td>\n"
1545                } elsif ($status eq "M" || $status eq "T") {
1546                        my $mode_chnge = "";
1547                        if ($from_mode != $to_mode) {
1548                                $mode_chnge = " <span style=\"color: #777777;\">[changed";
1549                                if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1550                                        $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1551                                }
1552                                if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1553                                        if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1554                                                $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1555                                        } elsif (S_ISREG($to_mode)) {
1556                                                $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1557                                        }
1558                                }
1559                                $mode_chnge .= "]</span>\n";
1560                        }
1561                        print "<td>";
1562                        if ($to_id ne $from_id) {
1563                                print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file));
1564                        } else {
1565                                print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file));
1566                        }
1567                        print "</td>\n" .
1568                              "<td>$mode_chnge</td>\n" .
1569                              "<td class=\"link\">";
1570                        print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob");
1571                        if ($to_id ne $from_id) {
1572                                print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"}, "diff");
1573                        }
1574                        print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "\n";
1575                        print "</td>\n";
1576                } elsif ($status eq "R") {
1577                        my ($from_file, $to_file) = split "\t", $file;
1578                        my $mode_chng = "";
1579                        if ($from_mode != $to_mode) {
1580                                $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1581                        }
1582                        print "<td>" .
1583                              $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file", -class => "list"}, escapeHTML($to_file)) . "</td>\n" .
1584                              "<td><span style=\"color: #777777;\">[moved from " .
1585                              $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file", -class => "list"}, escapeHTML($from_file)) .
1586                              " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1587                              "<td class=\"link\">" .
1588                              $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"}, "blob");
1589                        if ($to_id ne $from_id) {
1590                                print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file"}, "diff");
1591                        }
1592                        print "</td>\n";
1593                }
1594                print "</tr>\n";
1595        }
1596        print "</table>\n";
1597        git_footer_html();
1598}
1599
1600sub git_blobdiff {
1601        mkdir($git_temp, 0700);
1602        git_header_html();
1603        if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1604                print "<div class=\"page_nav\">\n" .
1605                      $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1606                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1607                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1608                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1609                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1610                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") .
1611                      "<br/>\n";
1612                print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent"}, "plain") .
1613                      "</div>\n";
1614                print "<div>\n" .
1615                      $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1616                      "</div>\n";
1617        } else {
1618                print "<div class=\"page_nav\">\n" .
1619                      "<br/><br/></div>\n" .
1620                      "<div class=\"title\">$hash vs $hash_parent</div>\n";
1621        }
1622        if (defined $file_name) {
1623                print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1624        }
1625        print "<div class=\"page_body\">\n" .
1626              "<div class=\"diff_info\">blob:" .
1627              $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name"}, $hash_parent) .
1628              " -> blob:" .
1629              $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name"}, $hash) .
1630              "</div>\n";
1631        git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
1632        print "</div>";
1633        git_footer_html();
1634}
1635
1636sub git_blobdiff_plain {
1637        mkdir($git_temp, 0700);
1638        print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1639        git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
1640}
1641
1642sub git_commitdiff {
1643        mkdir($git_temp, 0700);
1644        my %co = git_read_commit($hash);
1645        if (!%co) {
1646                die_error(undef, "Unknown commit object.");
1647        }
1648        if (!defined $hash_parent) {
1649                $hash_parent = $co{'parent'};
1650        }
1651        open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1652        my (@difftree) = map { chomp; $_ } <$fd>;
1653        close $fd or die_error(undef, "Reading diff-tree failed.");
1654
1655        git_header_html();
1656        print "<div class=\"page_nav\">\n" .
1657              $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1658              " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1659              " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1660              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1661              " | commitdiff" .
1662              " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "<br/>\n";
1663        print $cgi->a({-href => "$my_uri?p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent"}, "plain") . "\n" .
1664              "</div>\n";
1665        print "<div>\n" .
1666              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1667              "</div>\n";
1668        print "<div class=\"page_body\">\n";
1669        my $comment = $co{'comment'};
1670        my $empty = 0;
1671        my $signed = 0;
1672        my @log = @$comment;
1673        # remove first and empty lines after that
1674        shift @log;
1675        while (defined $log[0] && $log[0] eq "") {
1676                shift @log;
1677        }
1678        foreach my $line (@log) {
1679                if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1680                        next;
1681                }
1682                if ($line eq "") {
1683                        if ($empty) {
1684                                next;
1685                        }
1686                        $empty = 1;
1687                } else {
1688                        $empty = 0;
1689                }
1690                print escapeHTML($line) . "<br/>\n";
1691        }
1692        print "<br/>\n";
1693        foreach my $line (@difftree) {
1694                # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M      ls-files.c'
1695                # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M      rev-tree.c'
1696                $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1697                my $from_mode = $1;
1698                my $to_mode = $2;
1699                my $from_id = $3;
1700                my $to_id = $4;
1701                my $status = $5;
1702                my $file = $6;
1703                if ($status eq "N") {
1704                        print "<div class=\"diff_info\">" .  file_type($to_mode) . ":" .
1705                              $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id) . "(new)" .
1706                              "</div>\n";
1707                        git_diff_print(undef, "/dev/null", $to_id, "b/$file");
1708                } elsif ($status eq "D") {
1709                        print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
1710                              $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) . "(deleted)" .
1711                              "</div>\n";
1712                        git_diff_print($from_id, "a/$file", undef, "/dev/null");
1713                } elsif ($status eq "M") {
1714                        if ($from_id ne $to_id) {
1715                                print "<div class=\"diff_info\">" .
1716                                      file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) .
1717                                      " -> " .
1718                                      file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id);
1719                                print "</div>\n";
1720                                git_diff_print($from_id, "a/$file",  $to_id, "b/$file");
1721                        }
1722                }
1723        }
1724        print "<br/>\n" .
1725              "</div>";
1726        git_footer_html();
1727}
1728
1729sub git_commitdiff_plain {
1730        mkdir($git_temp, 0700);
1731        open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1732        my (@difftree) = map { chomp; $_ } <$fd>;
1733        close $fd or die_error(undef, "Reading diff-tree failed.");
1734
1735        my %co = git_read_commit($hash);
1736        my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1737        print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1738        my $comment = $co{'comment'};
1739        print "Author: $co{'author'}\n" .
1740              "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
1741              "Source: $my_url?p=$project;a=commitdiff;h=$hash\n" .
1742              "\n";
1743        foreach my $line (@$comment) {;
1744                print "  $line\n";
1745        }
1746        print "\n";
1747        foreach my $line (@difftree) {
1748                $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1749                my $from_id = $3;
1750                my $to_id = $4;
1751                my $status = $5;
1752                my $file = $6;
1753                if ($status eq "N") {
1754                        git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
1755                } elsif ($status eq "D") {
1756                        git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
1757                } elsif ($status eq "M") {
1758                        git_diff_print($from_id, "a/$file",  $to_id, "b/$file", "plain");
1759                }
1760        }
1761}
1762
1763sub git_history {
1764        if (!defined $hash) {
1765                $hash = git_read_hash("$project/HEAD");
1766        }
1767        my %co = git_read_commit($hash);
1768        if (!%co) {
1769                die_error(undef, "Unknown commit object.");
1770        }
1771        git_header_html();
1772        print "<div class=\"page_nav\">\n" .
1773              $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1774              " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1775              " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1776              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1777              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1778              " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1779              "<br/><br/>\n" .
1780              "</div>\n";
1781        print "<div>\n" .
1782              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1783              "</div>\n";
1784        print "<div class=\"page_path\"><b>/$file_name</b><br/></div>\n";
1785
1786        open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin $file_name";
1787        my $commit;
1788        print "<table cellspacing=\"0\">\n";
1789        my $alternate = 0;
1790        while (my $line = <$fd>) {
1791                if ($line =~ m/^([0-9a-fA-F]{40})/){
1792                        $commit = $1;
1793                        next;
1794                }
1795                if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
1796                        my %co = git_read_commit($commit);
1797                        if (!%co) {
1798                                next;
1799                        }
1800                        if ($alternate) {
1801                                print "<tr class=\"dark\">\n";
1802                        } else {
1803                                print "<tr class=\"light\">\n";
1804                        }
1805                        $alternate ^= 1;
1806                        print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1807                              "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1808                              "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
1809                              escapeHTML(chop_str($co{'title'}, 50)) . "</b>") . "</td>\n" .
1810                              "<td class=\"link\">" .
1811                              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1812                              " | " . $cgi->a({-href => "$my_uri?p=$project;a=blob;hb=$commit;f=$file_name"}, "blob");
1813                        my $blob = git_get_hash_by_path($hash, $file_name);
1814                        my $blob_parent = git_get_hash_by_path($commit, $file_name);
1815                        if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
1816                                print " | " .
1817                                $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name"},
1818                                "diff to current");
1819                        }
1820                        print "</td>\n" .
1821                              "</tr>\n";
1822                        undef $commit;
1823                }
1824        }
1825        print "</table>\n";
1826        close $fd;
1827        git_footer_html();
1828}
1829
1830sub git_search {
1831        if (!defined $searchtext) {
1832                die_error("", "Text field empty.");
1833        }
1834        if (!defined $hash) {
1835                $hash = git_read_hash("$project/HEAD");
1836        }
1837        my %co = git_read_commit($hash);
1838        if (!%co) {
1839                die_error(undef, "Unknown commit object.");
1840        }
1841        # pickaxe may take all resources of your box and run for several minutes
1842        # with every query - so decide by yourself how public you make this feature :)
1843        my $commit_search = 1;
1844        my $author_search = 0;
1845        my $committer_search = 0;
1846        my $pickaxe_search = 0;
1847        if ($searchtext =~ s/^author\\://i) {
1848                $author_search = 1;
1849        } elsif ($searchtext =~ s/^committer\\://i) {
1850                $committer_search = 1;
1851        } elsif ($searchtext =~ s/^pickaxe\\://i) {
1852                $commit_search = 0;
1853                $pickaxe_search = 1;
1854        }
1855        git_header_html();
1856        print "<div class=\"page_nav\">\n" .
1857              $cgi->a({-href => "$my_uri?p=$project;a=summary;h=$hash"}, "summary") .
1858              " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1859              " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1860              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1861              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1862              " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1863              "<br/><br/>\n" .
1864              "</div>\n";
1865
1866        print "<div>\n" .
1867              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1868              "</div>\n";
1869        print "<table cellspacing=\"0\">\n";
1870        my $alternate = 0;
1871        if ($commit_search) {
1872                $/ = "\0";
1873                open my $fd, "-|", "$gitbin/git-rev-list --header $hash";
1874                while (my $commit_text = <$fd>) {
1875                        if (!grep m/$searchtext/i, $commit_text) {
1876                                next;
1877                        }
1878                        if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
1879                                next;
1880                        }
1881                        if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
1882                                next;
1883                        }
1884                        my @commit_lines = split "\n", $commit_text;
1885                        my $commit = shift @commit_lines;
1886                        my %co = git_read_commit($commit, \@commit_lines);
1887                        if (!%co) {
1888                                next;
1889                        }
1890                        if ($alternate) {
1891                                print "<tr class=\"dark\">\n";
1892                        } else {
1893                                print "<tr class=\"light\">\n";
1894                        }
1895                        $alternate ^= 1;
1896                        print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1897                              "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
1898                              "<td>" .
1899                              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" . escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
1900                        my $comment = $co{'comment'};
1901                        foreach my $line (@$comment) {
1902                                if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
1903                                        my $lead = escapeHTML($1) || "";
1904                                        $lead = chop_str($lead, 30, 10);
1905                                        my $match = escapeHTML($2) || "";
1906                                        my $trail = escapeHTML($3) || "";
1907                                        $trail = chop_str($trail, 30, 10);
1908                                        my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
1909                                        print chop_str($text, 80, 5) . "<br/>\n";
1910                                }
1911                        }
1912                        print "</td>\n" .
1913                              "<td class=\"link\">" .
1914                              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1915                              " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$commit"}, "tree");
1916                        print "</td>\n" .
1917                              "</tr>\n";
1918                }
1919                close $fd;
1920        }
1921
1922        if ($pickaxe_search) {
1923                $/ = "\n";
1924                open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S$searchtext";
1925                undef %co;
1926                my @files;
1927                while (my $line = <$fd>) {
1928                        if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
1929                                my %set;
1930                                $set{'file'} = $6;
1931                                $set{'from_id'} = $3;
1932                                $set{'to_id'} = $4;
1933                                $set{'id'} = $set{'to_id'};
1934                                if ($set{'id'} =~ m/0{40}/) {
1935                                        $set{'id'} = $set{'from_id'};
1936                                }
1937                                if ($set{'id'} =~ m/0{40}/) {
1938                                        next;
1939                                }
1940                                push @files, \%set;
1941                        } elsif ($line =~ m/^([0-9a-fA-F]{40}) /){
1942                                if (%co) {
1943                                        if ($alternate) {
1944                                                print "<tr class=\"dark\">\n";
1945                                        } else {
1946                                                print "<tr class=\"light\">\n";
1947                                        }
1948                                        $alternate ^= 1;
1949                                        print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1950                                              "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
1951                                              "<td>" .
1952                                              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}", -class => "list"}, "<b>" .
1953                                              escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
1954                                        while (my $setref = shift @files) {
1955                                                my %set = %$setref;
1956                                                print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}", class => "list"},
1957                                                      "<span style=\"color:#e00000\">" . escapeHTML($set{'file'}) . "</span>") .
1958                                                      "<br/>\n";
1959                                        }
1960                                        print "</td>\n" .
1961                                              "<td class=\"link\">" .
1962                                              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}"}, "commit") .
1963                                              " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}"}, "tree");
1964                                        print "</td>\n" .
1965                                              "</tr>\n";
1966                                }
1967                                %co = git_read_commit($1);
1968                        }
1969                }
1970                close $fd;
1971        }
1972        print "</table>\n";
1973        git_footer_html();
1974}
1975
1976sub git_shortlog {
1977        my $head = git_read_hash("$project/HEAD");
1978        if (!defined $hash) {
1979                $hash = $head;
1980        }
1981        if (!defined $page) {
1982                $page = 0;
1983        }
1984        git_header_html();
1985        print "<div class=\"page_nav\">\n" .
1986              $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1987              " | shortlog" .
1988              " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1989              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1990              " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1991              " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
1992
1993        my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1994        open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1995        my (@revlist) = map { chomp; $_ } <$fd>;
1996        close $fd;
1997
1998        if ($hash ne $head || $page) {
1999                print $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "HEAD");
2000        } else {
2001                print "HEAD";
2002        }
2003        if ($page > 0) {
2004                print " &sdot; " .
2005                $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page-1), -accesskey => "p", -title => "Alt-p"}, "prev");
2006        } else {
2007                print " &sdot; prev";
2008        }
2009        if ($#revlist >= (100 * ($page+1)-1)) {
2010                print " &sdot; " .
2011                $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1), -accesskey => "n", -title => "Alt-n"}, "next");
2012        } else {
2013                print " &sdot; next";
2014        }
2015        print "<br/>\n" .
2016              "</div>\n";
2017        print "<div>\n" .
2018              $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "&nbsp;") .
2019              "</div>\n";
2020        print "<table cellspacing=\"0\">\n";
2021        my $alternate = 0;
2022        for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2023                my $commit = $revlist[$i];
2024                my %co = git_read_commit($commit);
2025                my %ad = date_str($co{'author_epoch'});
2026                if ($alternate) {
2027                        print "<tr class=\"dark\">\n";
2028                } else {
2029                        print "<tr class=\"light\">\n";
2030                }
2031                $alternate ^= 1;
2032                print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2033                      "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2034                      "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
2035                      escapeHTML($co{'title_short'}) . "</b>") . "</td>\n" .
2036                      "<td class=\"link\">" .
2037                      $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
2038                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
2039                      "</td>\n" .
2040                      "</tr>";
2041        }
2042        if ($#revlist >= (100 * ($page+1)-1)) {
2043                print "<tr>\n" .
2044                      "<td>" .
2045                      $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1), -title => "Alt-n"}, "next") .
2046                      "</td>\n" .
2047                      "</tr>\n";
2048        }
2049        print "</table\n>";
2050        git_footer_html();
2051}