v234
[git.git] / gitweb.cgi
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
10 use strict;
11 use warnings;
12 use CGI qw(:standard :escapeHTML -nosticky);
13 use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
15 use Fcntl ':mode';
16
17 my $cgi = new CGI;
18 my $version =           "234";
19 my $my_url =            $cgi->url();
20 my $my_uri =            $cgi->url(-absolute => 1);
21 my $rss_link = "";
22
23 # absolute fs-path which will be prepended to the project path
24 my $projectroot =       "/pub/scm";
25
26 # location of the git-core binaries
27 my $gitbin =            "/usr/bin";
28
29 # location for temporary files needed for diffs
30 my $git_temp =          "/tmp/gitweb";
31
32 # target of the home link on top of all pages
33 my $home_link =         $my_uri;
34
35 # html text to include at home page
36 my $home_text =         "indextext.html";
37
38 # source of projects list
39 #my $projects_list = $projectroot;
40 my $projects_list = "index/index.aux";
41
42 # input validation and dispatch
43 my $action = $cgi->param('a');
44 if (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
58 my $project = $cgi->param('p');
59 if (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
83 my $file_name = $cgi->param('f');
84 if (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
95 my $hash = $cgi->param('h');
96 if (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
118 my $hash_parent = $cgi->param('hp');
119 if (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
124 my $hash_base = $cgi->param('hb');
125 if (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
130 my $page = $cgi->param('pg');
131 if (defined $page) {
132         if ($page =~ m/^[^0-9]+$/) {
133                 undef $page;
134                 die_error(undef, "Invalid page parameter.");
135         }
136 }
137
138 my $searchtext = $cgi->param('s');
139 if (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
147 if (!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
201 sub 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">
223 body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
224 a { color:#0000cc; }
225 a:hover, a:visited, a:active { color:#880000; }
226 div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; }
227 div.page_header a:visited { color:#0000cc; }
228 div.page_header a:hover { color:#880000; }
229 div.page_nav { padding:8px; }
230 div.page_nav a:visited { color:#0000cc; }
231 div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
232 div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
233 div.page_footer_text { float:left; color:#555555; font-style:italic; }
234 div.page_body { padding:8px; }
235 div.title, a.title {
236         display:block; padding:6px 8px;
237         font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
238 }
239 a.title:hover { background-color: #d9d8d1; }
240 div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; }
241 div.log_body { padding:8px 8px 8px 150px; }
242 span.age { position:relative; float:left; width:142px; font-style:italic; }
243 div.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 }
248 div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; }
249 a.list { text-decoration:none; color:#000000; }
250 a.list:hover { text-decoration:underline; color:#880000; }
251 table { padding:8px 4px; }
252 th { padding:2px 5px; font-size:12px; text-align:left; }
253 tr.light:hover { background-color:#edece6; }
254 tr.dark { background-color:#f6f6f0; }
255 tr.dark:hover { background-color:#edece6; }
256 td { padding:2px 5px; font-size:12px; vertical-align:top; }
257 td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; }
258 div.pre { font-family:monospace; font-size:12px; white-space:pre; }
259 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
260 div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
261 div.search { margin:4px 8px; position:absolute; top:56px; right:12px }
262 a.linenr { color:#999999; text-decoration:none }
263 a.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 }
270 a.rss_logo:hover { background-color:#ee5500; }
271 </style>
272 </head>
273 <body>
274 EOF
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
301 sub 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
317 sub 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
331 sub 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
341 sub 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
353 sub 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
363 sub 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
385 sub 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+1, $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+1, $mday;
488         }
489         return %co;
490 }
491
492 sub 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
564 sub 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
583 sub 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
596 sub 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
610 sub format_log_line_html {
611         my $line = shift;
612
613         $line = escapeHTML($line);
614         $line =~ s/ /&nbsp;/g;
615         if ($line =~ m/([0-9a-fA-F]{40})/) {
616                 my $hash_text = $1;
617                 if (git_get_type($hash_text) eq "commit") {
618                         my $link = $cgi->a({-class => "list", -href => "$my_uri?p=$project;a=commit;h=$hash_text"}, $hash_text);
619                         $line =~ s/$hash_text/$link/;
620                 }
621         }
622         return $line;
623 }
624
625 sub date_str {
626         my $epoch = shift;
627         my $tz = shift || "-0000";
628
629         my %date;
630         my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
631         my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
632         my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
633         $date{'hour'} = $hour;
634         $date{'minute'} = $min;
635         $date{'mday'} = $mday;
636         $date{'day'} = $days[$wday];
637         $date{'month'} = $months[$mon];
638         $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
639         $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
640
641         $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
642         my $local = $epoch + ((int $1 + ($2/60)) * 3600);
643         ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
644         $date{'hour_local'} = $hour;
645         $date{'minute_local'} = $min;
646         $date{'tz_local'} = $tz;
647         return %date;
648 }
649
650 # git-logo (cached in browser for one day)
651 sub git_logo {
652         print $cgi->header(-type => 'image/png', -expires => '+1d');
653         # cat git-logo.png | hexdump -e '16/1 " %02x"  "\n"' | sed 's/ /\\x/g'
654         print   "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
655                 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
656                 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
657                 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
658                 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
659                 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
660                 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
661                 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
662                 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
663                 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
664                 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
665                 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
666                 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
667 }
668
669 sub get_file_owner {
670         my $path = shift;
671
672         my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
673         my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
674         if (!defined $gcos) {
675                 return undef;
676         }
677         my $owner = $gcos;
678         $owner =~ s/[,;].*$//;
679         return $owner;
680 }
681
682 sub git_read_projects {
683         my @list;
684
685         if (-d $projects_list) {
686                 # search in directory
687                 my $dir = $projects_list;
688                 opendir my $dh, $dir or return undef;
689                 while (my $dir = readdir($dh)) {
690                         if (-e "$projectroot/$dir/HEAD") {
691                                 my $pr = {
692                                         path => $dir,
693                                 };
694                                 push @list, $pr
695                         }
696                 }
697                 closedir($dh);
698         } elsif (-f $projects_list) {
699                 # read from file(url-encoded):
700                 # 'git%2Fgit.git Linus+Torvalds'
701                 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
702                 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
703                 open my $fd , $projects_list or return undef;
704                 while (my $line = <$fd>) {
705                         chomp $line;
706                         my ($path, $owner) = split ' ', $line;
707                         $path = unescape($path);
708                         $owner = unescape($owner);
709                         if (!defined $path) {
710                                 next;
711                         }
712                         if (-e "$projectroot/$path/HEAD") {
713                                 my $pr = {
714                                         path => $path,
715                                         owner => $owner,
716                                 };
717                                 push @list, $pr
718                         }
719                 }
720                 close $fd;
721         }
722         @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
723         return @list;
724 }
725
726 sub git_project_list {
727         my @list = git_read_projects();
728         if (!@list) {
729                 die_error(undef, "No project found.");
730         }
731         git_header_html();
732         if (-f $home_text) {
733                 print "<div class=\"index_include\">\n";
734                 open (my $fd, $home_text);
735                 print <$fd>;
736                 close $fd;
737                 print "</div>\n";
738         }
739         print "<table cellspacing=\"0\">\n" .
740               "<tr>\n" .
741               "<th>Project</th>\n" .
742               "<th>Description</th>\n" .
743               "<th>Owner</th>\n" .
744               "<th>last change</th>\n" .
745               "<th></th>\n" .
746               "</tr>\n";
747         my $alternate = 0;
748         foreach my $pr (@list) {
749                 my %proj = %$pr;
750                 my $head = git_read_hash("$proj{'path'}/HEAD");
751                 if (!defined $head) {
752                         next;
753                 }
754                 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
755                 my %co = git_read_commit($head);
756                 if (!%co) {
757                         next;
758                 }
759                 my $descr = git_read_description($proj{'path'}) || "";
760                 $descr = chop_str($descr, 25, 5);
761                 # get directory owner if not already specified
762                 if (!defined $proj{'owner'}) {
763                         $proj{'owner'} = get_file_owner("$projectroot/$proj{'path'}") || "";
764                 }
765                 if ($alternate) {
766                         print "<tr class=\"dark\">\n";
767                 } else {
768                         print "<tr class=\"light\">\n";
769                 }
770                 $alternate ^= 1;
771                 print "<td>" . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary", -class => "list"}, escapeHTML($proj{'path'})) . "</td>\n" .
772                       "<td>$descr</td>\n" .
773                       "<td><i>" . chop_str($proj{'owner'}, 15) . "</i></td>\n";
774                 my $colored_age;
775                 if ($co{'age'} < 60*60*2) {
776                         $colored_age = "<span style =\"color: #009900;\"><b><i>$co{'age_string'}</i></b></span>";
777                 } elsif ($co{'age'} < 60*60*24*2) {
778                         $colored_age = "<span style =\"color: #009900;\"><i>$co{'age_string'}</i></span>";
779                 } else {
780                         $colored_age = "<i>$co{'age_string'}</i>";
781                 }
782                 print "<td>$colored_age</td>\n" .
783                       "<td class=\"link\">" .
784                       $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary"}, "summary") .
785                       " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=shortlog"}, "shortlog") .
786                       " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=log"}, "log") .
787                       "</td>\n" .
788                       "</tr>\n";
789         }
790         print "</table>\n";
791         git_footer_html();
792 }
793
794 sub git_read_refs {
795         my $ref_dir = shift;
796         my @reflist;
797
798         my @refs;
799         opendir my $dh, "$projectroot/$project/$ref_dir";
800         while (my $dir = readdir($dh)) {
801                 if ($dir =~ m/^\./) {
802                         next;
803                 }
804                 if (-d "$projectroot/$project/$ref_dir/$dir") {
805                         opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
806                         my @subdirs = grep !m/^\./, readdir $dh2;
807                         closedir($dh2);
808                         foreach my $subdir (@subdirs) {
809                                 push @refs, "$dir/$subdir"
810                         }
811                         next;
812                 }
813                 push @refs, $dir;
814         }
815         closedir($dh);
816         foreach my $ref_file (@refs) {
817                 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
818                 my $type = git_get_type($ref_id) || next;
819                 my %ref_item;
820                 my %co;
821                 if ($type eq "tag") {
822                         my %tag = git_read_tag($ref_id);
823                         if ($tag{'type'} eq "commit") {
824                                 %co = git_read_commit($tag{'object'});
825                         }
826                         $ref_item{'type'} = $tag{'type'};
827                         $ref_item{'name'} = $tag{'name'};
828                         $ref_item{'id'} = $tag{'object'};
829                 } elsif ($type eq "commit"){
830                         %co = git_read_commit($ref_id);
831                         $ref_item{'type'} = "commit";
832                         $ref_item{'name'} = $ref_file;
833                         $ref_item{'title'} = $co{'title'};
834                         $ref_item{'id'} = $ref_id;
835                 }
836                 $ref_item{'epoch'} = $co{'committer_epoch'} || 0;
837                 $ref_item{'age'} = $co{'age_string'} || "unknown";
838
839                 push @reflist, \%ref_item;
840         }
841         # sort tags by age
842         @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
843         return \@reflist;
844 }
845
846 sub git_summary {
847         my $descr = git_read_description($project) || "none";
848         my $head = git_read_hash("$project/HEAD");
849         my %co = git_read_commit($head);
850         my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
851
852         my $owner;
853         if (-f $projects_list) {
854                 open (my $fd , $projects_list);
855                 while (my $line = <$fd>) {
856                         chomp $line;
857                         my ($pr, $ow) = split ' ', $line;
858                         $pr = unescape($pr);
859                         $ow = unescape($ow);
860                         if ($pr eq $project) {
861                                 $owner = $ow;
862                                 last;
863                         }
864                 }
865                 close $fd;
866         }
867         if (!defined $owner) {
868                 $owner = get_file_owner("$projectroot/$project");
869         }
870
871         git_header_html();
872         print "<div class=\"page_nav\">\n" .
873               "summary".
874               " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
875               " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
876               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
877               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
878               " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree"}, "tree") .
879               "<br/><br/>\n" .
880               "</div>\n";
881         print "<div class=\"title\">&nbsp;</div>\n";
882         print "<table cellspacing=\"0\">\n" .
883               "<tr><td>description</td><td>" . escapeHTML($descr) . "</td></tr>\n" .
884               "<tr><td>owner</td><td>$owner</td></tr>\n" .
885               "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
886               "</table>\n";
887         open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
888         my (@revlist) = map { chomp; $_ } <$fd>;
889         close $fd;
890         print "<div>\n" .
891               $cgi->a({-href => "$my_uri?p=$project;a=shortlog", -class => "title"}, "shortlog") .
892               "</div>\n";
893         my $i = 16;
894         print "<table cellspacing=\"0\">\n";
895         my $alternate = 0;
896         foreach my $commit (@revlist) {
897                 my %co = git_read_commit($commit);
898                 my %ad = date_str($co{'author_epoch'});
899                 if ($alternate) {
900                         print "<tr class=\"dark\">\n";
901                 } else {
902                         print "<tr class=\"light\">\n";
903                 }
904                 $alternate ^= 1;
905                 if ($i-- > 0) {
906                         print "<td><i>$co{'age_string'}</i></td>\n" .
907                               "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
908                               "<td>" .
909                               $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"},
910                               "<b>" . escapeHTML($co{'title_short'}) . "</b>") .
911                               "</td>\n" .
912                               "<td class=\"link\">" .
913                               $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
914                               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
915                               "</td>\n" .
916                               "</tr>";
917                 } else {
918                         print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "...") . "</td>\n" .
919                         "</tr>";
920                         last;
921                 }
922         }
923         print "</table\n>";
924
925         my $taglist = git_read_refs("refs/tags");
926         if (defined @$taglist) {
927                 print "<div>\n" .
928                       $cgi->a({-href => "$my_uri?p=$project;a=tags", -class => "title"}, "tags") .
929                       "</div>\n";
930                 my $i = 16;
931                 print "<table cellspacing=\"0\">\n";
932                 my $alternate = 0;
933                 foreach my $entry (@$taglist) {
934                         my %tag = %$entry;
935                         if ($alternate) {
936                                 print "<tr class=\"dark\">\n";
937                         } else {
938                                 print "<tr class=\"light\">\n";
939                         }
940                         $alternate ^= 1;
941                         if ($i-- > 0) {
942                                 print "<td><i>$tag{'age'}</i></td>\n" .
943                                       "<td>" .
944                                       $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}", -class => "list"}, "<b>" .
945                                       escapeHTML($tag{'name'}) . "</b>") .
946                                       "</td>\n" .
947                                       "<td class=\"link\">" .
948                                       $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, $tag{'type'});
949                                 if ($tag{'type'} eq "commit") {
950                                       print " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}"}, "shortlog") .
951                                             " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log");
952                                 }
953                                 print "</td>\n" .
954                                       "</tr>";
955                         } else {
956                                 print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=tags"}, "...") . "</td>\n" .
957                                 "</tr>";
958                                 last;
959                         }
960                 }
961                 print "</table\n>";
962         }
963
964         my $branchlist = git_read_refs("refs/heads");
965         if (defined @$branchlist) {
966                 print "<div>\n" .
967                       $cgi->a({-href => "$my_uri?p=$project;a=branches", -class => "title"}, "branches") .
968                       "</div>\n";
969                 my $i = 16;
970                 print "<table cellspacing=\"0\">\n";
971                 my $alternate = 0;
972                 foreach my $entry (@$branchlist) {
973                         my %tag = %$entry;
974                         if ($alternate) {
975                                 print "<tr class=\"dark\">\n";
976                         } else {
977                                 print "<tr class=\"light\">\n";
978                         }
979                         $alternate ^= 1;
980                         if ($i-- > 0) {
981                                 print "<td><i>$tag{'age'}</i></td>\n" .
982                                       "<td>" .
983                                       $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}", -class => "list"},
984                                       "<b>" . escapeHTML($tag{'name'}) . "</b>") .
985                                       "</td>\n" .
986                                       "<td class=\"link\">" .
987                                       $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
988                                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'name'}"}, "log") .
989                                       "</td>\n" .
990                                       "</tr>";
991                         } else {
992                                 print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=branches"}, "...") . "</td>\n" .
993                                 "</tr>";
994                                 last;
995                         }
996                 }
997                 print "</table\n>";
998         }
999         git_footer_html();
1000 }
1001
1002 sub git_tags {
1003         my $head = git_read_hash("$project/HEAD");
1004         git_header_html();
1005         print "<div class=\"page_nav\">\n" .
1006               $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1007               " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1008               " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1009               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
1010               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
1011               " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;hb=$head"}, "tree") . "<br/>\n" .
1012               "<br/>\n" .
1013               "</div>\n";
1014         my $taglist = git_read_refs("refs/tags");
1015         print "<div>\n" .
1016               $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "&nbsp;") .
1017               "</div>\n";
1018         print "<table cellspacing=\"0\">\n";
1019         my $alternate = 0;
1020         if (defined @$taglist) {
1021                 foreach my $entry (@$taglist) {
1022                         my %tag = %$entry;
1023                         if ($alternate) {
1024                                 print "<tr class=\"dark\">\n";
1025                         } else {
1026                                 print "<tr class=\"light\">\n";
1027                         }
1028                         $alternate ^= 1;
1029                         print "<td><i>$tag{'age'}</i></td>\n" .
1030                               "<td>" .
1031                               $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}", -class => "list"},
1032                               "<b>" . escapeHTML($tag{'name'}) . "</b>") .
1033                               "</td>\n" .
1034                               "<td class=\"link\">" .
1035                               $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, $tag{'type'});
1036                         if ($tag{'type'} eq "commit") {
1037                               print " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
1038                                     " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log");
1039                         }
1040                         print "</td>\n" .
1041                               "</tr>";
1042                 }
1043         }
1044         print "</table\n>";
1045         git_footer_html();
1046 }
1047
1048 sub git_branches {
1049         my $head = git_read_hash("$project/HEAD");
1050         git_header_html();
1051         print "<div class=\"page_nav\">\n" .
1052               $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1053               " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1054               " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1055               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
1056               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
1057               " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;hb=$head"}, "tree") . "<br/>\n" .
1058               "<br/>\n" .
1059               "</div>\n";
1060         my $taglist = git_read_refs("refs/heads");
1061         print "<div>\n" .
1062               $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "&nbsp;") .
1063               "</div>\n";
1064         print "<table cellspacing=\"0\">\n";
1065         my $alternate = 0;
1066         if (defined @$taglist) {
1067                 foreach my $entry (@$taglist) {
1068                         my %tag = %$entry;
1069                         if ($alternate) {
1070                                 print "<tr class=\"dark\">\n";
1071                         } else {
1072                                 print "<tr class=\"light\">\n";
1073                         }
1074                         $alternate ^= 1;
1075                         print "<td><i>$tag{'age'}</i></td>\n" .
1076                               "<td>" .
1077                               $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}", -class => "list"}, "<b>" . escapeHTML($tag{'name'}) . "</b>") .
1078                               "</td>\n" .
1079                               "<td class=\"link\">" .
1080                               $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
1081                               " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'name'}"}, "log") .
1082                               "</td>\n" .
1083                               "</tr>";
1084                 }
1085         }
1086         print "</table\n>";
1087         git_footer_html();
1088 }
1089
1090 sub git_get_hash_by_path {
1091         my $base = shift;
1092         my $path = shift || return undef;
1093
1094         my $tree = $base;
1095         my @parts = split '/', $path;
1096         while (my $part = shift @parts) {
1097                 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1098                 my (@entries) = map { chomp; $_ } <$fd>;
1099                 close $fd or return undef;
1100                 foreach my $line (@entries) {
1101                         #'100644        blob    0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa        panic.c'
1102                         $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1103                         my $t_mode = $1;
1104                         my $t_type = $2;
1105                         my $t_hash = $3;
1106                         my $t_name = $4;
1107                         if ($t_name eq $part) {
1108                                 if (!(@parts)) {
1109                                         return $t_hash;
1110                                 }
1111                                 if ($t_type eq "tree") {
1112                                         $tree = $t_hash;
1113                                 }
1114                                 last;
1115                         }
1116                 }
1117         }
1118 }
1119
1120 sub git_blob {
1121         if (!defined $hash && defined $file_name) {
1122                 my $base = $hash_base || git_read_hash("$project/HEAD");
1123                 $hash = git_get_hash_by_path($base, $file_name, "blob");
1124         }
1125         open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1126         my $base = $file_name || "";
1127         git_header_html();
1128         if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1129                 print "<div class=\"page_nav\">\n" .
1130                       $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1131                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1132                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1133                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1134                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1135                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") . "<br/>\n";
1136                 print $cgi->a({-href => "$my_uri?p=$project;a=blob_plain;h=$hash"}, "plain") . "<br/>\n" .
1137                       "</div>\n";
1138                 print "<div>" .
1139                       $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) .
1140                       "</div>\n";
1141         } else {
1142                 print "<div class=\"page_nav\">\n" .
1143                       "<br/><br/></div>\n" .
1144                       "<div class=\"title\">$hash</div>\n";
1145         }
1146         if (defined $file_name) {
1147                 print "<div class=\"page_path\"><b>$file_name</b></div>\n";
1148         }
1149         print "<div class=\"page_body\">\n";
1150         my $nr;
1151         while (my $line = <$fd>) {
1152                 chomp $line;
1153                 $nr++;
1154                 while ((my $pos = index($line, "\t")) != -1) {
1155                         if (my $count = (8 - ($pos % 8))) {
1156                                 my $spaces = ' ' x $count;
1157                                 $line =~ s/\t/$spaces/;
1158                         }
1159                 }
1160                 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, escapeHTML($line);
1161         }
1162         close $fd or print "Reading blob failed.\n";
1163         print "</div>";
1164         git_footer_html();
1165 }
1166
1167 sub git_blob_plain {
1168         print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1169         open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1170         undef $/;
1171         print <$fd>;
1172         $/ = "\n";
1173         close $fd;
1174 }
1175
1176 sub git_tree {
1177         if (!defined $hash) {
1178                 $hash = git_read_hash("$project/HEAD");
1179                 if (defined $file_name) {
1180                         my $base = $hash_base || git_read_hash("$project/HEAD");
1181                         $hash = git_get_hash_by_path($base, $file_name, "tree");
1182                 }
1183                 if (!defined $hash_base) {
1184                         $hash_base = git_read_hash("$project/HEAD");
1185                 }
1186         }
1187         open my $fd, "-|", "$gitbin/git-ls-tree $hash" or die_error(undef, "Open git-ls-tree failed.");
1188         my (@entries) = map { chomp; $_ } <$fd>;
1189         close $fd or die_error(undef, "Reading tree failed.");
1190
1191         git_header_html();
1192         my $base_key = "";
1193         my $file_key = "";
1194         my $base = "";
1195         if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1196                 $base_key = ";hb=$hash_base";
1197                 print "<div class=\"page_nav\">\n" .
1198                       $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1199                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash_base"}, "shortlog") .
1200                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash_base"}, "log") .
1201                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1202                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1203                       " | tree" .
1204                       "<br/><br/>\n" .
1205                       "</div>\n";
1206                 print "<div>\n" .
1207                       $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1208                       "</div>\n";
1209         } else {
1210                 print "<div class=\"page_nav\">\n";
1211                 print "<br/><br/></div>\n";
1212                 print "<div class=\"title\">$hash</div>\n";
1213         }
1214         if (defined $file_name) {
1215                 $base = "$file_name/";
1216                 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1217         } else {
1218                 print "<div class=\"page_path\"><b>/</b></div>\n";
1219         }
1220         print "<div class=\"page_body\">\n";
1221         print "<table cellspacing=\"0\">\n";
1222         my $alternate = 0;
1223         foreach my $line (@entries) {
1224                 #'100644        blob    0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa        panic.c'
1225                 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1226                 my $t_mode = $1;
1227                 my $t_type = $2;
1228                 my $t_hash = $3;
1229                 my $t_name = $4;
1230                 $file_key = ";f=$base$t_name";
1231                 if ($alternate) {
1232                         print "<tr class=\"dark\">\n";
1233                 } else {
1234                         print "<tr class=\"light\">\n";
1235                 }
1236                 $alternate ^= 1;
1237                 print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n";
1238                 if ($t_type eq "blob") {
1239                         print "<td class=\"list\">" .
1240                               $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key, -class => "list"}, $t_name) .
1241                               "</td>\n" .
1242                               "<td class=\"link\">" .
1243                               $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key}, "blob") .
1244                               " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base" . $file_key}, "history") .
1245                               "</td>\n";
1246                 } elsif ($t_type eq "tree") {
1247                         print "<td class=\"list\">" .
1248                               $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key}, $t_name) .
1249                               "</td>\n" .
1250                               "<td class=\"link\">" .
1251                               $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key}, "tree") .
1252                               "</td>\n";
1253                 }
1254                 print "</tr>\n";
1255         }
1256         print "</table>\n" .
1257               "</div>";
1258         git_footer_html();
1259 }
1260
1261 sub git_rss {
1262         # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1263         open my $fd, "-|", "$gitbin/git-rev-list --max-count=20 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
1264         my (@revlist) = map { chomp; $_ } <$fd>;
1265         close $fd or die_error(undef, "Reading rev-list failed.");
1266
1267         print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1268         print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1269               "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1270         print "<channel>\n";
1271         print "<title>$project</title>\n".
1272               "<link>" . escapeHTML("$my_url?p=$project;a=summary") . "</link>\n".
1273               "<description>$project log</description>\n".
1274               "<language>en</language>\n";
1275
1276         foreach my $commit (@revlist) {
1277                 my %co = git_read_commit($commit);
1278                 my %cd = date_str($co{'committer_epoch'});
1279                 print "<item>\n" .
1280                       "<title>" .
1281                       sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . escapeHTML($co{'title'}) .
1282                       "</title>\n" .
1283                       "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1284                       "<link>" . escapeHTML("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1285                       "<description>" . escapeHTML($co{'title'}) . "</description>\n" .
1286                       "<content:encoded>" .
1287                       "<![CDATA[\n";
1288                 my $comment = $co{'comment'};
1289                 foreach my $line (@$comment) {
1290                         print "$line<br/>\n";
1291                 }
1292                 print "]]>\n" .
1293                       "</content:encoded>\n" .
1294                       "</item>\n";
1295         }
1296         print "</channel></rss>";
1297 }
1298
1299 sub git_opml {
1300         my @list = git_read_projects();
1301
1302         print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1303         print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1304               "<opml version=\"1.0\">\n".
1305               "<head>".
1306               "  <title>Git OPML Export</title>\n".
1307               "</head>\n".
1308               "<body>\n".
1309               "<outline text=\"git RSS feeds\">\n";
1310
1311         foreach my $pr (@list) {
1312                 my %proj = %$pr;
1313                 my $head = git_read_hash("$proj{'path'}/HEAD");
1314                 if (!defined $head) {
1315                         next;
1316                 }
1317                 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1318                 my %co = git_read_commit($head);
1319                 if (!%co) {
1320                         next;
1321                 }
1322
1323                 my $path = escapeHTML(chop_str($proj{'path'}, 25, 5));
1324                 my $rss =  "$my_url?p=$proj{'path'};a=rss";
1325                 my $html =  "$my_url?p=$proj{'path'};a=summary";
1326                 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1327         }
1328         print "</outline>\n".
1329               "</body>\n".
1330               "</opml>\n";
1331 }
1332
1333 sub git_log {
1334         my $head = git_read_hash("$project/HEAD");
1335         if (!defined $hash) {
1336                 $hash = $head;
1337         }
1338         if (!defined $page) {
1339                 $page = 0;
1340         }
1341         git_header_html();
1342         print "<div class=\"page_nav\">\n";
1343         print $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1344               " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1345               " | log" .
1346               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1347               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1348               " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
1349
1350         my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1351         open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1352         my (@revlist) = map { chomp; $_ } <$fd>;
1353         close $fd;
1354
1355         if ($hash ne $head || $page) {
1356                 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, "HEAD");
1357         } else {
1358                 print "HEAD";
1359         }
1360         if ($page > 0) {
1361                 print " &sdot; " .
1362                 $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash;pg=" . ($page-1), -accesskey => "p", -title => "Alt-p"}, "prev");
1363         } else {
1364                 print " &sdot; prev";
1365         }
1366         if ($#revlist >= (100 * ($page+1)-1)) {
1367                 print " &sdot; " .
1368                 $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash;pg=" . ($page+1), -accesskey => "n", -title => "Alt-n"}, "next");
1369         } else {
1370                 print " &sdot; next";
1371         }
1372         print "<br/>\n" .
1373               "</div>\n";
1374         if (!@revlist) {
1375                 print "<div>\n" .
1376                       $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "&nbsp;") .
1377                       "</div>\n";
1378                 my %co = git_read_commit($hash);
1379                 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1380         }
1381         for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1382                 my $commit = $revlist[$i];
1383                 my %co = git_read_commit($commit);
1384                 next if !%co;
1385                 my %ad = date_str($co{'author_epoch'});
1386                 print "<div>\n" .
1387                       $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
1388                       "<span class=\"age\">$co{'age_string'}</span>" . escapeHTML($co{'title'})) . "\n" .
1389                       "</div>\n";
1390                 print "<div class=\"title_text\">\n" .
1391                       "<div class=\"log_link\">\n" .
1392                       $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1393                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
1394                       "<br/>\n" .
1395                       "</div>\n" .
1396                       "<i>" . escapeHTML($co{'author_name'}) .  " [$ad{'rfc2822'}]</i><br/>\n" .
1397                       "</div>\n" .
1398                       "<div class=\"log_body\">\n";
1399                 my $comment = $co{'comment'};
1400                 my $empty = 0;
1401                 foreach my $line (@$comment) {
1402                         if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1403                                 next;
1404                         }
1405                         if ($line eq "") {
1406                                 if ($empty) {
1407                                         next;
1408                                 }
1409                                 $empty = 1;
1410                         } else {
1411                                 $empty = 0;
1412                         }
1413                         print format_log_line_html($line) . "<br/>\n";
1414                 }
1415                 if (!$empty) {
1416                         print "<br/>\n";
1417                 }
1418                 print "</div>\n";
1419         }
1420         git_footer_html();
1421 }
1422
1423 sub git_commit {
1424         my %co = git_read_commit($hash);
1425         if (!%co) {
1426                 die_error(undef, "Unknown commit object.");
1427         }
1428         my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1429         my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1430
1431         my @difftree;
1432         my $root = "";
1433         if (!defined $co{'parent'}) {
1434                 $root = " --root";
1435         }
1436         open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $co{'parent'} $hash" or die_error(undef, "Open failed.");
1437         @difftree = map { chomp; $_ } <$fd>;
1438         close $fd or die_error(undef, "Reading diff-tree failed.");
1439         git_header_html();
1440         print "<div class=\"page_nav\">\n" .
1441               $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1442               " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1443               " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1444               " | commit";
1445         if (defined $co{'parent'}) {
1446                 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff");
1447         }
1448         print " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "\n" .
1449               "<br/><br/></div>\n";
1450         if (defined $co{'parent'}) {
1451                 print "<div>\n" .
1452                       $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1453                       "</div>\n";
1454         } else {
1455                 print "<div>\n" .
1456                       $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1457                       "</div>\n";
1458         }
1459         print "<div class=\"title_text\">\n" .
1460               "<table cellspacing=\"0\">\n";
1461         print "<tr><td>author</td><td>" . escapeHTML($co{'author'}) . "</td></tr>\n".
1462               "<tr>" .
1463               "<td></td><td> $ad{'rfc2822'}";
1464         if ($ad{'hour_local'} < 6) {
1465                 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1466         } else {
1467                 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1468         }
1469         print "</td>" .
1470               "</tr>\n";
1471         print "<tr><td>committer</td><td>" . escapeHTML($co{'committer'}) . "</td></tr>\n";
1472         print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1473         print "<tr><td>commit</td><td style=\"font-family:monospace\">$hash</td></tr>\n";
1474         print "<tr>" .
1475               "<td>tree</td>" .
1476               "<td style=\"font-family:monospace\">" .
1477               $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", class => "list"}, $co{'tree'}) .
1478               "</td>" .
1479               "<td class=\"link\">" . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1480               "</td>" .
1481               "</tr>\n";
1482         my $parents  = $co{'parents'};
1483         foreach my $par (@$parents) {
1484                 print "<tr>" .
1485                       "<td>parent</td>" .
1486                       "<td style=\"font-family:monospace\">" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par", class => "list"}, $par) . "</td>" .
1487                       "<td class=\"link\">" .
1488                       $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, "commit") .
1489                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash;hp=$par"}, "commitdiff") .
1490                       "</td>" .
1491                       "</tr>\n";
1492         }
1493         print "</table>". 
1494               "</div>\n";
1495         print "<div class=\"page_body\">\n";
1496         my $comment = $co{'comment'};
1497         my $empty = 0;
1498         my $signed = 0;
1499         foreach my $line (@$comment) {
1500                 # print only one empty line
1501                 if ($line eq "") {
1502                         if ($empty || $signed) {
1503                                 next;
1504                         }
1505                         $empty = 1;
1506                 } else {
1507                         $empty = 0;
1508                 }
1509                 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1510                         $signed = 1;
1511                         print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
1512                 } else {
1513                         $signed = 0;
1514                         print format_log_line_html($line) . "<br/>\n";
1515                 }
1516         }
1517         print "</div>\n";
1518         print "<div class=\"list_head\">\n";
1519         if ($#difftree > 10) {
1520                 print(($#difftree + 1) . " files changed:\n");
1521         }
1522         print "</div>\n";
1523         print "<table cellspacing=\"0\">\n";
1524         my $alternate = 0;
1525         foreach my $line (@difftree) {
1526                 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M      ls-files.c'
1527                 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M      rev-tree.c'
1528                 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/;
1529                 my $from_mode = $1;
1530                 my $to_mode = $2;
1531                 my $from_id = $3;
1532                 my $to_id = $4;
1533                 my $status = $5;
1534                 my $similarity = $6;
1535                 my $file = $7;
1536                 #print "$line ($status)<br/>\n";
1537                 if ($alternate) {
1538                         print "<tr class=\"dark\">\n";
1539                 } else {
1540                         print "<tr class=\"light\">\n";
1541                 }
1542                 $alternate ^= 1;
1543                 if ($status eq "A") {
1544                         my $mode_chng = "";
1545                         if (S_ISREG(oct $to_mode)) {
1546                                 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1547                         }
1548                         print "<td>" .
1549                               $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hp=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "</td>\n" .
1550                               "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1551                               "<td class=\"link\">" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob") . "</td>\n";
1552                 } elsif ($status eq "D") {
1553                         print "<td>" .
1554                               $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "</td>\n" .
1555                               "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1556                               "<td class=\"link\">" .
1557                               $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, "blob") .
1558                               " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") .
1559                               "</td>\n"
1560                 } elsif ($status eq "M" || $status eq "T") {
1561                         my $mode_chnge = "";
1562                         if ($from_mode != $to_mode) {
1563                                 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1564                                 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1565                                         $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1566                                 }
1567                                 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1568                                         if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1569                                                 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1570                                         } elsif (S_ISREG($to_mode)) {
1571                                                 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1572                                         }
1573                                 }
1574                                 $mode_chnge .= "]</span>\n";
1575                         }
1576                         print "<td>";
1577                         if ($to_id ne $from_id) {
1578                                 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file));
1579                         } else {
1580                                 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file));
1581                         }
1582                         print "</td>\n" .
1583                               "<td>$mode_chnge</td>\n" .
1584                               "<td class=\"link\">";
1585                         print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob");
1586                         if ($to_id ne $from_id) {
1587                                 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"}, "diff");
1588                         }
1589                         print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "\n";
1590                         print "</td>\n";
1591                 } elsif ($status eq "R") {
1592                         my ($from_file, $to_file) = split "\t", $file;
1593                         my $mode_chng = "";
1594                         if ($from_mode != $to_mode) {
1595                                 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1596                         }
1597                         print "<td>" .
1598                               $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file", -class => "list"}, escapeHTML($to_file)) . "</td>\n" .
1599                               "<td><span style=\"color: #777777;\">[moved from " .
1600                               $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file", -class => "list"}, escapeHTML($from_file)) .
1601                               " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1602                               "<td class=\"link\">" .
1603                               $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"}, "blob");
1604                         if ($to_id ne $from_id) {
1605                                 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file"}, "diff");
1606                         }
1607                         print "</td>\n";
1608                 }
1609                 print "</tr>\n";
1610         }
1611         print "</table>\n";
1612         git_footer_html();
1613 }
1614
1615 sub git_blobdiff {
1616         mkdir($git_temp, 0700);
1617         git_header_html();
1618         if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1619                 print "<div class=\"page_nav\">\n" .
1620                       $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1621                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1622                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1623                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1624                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1625                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") .
1626                       "<br/>\n";
1627                 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent"}, "plain") .
1628                       "</div>\n";
1629                 print "<div>\n" .
1630                       $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1631                       "</div>\n";
1632         } else {
1633                 print "<div class=\"page_nav\">\n" .
1634                       "<br/><br/></div>\n" .
1635                       "<div class=\"title\">$hash vs $hash_parent</div>\n";
1636         }
1637         if (defined $file_name) {
1638                 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1639         }
1640         print "<div class=\"page_body\">\n" .
1641               "<div class=\"diff_info\">blob:" .
1642               $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name"}, $hash_parent) .
1643               " -> blob:" .
1644               $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name"}, $hash) .
1645               "</div>\n";
1646         git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
1647         print "</div>";
1648         git_footer_html();
1649 }
1650
1651 sub git_blobdiff_plain {
1652         mkdir($git_temp, 0700);
1653         print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1654         git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
1655 }
1656
1657 sub git_commitdiff {
1658         mkdir($git_temp, 0700);
1659         my %co = git_read_commit($hash);
1660         if (!%co) {
1661                 die_error(undef, "Unknown commit object.");
1662         }
1663         if (!defined $hash_parent) {
1664                 $hash_parent = $co{'parent'};
1665         }
1666         open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1667         my (@difftree) = map { chomp; $_ } <$fd>;
1668         close $fd or die_error(undef, "Reading diff-tree failed.");
1669
1670         git_header_html();
1671         print "<div class=\"page_nav\">\n" .
1672               $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1673               " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1674               " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1675               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1676               " | commitdiff" .
1677               " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "<br/>\n";
1678         print $cgi->a({-href => "$my_uri?p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent"}, "plain") . "\n" .
1679               "</div>\n";
1680         print "<div>\n" .
1681               $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1682               "</div>\n";
1683         print "<div class=\"page_body\">\n";
1684         my $comment = $co{'comment'};
1685         my $empty = 0;
1686         my $signed = 0;
1687         my @log = @$comment;
1688         # remove first and empty lines after that
1689         shift @log;
1690         while (defined $log[0] && $log[0] eq "") {
1691                 shift @log;
1692         }
1693         foreach my $line (@log) {
1694                 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1695                         next;
1696                 }
1697                 if ($line eq "") {
1698                         if ($empty) {
1699                                 next;
1700                         }
1701                         $empty = 1;
1702                 } else {
1703                         $empty = 0;
1704                 }
1705                 print format_log_line_html($line) . "<br/>\n";
1706         }
1707         print "<br/>\n";
1708         foreach my $line (@difftree) {
1709                 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M      ls-files.c'
1710                 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M      rev-tree.c'
1711                 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1712                 my $from_mode = $1;
1713                 my $to_mode = $2;
1714                 my $from_id = $3;
1715                 my $to_id = $4;
1716                 my $status = $5;
1717                 my $file = $6;
1718                 if ($status eq "A") {
1719                         print "<div class=\"diff_info\">" .  file_type($to_mode) . ":" .
1720                               $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id) . "(new)" .
1721                               "</div>\n";
1722                         git_diff_print(undef, "/dev/null", $to_id, "b/$file");
1723                 } elsif ($status eq "D") {
1724                         print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
1725                               $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) . "(deleted)" .
1726                               "</div>\n";
1727                         git_diff_print($from_id, "a/$file", undef, "/dev/null");
1728                 } elsif ($status eq "M") {
1729                         if ($from_id ne $to_id) {
1730                                 print "<div class=\"diff_info\">" .
1731                                       file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) .
1732                                       " -> " .
1733                                       file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id);
1734                                 print "</div>\n";
1735                                 git_diff_print($from_id, "a/$file",  $to_id, "b/$file");
1736                         }
1737                 }
1738         }
1739         print "<br/>\n" .
1740               "</div>";
1741         git_footer_html();
1742 }
1743
1744 sub git_commitdiff_plain {
1745         mkdir($git_temp, 0700);
1746         open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1747         my (@difftree) = map { chomp; $_ } <$fd>;
1748         close $fd or die_error(undef, "Reading diff-tree failed.");
1749
1750         # try to figure out the next tag after this commit
1751         my $tagname;
1752         my %taghash;
1753         my $tags = git_read_refs("refs/tags");
1754         foreach my $entry (@$tags) {
1755                 my %tag = %$entry;
1756                 $taghash{$tag{'id'}} = $tag{'name'};
1757         }
1758         open $fd, "-|", "$gitbin/git-rev-list HEAD";
1759         while (my $commit = <$fd>) {
1760                 chomp $commit;
1761                 if ($taghash{$commit}) {
1762                         $tagname = $taghash{$commit};
1763                 }
1764                 if ($commit eq $hash) {
1765                         last;
1766                 }
1767         }
1768         close $fd;
1769
1770         print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1771         my %co = git_read_commit($hash);
1772         my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1773         my $comment = $co{'comment'};
1774         print "From: $co{'author'}\n" .
1775               "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
1776               "Subject: $co{'title'}\n";
1777         if (defined $tagname) {
1778               print "X-Git-Tag: $tagname\n";
1779         }
1780         print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
1781               "\n";
1782
1783         foreach my $line (@$comment) {;
1784                 print "  $line\n";
1785         }
1786         print "---\n\n";
1787
1788         foreach my $line (@difftree) {
1789                 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1790                 my $from_id = $3;
1791                 my $to_id = $4;
1792                 my $status = $5;
1793                 my $file = $6;
1794                 if ($status eq "A") {
1795                         git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
1796                 } elsif ($status eq "D") {
1797                         git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
1798                 } elsif ($status eq "M") {
1799                         git_diff_print($from_id, "a/$file",  $to_id, "b/$file", "plain");
1800                 }
1801         }
1802 }
1803
1804 sub git_history {
1805         if (!defined $hash) {
1806                 $hash = git_read_hash("$project/HEAD");
1807         }
1808         my %co = git_read_commit($hash);
1809         if (!%co) {
1810                 die_error(undef, "Unknown commit object.");
1811         }
1812         git_header_html();
1813         print "<div class=\"page_nav\">\n" .
1814               $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1815               " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1816               " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1817               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1818               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1819               " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1820               "<br/><br/>\n" .
1821               "</div>\n";
1822         print "<div>\n" .
1823               $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1824               "</div>\n";
1825         print "<div class=\"page_path\"><b>/$file_name</b><br/></div>\n";
1826
1827         open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin $file_name";
1828         my $commit;
1829         print "<table cellspacing=\"0\">\n";
1830         my $alternate = 0;
1831         while (my $line = <$fd>) {
1832                 if ($line =~ m/^([0-9a-fA-F]{40})/){
1833                         $commit = $1;
1834                         next;
1835                 }
1836                 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
1837                         my %co = git_read_commit($commit);
1838                         if (!%co) {
1839                                 next;
1840                         }
1841                         if ($alternate) {
1842                                 print "<tr class=\"dark\">\n";
1843                         } else {
1844                                 print "<tr class=\"light\">\n";
1845                         }
1846                         $alternate ^= 1;
1847                         print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1848                               "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1849                               "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
1850                               escapeHTML(chop_str($co{'title'}, 50)) . "</b>") . "</td>\n" .
1851                               "<td class=\"link\">" .
1852                               $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1853                               " | " . $cgi->a({-href => "$my_uri?p=$project;a=blob;hb=$commit;f=$file_name"}, "blob");
1854                         my $blob = git_get_hash_by_path($hash, $file_name);
1855                         my $blob_parent = git_get_hash_by_path($commit, $file_name);
1856                         if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
1857                                 print " | " .
1858                                 $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name"},
1859                                 "diff to current");
1860                         }
1861                         print "</td>\n" .
1862                               "</tr>\n";
1863                         undef $commit;
1864                 }
1865         }
1866         print "</table>\n";
1867         close $fd;
1868         git_footer_html();
1869 }
1870
1871 sub git_search {
1872         if (!defined $searchtext) {
1873                 die_error("", "Text field empty.");
1874         }
1875         if (!defined $hash) {
1876                 $hash = git_read_hash("$project/HEAD");
1877         }
1878         my %co = git_read_commit($hash);
1879         if (!%co) {
1880                 die_error(undef, "Unknown commit object.");
1881         }
1882         # pickaxe may take all resources of your box and run for several minutes
1883         # with every query - so decide by yourself how public you make this feature :)
1884         my $commit_search = 1;
1885         my $author_search = 0;
1886         my $committer_search = 0;
1887         my $pickaxe_search = 0;
1888         if ($searchtext =~ s/^author\\://i) {
1889                 $author_search = 1;
1890         } elsif ($searchtext =~ s/^committer\\://i) {
1891                 $committer_search = 1;
1892         } elsif ($searchtext =~ s/^pickaxe\\://i) {
1893                 $commit_search = 0;
1894                 $pickaxe_search = 1;
1895         }
1896         git_header_html();
1897         print "<div class=\"page_nav\">\n" .
1898               $cgi->a({-href => "$my_uri?p=$project;a=summary;h=$hash"}, "summary") .
1899               " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1900               " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1901               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1902               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1903               " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1904               "<br/><br/>\n" .
1905               "</div>\n";
1906
1907         print "<div>\n" .
1908               $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1909               "</div>\n";
1910         print "<table cellspacing=\"0\">\n";
1911         my $alternate = 0;
1912         if ($commit_search) {
1913                 $/ = "\0";
1914                 open my $fd, "-|", "$gitbin/git-rev-list --header $hash";
1915                 while (my $commit_text = <$fd>) {
1916                         if (!grep m/$searchtext/i, $commit_text) {
1917                                 next;
1918                         }
1919                         if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
1920                                 next;
1921                         }
1922                         if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
1923                                 next;
1924                         }
1925                         my @commit_lines = split "\n", $commit_text;
1926                         my $commit = shift @commit_lines;
1927                         my %co = git_read_commit($commit, \@commit_lines);
1928                         if (!%co) {
1929                                 next;
1930                         }
1931                         if ($alternate) {
1932                                 print "<tr class=\"dark\">\n";
1933                         } else {
1934                                 print "<tr class=\"light\">\n";
1935                         }
1936                         $alternate ^= 1;
1937                         print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1938                               "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
1939                               "<td>" .
1940                               $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" . escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
1941                         my $comment = $co{'comment'};
1942                         foreach my $line (@$comment) {
1943                                 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
1944                                         my $lead = escapeHTML($1) || "";
1945                                         $lead = chop_str($lead, 30, 10);
1946                                         my $match = escapeHTML($2) || "";
1947                                         my $trail = escapeHTML($3) || "";
1948                                         $trail = chop_str($trail, 30, 10);
1949                                         my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
1950                                         print chop_str($text, 80, 5) . "<br/>\n";
1951                                 }
1952                         }
1953                         print "</td>\n" .
1954                               "<td class=\"link\">" .
1955                               $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1956                               " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$commit"}, "tree");
1957                         print "</td>\n" .
1958                               "</tr>\n";
1959                 }
1960                 close $fd;
1961         }
1962
1963         if ($pickaxe_search) {
1964                 $/ = "\n";
1965                 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S$searchtext";
1966                 undef %co;
1967                 my @files;
1968                 while (my $line = <$fd>) {
1969                         if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
1970                                 my %set;
1971                                 $set{'file'} = $6;
1972                                 $set{'from_id'} = $3;
1973                                 $set{'to_id'} = $4;
1974                                 $set{'id'} = $set{'to_id'};
1975                                 if ($set{'id'} =~ m/0{40}/) {
1976                                         $set{'id'} = $set{'from_id'};
1977                                 }
1978                                 if ($set{'id'} =~ m/0{40}/) {
1979                                         next;
1980                                 }
1981                                 push @files, \%set;
1982                         } elsif ($line =~ m/^([0-9a-fA-F]{40}) /){
1983                                 if (%co) {
1984                                         if ($alternate) {
1985                                                 print "<tr class=\"dark\">\n";
1986                                         } else {
1987                                                 print "<tr class=\"light\">\n";
1988                                         }
1989                                         $alternate ^= 1;
1990                                         print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1991                                               "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
1992                                               "<td>" .
1993                                               $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}", -class => "list"}, "<b>" .
1994                                               escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
1995                                         while (my $setref = shift @files) {
1996                                                 my %set = %$setref;
1997                                                 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}", class => "list"},
1998                                                       "<span style=\"color:#e00000\">" . escapeHTML($set{'file'}) . "</span>") .
1999                                                       "<br/>\n";
2000                                         }
2001                                         print "</td>\n" .
2002                                               "<td class=\"link\">" .
2003                                               $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}"}, "commit") .
2004                                               " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}"}, "tree");
2005                                         print "</td>\n" .
2006                                               "</tr>\n";
2007                                 }
2008                                 %co = git_read_commit($1);
2009                         }
2010                 }
2011                 close $fd;
2012         }
2013         print "</table>\n";
2014         git_footer_html();
2015 }
2016
2017 sub git_shortlog {
2018         my $head = git_read_hash("$project/HEAD");
2019         if (!defined $hash) {
2020                 $hash = $head;
2021         }
2022         if (!defined $page) {
2023                 $page = 0;
2024         }
2025         git_header_html();
2026         print "<div class=\"page_nav\">\n" .
2027               $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
2028               " | shortlog" .
2029               " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
2030               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
2031               " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
2032               " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
2033
2034         my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2035         open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
2036         my (@revlist) = map { chomp; $_ } <$fd>;
2037         close $fd;
2038
2039         if ($hash ne $head || $page) {
2040                 print $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "HEAD");
2041         } else {
2042                 print "HEAD";
2043         }
2044         if ($page > 0) {
2045                 print " &sdot; " .
2046                 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page-1), -accesskey => "p", -title => "Alt-p"}, "prev");
2047         } else {
2048                 print " &sdot; prev";
2049         }
2050         if ($#revlist >= (100 * ($page+1)-1)) {
2051                 print " &sdot; " .
2052                 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1), -accesskey => "n", -title => "Alt-n"}, "next");
2053         } else {
2054                 print " &sdot; next";
2055         }
2056         print "<br/>\n" .
2057               "</div>\n";
2058         print "<div>\n" .
2059               $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "&nbsp;") .
2060               "</div>\n";
2061         print "<table cellspacing=\"0\">\n";
2062         my $alternate = 0;
2063         for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2064                 my $commit = $revlist[$i];
2065                 my %co = git_read_commit($commit);
2066                 my %ad = date_str($co{'author_epoch'});
2067                 if ($alternate) {
2068                         print "<tr class=\"dark\">\n";
2069                 } else {
2070                         print "<tr class=\"light\">\n";
2071                 }
2072                 $alternate ^= 1;
2073                 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2074                       "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2075                       "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
2076                       escapeHTML($co{'title_short'}) . "</b>") . "</td>\n" .
2077                       "<td class=\"link\">" .
2078                       $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
2079                       " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
2080                       "</td>\n" .
2081                       "</tr>";
2082         }
2083         if ($#revlist >= (100 * ($page+1)-1)) {
2084                 print "<tr>\n" .
2085                       "<td>" .
2086                       $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1), -title => "Alt-n"}, "next") .
2087                       "</td>\n" .
2088                       "</tr>\n";
2089         }
2090         print "</table\n>";
2091         git_footer_html();
2092 }