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