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