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