Refactor committags support, fix BUG(868) properly
[git/jnareb-git.git] / gitweb.cgi
blob4c46db72e4b42b070468f848a3a5d920ac086198
1 #!/usr/bin/perl
3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke <ch@gierke.de>
8 # This program is licensed under the GPLv2
10 use strict;
11 use warnings;
12 use CGI qw(:standard :escapeHTML -nosticky);
13 use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
15 use Encode;
16 use Fcntl ':mode';
17 use File::Temp qw(tempfile);
18 binmode STDOUT, ':utf8';
20 my $cgi = new CGI;
21 my $version = "264";
22 my $my_url = $cgi->url();
23 my $my_uri = $cgi->url(-absolute => 1);
24 my $rss_link = "";
26 # absolute fs-path which will be prepended to the project path
27 #my $projectroot = "/pub/scm";
28 my $projectroot = "/home/kay/public_html/pub/scm";
30 # location of the git-core binaries
31 my $gitbin = "/usr/bin";
33 # location for temporary files needed for diffs
34 my $git_temp = "/tmp/gitweb";
36 # target of the home link on top of all pages
37 my $home_link = $my_uri;
39 # html text to include at home page
40 my $home_text = "indextext.html";
42 # source of projects list
43 #my $projects_list = $projectroot;
44 my $projects_list = "index/index.aux";
46 # where to find etags
47 my $etagsbin = "etags";
49 my $snapshots_url = "http://git.xmms.se/snapshot.cgi";
50 my $git_base_url = "git://git.xmms.se/xmms2";
52 # syntax highlighting
53 my %highlight = (
54 "SConstruct" => "py",
55 "Program" => "py",
56 "Library" => "py",
57 "\.py\$" => "py",
58 "\.c\$" => "c",
59 "\.h\$" => "c",
60 "\.cpp\$" => "cpp",
61 "\.rb\$" => "ruby",
62 "\.java\$" => "java",
63 "\.cgi\$" => "pl",
64 "\.css\$" => "css",
65 "\.cfg\$" => "ini",
66 "\.kid\$" => "html",
67 "Makefile" => "make",
68 "\.pyx\$" => "pyx",
69 "\.js\$" => "js",
72 # custom stuff - mantis/commit tags integration
73 sub committags_real {
74 my $a = shift;
75 my $href = shift || undef;
76 my $class = shift || "";
77 my $aStart = "";
78 my $aEnd = "";
79 if (defined $href) {
80 $aStart = "</a>";
81 if ($class ne "") {
82 $class = "class=\"$class\"";
84 $aEnd = "<a $class href=\"$href\">";
86 $a =~ s!BUG\(([0-9]*)\)!$aStart<a href="http://bugs.xmms2.xmms.se/view.php?id=$1">BUG($1)</a>$aEnd!g;
87 $a =~ s!FEATURE\(([0-9]*)\)!$aStart<a href="http://bugs.xmms2.xmms.se/view.php?id=$1">FEATURE($1)</a>$aEnd!g;
88 $a =~ s!RELEASE: (.*)!RELEASE: $aStart<a href="http://wiki.xmms2.xmms.se/index.php/Release:$1">$1</a>$aEnd!g;
89 return $a;
92 sub committags($){
93 my $a = shift;
94 return committags_real($a);
96 sub committags_shortlog($$){
97 my $a = shift;
98 my $href = shift;
99 return committags_real($a, $href, "list");
102 # custom stuff - refactored navbar
103 sub git_navbar($$$$) {
104 my $project = shift;
105 my $head = shift;
106 my $curSection = shift;
107 my $extraLinks = shift;
109 my $sumLink = $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary");
110 my $slogLink = $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog");
111 my $logLink = $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log");
112 my $comLink = $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit");
113 my $comdifLink = $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff");
114 my $treeLink = $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree")}, "tree");
115 my $snapLink = $cgi->a({-href => "$snapshots_url?tree=$project&commit=HEAD"}, "latest snapshot");
117 if ($curSection eq "summary") {
118 $sumLink = "summary";
120 elsif ($curSection eq "shortlog") {
121 $slogLink = "shortlog";
123 elsif ($curSection eq "log") {
124 $logLink = "log";
126 elsif ($curSection eq "commit") {
127 $comLink = "commit";
129 elsif ($curSection eq "commitdiff") {
130 $comdifLink = "commitdiff";
132 elsif ($curSection eq "tree") {
133 $treeLink = "tree";
136 my $retVal = "<div class=\"page_nav\">\n" .
137 $sumLink .
138 " | " . $slogLink .
139 " | " . $logLink .
140 " | " . $comLink .
141 " | " . $comdifLink .
142 " | " . $treeLink .
143 " | " . $snapLink .
144 "<br/>$extraLinks<br/>\n" .
145 "</div>\n";
146 return $retVal;
149 # input validation and dispatch
150 my $action = $cgi->param('a');
151 if (defined $action) {
152 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
153 undef $action;
154 die_error(undef, "Invalid action parameter.");
156 if ($action eq "git-logo.png") {
157 git_logo();
158 exit;
159 } elsif ($action eq "opml") {
160 git_opml();
161 exit;
165 my $order = $cgi->param('o');
166 if (defined $order) {
167 if ($order =~ m/[^0-9a-zA-Z_]/) {
168 undef $order;
169 die_error(undef, "Invalid order parameter.");
173 my $project = $cgi->param('p');
174 if (defined $project) {
175 $project = validate_input($project);
176 if (!defined($project)) {
177 die_error(undef, "Invalid project parameter.");
179 if (!(-d "$projectroot/$project")) {
180 undef $project;
181 die_error(undef, "No such directory.");
183 if (!(-e "$projectroot/$project/HEAD")) {
184 undef $project;
185 die_error(undef, "No such project.");
187 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param($project) . " log\" href=\"" .
188 "$my_uri?" . esc_param("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
189 $ENV{'GIT_DIR'} = "$projectroot/$project";
190 } else {
191 git_project_list();
192 exit;
195 my $file_name = $cgi->param('f');
196 if (defined $file_name) {
197 $file_name = validate_input($file_name);
198 if (!defined($file_name)) {
199 die_error(undef, "Invalid file parameter.");
203 my $hash = $cgi->param('h');
204 if (defined $hash) {
205 $hash = validate_input($hash);
206 if (!defined($hash)) {
207 die_error(undef, "Invalid hash parameter.");
211 my $hash_parent = $cgi->param('hp');
212 if (defined $hash_parent) {
213 $hash_parent = validate_input($hash_parent);
214 if (!defined($hash_parent)) {
215 die_error(undef, "Invalid hash parent parameter.");
219 my $hash_base = $cgi->param('hb');
220 if (defined $hash_base) {
221 $hash_base = validate_input($hash_base);
222 if (!defined($hash_base)) {
223 die_error(undef, "Invalid hash base parameter.");
227 my $page = $cgi->param('pg');
228 if (defined $page) {
229 if ($page =~ m/[^0-9]$/) {
230 undef $page;
231 die_error(undef, "Invalid page parameter.");
235 my $searchtext = $cgi->param('s');
236 if (defined $searchtext) {
237 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
238 undef $searchtext;
239 die_error(undef, "Invalid search parameter.");
241 $searchtext = quotemeta $searchtext;
244 sub validate_input {
245 my $input = shift;
247 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
248 return $input;
250 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
251 return undef;
253 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
254 return undef;
256 return $input;
259 if (!defined $action || $action eq "summary") {
260 git_summary();
261 exit;
262 } elsif ($action eq "heads") {
263 git_heads();
264 exit;
265 } elsif ($action eq "tags") {
266 git_tags();
267 exit;
268 } elsif ($action eq "blob") {
269 git_blob();
270 exit;
271 } elsif ($action eq "blob_plain") {
272 git_blob_plain();
273 exit;
274 } elsif ($action eq "tree") {
275 git_tree();
276 exit;
277 } elsif ($action eq "rss") {
278 git_rss();
279 exit;
280 } elsif ($action eq "commit") {
281 git_commit();
282 exit;
283 } elsif ($action eq "log") {
284 git_log();
285 exit;
286 } elsif ($action eq "blobdiff") {
287 git_blobdiff();
288 exit;
289 } elsif ($action eq "blobdiff_plain") {
290 git_blobdiff_plain();
291 exit;
292 } elsif ($action eq "commitdiff") {
293 git_commitdiff();
294 exit;
295 } elsif ($action eq "commitdiff_plain") {
296 git_commitdiff_plain();
297 exit;
298 } elsif ($action eq "history") {
299 git_history();
300 exit;
301 } elsif ($action eq "search") {
302 git_search();
303 exit;
304 } elsif ($action eq "shortlog") {
305 git_shortlog();
306 exit;
307 } elsif ($action eq "tag") {
308 git_tag();
309 exit;
310 } else {
311 undef $action;
312 die_error(undef, "Unknown action.");
313 exit;
316 # quote unsafe chars, but keep the slash, even when it's not
317 # correct, but quoted slashes look too horrible in bookmarks
318 sub esc_param {
319 my $str = shift;
320 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
321 $str =~ s/\+/%2B/g;
322 $str =~ s/ /\+/g;
323 return $str;
326 # replace invalid utf8 character with SUBSTITUTION sequence
327 sub esc_html {
328 my $str = shift;
329 $str = decode("utf8", $str, Encode::FB_DEFAULT);
330 $str = escapeHTML($str);
331 return $str;
334 # git may return quoted and escaped filenames
335 sub unquote {
336 my $str = shift;
337 if ($str =~ m/^"(.*)"$/) {
338 $str = $1;
339 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
341 return $str;
344 sub git_header_html {
345 my $status = shift || "200 OK";
346 my $expires = shift;
348 my $title = "git";
349 if (defined $project) {
350 $title .= " - $project";
351 if (defined $action) {
352 $title .= "/$action";
355 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires);
356 print <<EOF;
357 <?xml version="1.0" encoding="utf-8"?>
358 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
359 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
360 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
361 <head>
362 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
363 <meta name="robots" content="index, nofollow"/>
364 <title>$title</title>
365 $rss_link
366 <link rel="stylesheet" type="text/css" href="gitweb-style.css"/>
367 </head>
368 <body>
370 print "<div class=\"page_header\">\n" .
371 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
372 "<img src=\"$my_uri?" . esc_param("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
373 "</a>\n";
374 print $cgi->a({-href => esc_param($home_link)}, "projects") . " / ";
375 if (defined $project) {
376 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, esc_html($project));
377 if (defined $action) {
378 print " / $action";
380 print "\n";
381 if (!defined $searchtext) {
382 $searchtext = "";
384 my $search_hash;
385 if (defined $hash) {
386 $search_hash = $hash;
387 } else {
388 $search_hash = "HEAD";
390 $cgi->param("a", "search");
391 $cgi->param("h", $search_hash);
392 print $cgi->startform(-method => "get", -action => $my_uri) .
393 "<div class=\"search\">\n" .
394 $cgi->hidden(-name => "p") . "\n" .
395 $cgi->hidden(-name => "a") . "\n" .
396 $cgi->hidden(-name => "h") . "\n" .
397 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
398 "</div>" .
399 $cgi->end_form() . "\n";
401 print "</div>\n";
404 sub git_footer_html {
405 print "<div class=\"page_footer\">\n";
406 if (defined $project) {
407 my $descr = git_read_description($project);
408 if (defined $descr) {
409 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
411 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
412 } else {
413 print $cgi->a({-href => "$my_uri?" . esc_param("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
415 print "</div>\n" .
416 "</body>\n" .
417 "</html>";
420 sub die_error {
421 my $status = shift || "403 Forbidden";
422 my $error = shift || "Malformed query, file missing or permission denied";
424 git_header_html($status);
425 print "<div class=\"page_body\">\n" .
426 "<br/><br/>\n" .
427 "$status - $error\n" .
428 "<br/>\n" .
429 "</div>\n";
430 git_footer_html();
431 exit;
434 sub git_get_type {
435 my $hash = shift;
437 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
438 my $type = <$fd>;
439 close $fd or return;
440 chomp $type;
441 return $type;
444 sub git_read_head {
445 my $project = shift;
446 my $oENV = $ENV{'GIT_DIR'};
447 my $retval = undef;
448 $ENV{'GIT_DIR'} = "$projectroot/$project";
449 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
450 my $head = <$fd>;
451 close $fd;
452 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
453 $retval = $1;
456 if (defined $oENV) {
457 $ENV{'GIT_DIR'} = $oENV;
459 return $retval;
462 sub git_read_hash {
463 my $path = shift;
465 open my $fd, "$projectroot/$path" or return undef;
466 my $head = <$fd>;
467 close $fd;
468 chomp $head;
469 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
470 return $head;
474 sub git_read_file {
475 my $path = shift;
476 open my $fd, "$path" or return undef;
477 my $content = <$fd>;
478 close $fd;
479 chomp $content;
480 return $content;
483 sub git_read_description {
484 my $path = shift;
485 return git_read_file("$projectroot/$path/description");
488 sub git_read_category {
489 my $path = shift;
490 return git_read_file("$projectroot/$path/category");
493 sub git_read_tag {
494 my $tag_id = shift;
495 my %tag;
496 my @comment;
498 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
499 $tag{'id'} = $tag_id;
500 while (my $line = <$fd>) {
501 chomp $line;
502 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
503 $tag{'object'} = $1;
504 } elsif ($line =~ m/^type (.+)$/) {
505 $tag{'type'} = $1;
506 } elsif ($line =~ m/^tag (.+)$/) {
507 $tag{'name'} = $1;
508 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
509 $tag{'author'} = $1;
510 $tag{'epoch'} = $2;
511 $tag{'tz'} = $3;
512 } elsif ($line =~ m/--BEGIN/) {
513 push @comment, $line;
514 last;
515 } elsif ($line eq "") {
516 last;
519 push @comment, <$fd>;
520 $tag{'comment'} = \@comment;
521 close $fd or return;
522 if (!defined $tag{'name'}) {
523 return
525 return %tag
528 sub age_string {
529 my $age = shift;
530 my $age_str;
532 if ($age > 60*60*24*365*2) {
533 $age_str = (int $age/60/60/24/365);
534 $age_str .= " years ago";
535 } elsif ($age > 60*60*24*(365/12)*2) {
536 $age_str = int $age/60/60/24/(365/12);
537 $age_str .= " months ago";
538 } elsif ($age > 60*60*24*7*2) {
539 $age_str = int $age/60/60/24/7;
540 $age_str .= " weeks ago";
541 } elsif ($age > 60*60*24*2) {
542 $age_str = int $age/60/60/24;
543 $age_str .= " days ago";
544 } elsif ($age > 60*60*2) {
545 $age_str = int $age/60/60;
546 $age_str .= " hours ago";
547 } elsif ($age > 60*2) {
548 $age_str = int $age/60;
549 $age_str .= " min ago";
550 } elsif ($age > 2) {
551 $age_str = int $age;
552 $age_str .= " sec ago";
553 } else {
554 $age_str .= " right now";
556 return $age_str;
559 sub git_read_commit {
560 my $commit_id = shift;
561 my $commit_text = shift;
563 my @commit_lines;
564 my %co;
566 if (defined $commit_text) {
567 @commit_lines = @$commit_text;
568 } else {
569 $/ = "\0";
570 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
571 @commit_lines = split '\n', <$fd>;
572 close $fd or return;
573 $/ = "\n";
574 pop @commit_lines;
576 my $header = shift @commit_lines;
577 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
578 return;
580 ($co{'id'}, my @parents) = split ' ', $header;
581 $co{'parents'} = \@parents;
582 $co{'parent'} = $parents[0];
583 while (my $line = shift @commit_lines) {
584 last if $line eq "\n";
585 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
586 $co{'tree'} = $1;
587 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
588 $co{'author'} = $1;
589 $co{'author_epoch'} = $2;
590 $co{'author_tz'} = $3;
591 if ($co{'author'} =~ m/^([^<]+) </) {
592 $co{'author_name'} = $1;
593 } else {
594 $co{'author_name'} = $co{'author'};
596 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
597 $co{'committer'} = $1;
598 $co{'committer_epoch'} = $2;
599 $co{'committer_tz'} = $3;
600 $co{'committer_name'} = $co{'committer'};
601 $co{'committer_name'} =~ s/ <.*//;
604 if (!defined $co{'tree'}) {
605 return;
608 foreach my $title (@commit_lines) {
609 $title =~ s/^ //;
610 if ($title ne "") {
611 $co{'title'} = chop_str($title, 80, 5);
612 # remove leading stuff of merges to make the interesting part visible
613 if (length($title) > 50) {
614 $title =~ s/^Automatic //;
615 $title =~ s/^merge (of|with) /Merge ... /i;
616 if (length($title) > 50) {
617 $title =~ s/(http|rsync):\/\///;
619 if (length($title) > 50) {
620 $title =~ s/(master|www|rsync)\.//;
622 if (length($title) > 50) {
623 $title =~ s/kernel.org:?//;
625 if (length($title) > 50) {
626 $title =~ s/\/pub\/scm//;
629 $co{'title_short'} = chop_str($title, 50, 5);
630 last;
633 # remove added spaces
634 foreach my $line (@commit_lines) {
635 $line =~ s/^ //;
637 $co{'comment'} = \@commit_lines;
639 my $age = time - $co{'committer_epoch'};
640 $co{'age'} = $age;
641 $co{'age_string'} = age_string($age);
642 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
643 if ($age > 60*60*24*7*2) {
644 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
645 $co{'age_string_age'} = $co{'age_string'};
646 } else {
647 $co{'age_string_date'} = $co{'age_string'};
648 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
650 return %co;
653 sub git_diff_print {
654 my $from = shift;
655 my $from_name = shift;
656 my $to = shift;
657 my $to_name = shift;
658 my $format = shift || "html";
660 my $from_tmp = "/dev/null";
661 my $to_tmp = "/dev/null";
662 my $pid = $$;
664 # create tmp from-file
665 if (defined $from) {
666 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
667 open my $fd2, "> $from_tmp";
668 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
669 my @file = <$fd>;
670 print $fd2 @file;
671 close $fd2;
672 close $fd;
675 # create tmp to-file
676 if (defined $to) {
677 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
678 open my $fd2, "> $to_tmp";
679 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
680 my @file = <$fd>;
681 print $fd2 @file;
682 close $fd2;
683 close $fd;
686 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
687 if ($format eq "plain") {
688 undef $/;
689 print <$fd>;
690 $/ = "\n";
691 } else {
692 while (my $line = <$fd>) {
693 chomp($line);
694 my $char = substr($line, 0, 1);
695 my $color = "";
696 if ($char eq '+') {
697 $color = " style=\"color:#008800;\"";
698 } elsif ($char eq "-") {
699 $color = " style=\"color:#cc0000;\"";
700 } elsif ($char eq "@") {
701 $color = " style=\"color:#990099;\"";
702 } elsif ($char eq "\\") {
703 # skip errors
704 next;
706 while ((my $pos = index($line, "\t")) != -1) {
707 if (my $count = (8 - (($pos-1) % 8))) {
708 my $spaces = ' ' x $count;
709 $line =~ s/\t/$spaces/;
712 print "<div class=\"pre\"$color>" . esc_html($line) . "</div>\n";
715 close $fd;
717 if (defined $from) {
718 unlink($from_tmp);
720 if (defined $to) {
721 unlink($to_tmp);
725 sub mode_str {
726 my $mode = oct shift;
728 if (S_ISDIR($mode & S_IFMT)) {
729 return 'drwxr-xr-x';
730 } elsif (S_ISLNK($mode)) {
731 return 'lrwxrwxrwx';
732 } elsif (S_ISREG($mode)) {
733 # git cares only about the executable bit
734 if ($mode & S_IXUSR) {
735 return '-rwxr-xr-x';
736 } else {
737 return '-rw-r--r--';
739 } else {
740 return '----------';
744 sub chop_str {
745 my $str = shift;
746 my $len = shift;
747 my $add_len = shift || 10;
749 # allow only $len chars, but don't cut a word if it would fit in $add_len
750 # if it doesn't fit, cut it if it's still longer than the dots we would add
751 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
752 my $body = $1;
753 my $tail = $2;
754 if (length($tail) > 4) {
755 $tail = " ...";
757 return "$body$tail";
760 sub file_type {
761 my $mode = oct shift;
763 if (S_ISDIR($mode & S_IFMT)) {
764 return "directory";
765 } elsif (S_ISLNK($mode)) {
766 return "symlink";
767 } elsif (S_ISREG($mode)) {
768 return "file";
769 } else {
770 return "unknown";
774 sub format_log_line_html {
775 my $line = shift;
777 $line = esc_html($line);
778 $line =~ s/ /&nbsp;/g;
779 if ($line =~ m/([0-9a-fA-F]{40})/) {
780 my $hash_text = $1;
781 if (git_get_type($hash_text) eq "commit") {
782 my $link = $cgi->a({-class => "text", -href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_text")}, $hash_text);
783 $line =~ s/$hash_text/$link/;
786 return committags($line);
789 sub date_str {
790 my $epoch = shift;
791 my $tz = shift || "-0000";
793 my %date;
794 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
795 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
796 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
797 $date{'hour'} = $hour;
798 $date{'minute'} = $min;
799 $date{'mday'} = $mday;
800 $date{'day'} = $days[$wday];
801 $date{'month'} = $months[$mon];
802 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
803 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
805 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
806 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
807 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
808 $date{'hour_local'} = $hour;
809 $date{'minute_local'} = $min;
810 $date{'tz_local'} = $tz;
811 return %date;
814 # git-logo (cached in browser for one day)
815 sub git_logo {
816 binmode STDOUT, ':raw';
817 print $cgi->header(-type => 'image/png', -expires => '+1d');
818 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
819 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
820 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
821 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
822 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
823 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
824 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
825 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
826 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
827 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
828 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
829 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
830 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
831 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
834 sub get_file_owner {
835 my $path = shift;
837 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
838 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
839 if (!defined $gcos) {
840 return undef;
842 my $owner = $gcos;
843 $owner =~ s/[,;].*$//;
844 return $owner;
847 sub git_read_projects {
848 my @list;
850 if (-d $projects_list) {
851 # search in directory
852 my $dir = $projects_list;
853 opendir my $dh, $dir or return undef;
854 while (my $dir = readdir($dh)) {
855 if (-e "$projectroot/$dir/HEAD") {
856 my $pr = {
857 path => $dir,
859 push @list, $pr
862 closedir($dh);
863 } elsif (-f $projects_list) {
864 # read from file(url-encoded):
865 # 'git%2Fgit.git Linus+Torvalds'
866 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
867 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
868 open my $fd , $projects_list or return undef;
869 while (my $line = <$fd>) {
870 chomp $line;
871 my ($path, $owner) = split ' ', $line;
872 $path = unescape($path);
873 $owner = unescape($owner);
874 if (!defined $path) {
875 next;
877 if (-e "$projectroot/$path/HEAD") {
878 my $pr = {
879 path => $path,
880 owner => $owner,
882 push @list, $pr
885 close $fd;
887 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
888 return @list;
891 sub git_project_list {
892 my @list = git_read_projects();
893 my %projects;
894 if (!@list) {
895 die_error(undef, "No project found.");
897 foreach my $pr (@list) {
898 my $head = git_read_head($pr->{'path'});
899 if (!defined $head) {
900 next;
902 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
903 my %co = git_read_commit($head);
904 if (!%co) {
905 next;
907 $pr->{'commit'} = \%co;
908 if (!defined $pr->{'descr'}) {
909 my $descr = git_read_description($pr->{'path'}) || "";
910 $pr->{'descr'} = chop_str($descr, 25, 5);
912 if (!defined $pr->{'category'}) {
913 my $cat = git_read_category($pr->{'path'}) || "Misc";
914 $pr->{'category'} = $cat;
916 if (!defined $pr->{'owner'}) {
917 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
919 if (defined $projects{$pr->{'category'}}) {
920 push @{$projects{$pr->{'category'}}}, $pr;
922 else {
923 my @catList = ($pr);
924 $projects{$pr->{'category'}} = \@catList;
927 git_header_html();
928 if (-f $home_text) {
929 print "<div class=\"index_include\">\n";
930 open (my $fd, $home_text);
931 print <$fd>;
932 close $fd;
933 print "</div>\n";
935 print "<table cellspacing=\"0\">\n" .
936 "<tr>\n";
937 print "<th></th>\n" .
938 "</tr>\n";
939 my $alternate = 0;
940 my $headRow = "";
941 my $headDone = 0;
942 foreach my $cat (sort keys %projects) {
943 my @catList = @{$projects{"$cat"}};
945 if (!defined($order) || (defined($order) && ($order eq "project"))) {
946 @catList = sort {$a->{'path'} cmp $b->{'path'}} @catList;
947 $headRow .= "<th>Project</th>\n";
948 } else {
949 $headRow .= "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=project")}, "Project") . "</th>\n";
951 if (defined($order) && ($order eq "descr")) {
952 @catList = sort {$a->{'descr'} cmp $b->{'descr'}} @catList;
953 $headRow .= "<th>Description</th>\n";
954 } else {
955 $headRow .= "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=descr")}, "Description") . "</th>\n";
957 if (defined($order) && ($order eq "owner")) {
958 @catList = sort {$a->{'owner'} cmp $b->{'owner'}} @catList;
959 $headRow .= "<th>Owner</th>\n";
960 } else {
961 $headRow .= "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=owner")}, "Owner") . "</th>\n";
963 if (defined($order) && ($order eq "age")) {
964 @catList = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @catList;
965 $headRow .= "<th>Last Change</th>\n";
966 } else {
967 $headRow .= "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=age")}, "Last Change") . "</th>\n";
970 if (!$headDone) {
971 print '<tr>'.$headRow.'</tr>';
972 $headDone = 1;
975 print "<tr><td colspan=\"5\"><b>" . $cat . "</b></td><tr>";
977 foreach my $pr (@catList) {
978 if ($alternate) {
979 print "<tr class=\"dark\">\n";
980 } else {
981 print "<tr class=\"light\">\n";
983 $alternate ^= 1;
984 print "<td style=\"padding-left: 1em;\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
985 "<td>$pr->{'descr'}</td>\n" .
986 "<td><i>" . chop_str(esc_html($pr->{'owner'}), 15) . "</i></td>\n";
987 my $colored_age;
988 if ($pr->{'commit'}{'age'} < 60*60*2) {
989 $colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>";
990 } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {
991 $colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>";
992 } else {
993 $colored_age = "<i>$pr->{'commit'}{'age_string'}</i>";
995 print "<td>$colored_age</td>\n" .
996 "<td class=\"link\">" .
997 $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") .
998 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") .
999 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") .
1000 " | " . $cgi->a({-href => "$snapshots_url/$pr->{'path'}-snapshot-HEAD.tar.bz2"}, "latest snapshot") .
1001 "</td>\n" .
1002 "</tr>\n";
1005 print "</table>\n";
1006 git_footer_html();
1009 sub read_info_ref {
1010 my $type = shift || "";
1011 my %refs;
1012 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1013 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1014 open my $fd, "$projectroot/$project/info/refs" or return;
1015 while (my $line = <$fd>) {
1016 chomp($line);
1017 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\^]+)/) {
1018 if (defined $refs{$1}) {
1019 $refs{$1} .= " / $2";
1020 } else {
1021 $refs{$1} = $2;
1025 close $fd or return;
1026 return \%refs;
1029 sub git_read_refs {
1030 my $ref_dir = shift;
1031 my @reflist;
1033 my @refs;
1034 opendir my $dh, "$projectroot/$project/$ref_dir";
1035 while (my $dir = readdir($dh)) {
1036 if ($dir =~ m/^\./) {
1037 next;
1039 if (-d "$projectroot/$project/$ref_dir/$dir") {
1040 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
1041 my @subdirs = grep !m/^\./, readdir $dh2;
1042 closedir($dh2);
1043 foreach my $subdir (@subdirs) {
1044 push @refs, "$dir/$subdir"
1046 next;
1048 push @refs, $dir;
1050 closedir($dh);
1051 foreach my $ref_file (@refs) {
1052 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
1053 my $type = git_get_type($ref_id) || next;
1054 my %ref_item;
1055 my %co;
1056 $ref_item{'type'} = $type;
1057 $ref_item{'id'} = $ref_id;
1058 $ref_item{'epoch'} = 0;
1059 $ref_item{'age'} = "unknown";
1060 if ($type eq "tag") {
1061 my %tag = git_read_tag($ref_id);
1062 $ref_item{'comment'} = $tag{'comment'};
1063 if ($tag{'type'} eq "commit") {
1064 %co = git_read_commit($tag{'object'});
1065 $ref_item{'epoch'} = $co{'committer_epoch'};
1066 $ref_item{'age'} = $co{'age_string'};
1067 } elsif (defined($tag{'epoch'})) {
1068 my $age = time - $tag{'epoch'};
1069 $ref_item{'epoch'} = $tag{'epoch'};
1070 $ref_item{'age'} = age_string($age);
1072 $ref_item{'reftype'} = $tag{'type'};
1073 $ref_item{'name'} = $tag{'name'};
1074 $ref_item{'refid'} = $tag{'object'};
1075 } elsif ($type eq "commit"){
1076 %co = git_read_commit($ref_id);
1077 $ref_item{'reftype'} = "commit";
1078 $ref_item{'name'} = $ref_file;
1079 $ref_item{'title'} = $co{'title'};
1080 $ref_item{'refid'} = $ref_id;
1081 $ref_item{'epoch'} = $co{'committer_epoch'};
1082 $ref_item{'age'} = $co{'age_string'};
1085 push @reflist, \%ref_item;
1087 # sort tags by age
1088 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1089 return \@reflist;
1092 sub git_summary {
1093 my $descr = git_read_description($project) || "none";
1094 my $head = git_read_head($project);
1095 my %co = git_read_commit($head);
1096 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1098 my $owner;
1099 if (-f $projects_list) {
1100 open (my $fd , $projects_list);
1101 while (my $line = <$fd>) {
1102 chomp $line;
1103 my ($pr, $ow) = split ' ', $line;
1104 $pr = unescape($pr);
1105 $ow = unescape($ow);
1106 if ($pr eq $project) {
1107 $owner = $ow;
1108 last;
1111 close $fd;
1113 if (!defined $owner) {
1114 $owner = get_file_owner("$projectroot/$project");
1117 my $refs = read_info_ref();
1118 git_header_html();
1119 print git_navbar($project, $head, "summary", "");
1120 print "<div class=\"title\">&nbsp;</div>\n";
1121 print "<table cellspacing=\"0\">\n" .
1122 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
1123 "<tr><td>owner</td><td>" . esc_html($owner) . "</td></tr>\n" .
1124 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1125 "<tr><td>url</td><td>$git_base_url/$project</td></tr>" .
1126 "</table>\n";
1127 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head($project) or die_error(undef, "Open failed.");
1128 my (@revlist) = map { chomp; $_ } <$fd>;
1129 close $fd;
1130 print "<div>\n" .
1131 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1132 "</div>\n";
1133 my $i = 16;
1134 print "<table cellspacing=\"0\">\n";
1135 my $alternate = 0;
1136 foreach my $commit (@revlist) {
1137 my %co = git_read_commit($commit);
1138 my %ad = date_str($co{'author_epoch'});
1139 if ($alternate) {
1140 print "<tr class=\"dark\">\n";
1141 } else {
1142 print "<tr class=\"light\">\n";
1144 $alternate ^= 1;
1145 if ($i-- > 0) {
1146 my $ref = "";
1147 if (defined $refs->{$commit}) {
1148 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
1150 print "<td><i>$co{'age_string'}</i></td>\n" .
1151 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1152 "<td>";
1153 if (length($co{'title_short'}) < length($co{'title'})) {
1154 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
1155 "<b>" . committags_shortlog(esc_html($co{'title_short'}), ("$my_uri?" . esc_param("p=$project;a=commit;h=$commit"))) . "$ref</b>");
1156 } else {
1157 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
1158 "<b>" . committags_shortlog(esc_html($co{'title'}), ("$my_uri?" . esc_param("p=$project;a=commit;h=$commit"))) . "$ref</b>");
1160 print "</td>\n" .
1161 "<td class=\"link\">" .
1162 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1163 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1164 " | " . $cgi->a({-href => "$snapshots_url/$project-snapshot-$commit.tar.bz2"}, "snapshot") .
1165 "</td>\n" .
1166 "</tr>";
1167 } else {
1168 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "...") . "</td>\n" .
1169 "</tr>";
1170 last;
1173 print "</table\n>";
1175 my $taglist = git_read_refs("refs/tags");
1176 if (defined @$taglist) {
1177 print "<div>\n" .
1178 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags"), -class => "title"}, "tags") .
1179 "</div>\n";
1180 my $i = 16;
1181 print "<table cellspacing=\"0\">\n";
1182 my $alternate = 0;
1183 foreach my $entry (@$taglist) {
1184 my %tag = %$entry;
1185 my $comment_lines = $tag{'comment'};
1186 my $comment = shift @$comment_lines;
1187 if (defined($comment)) {
1188 $comment = chop_str($comment, 30, 5);
1190 if ($alternate) {
1191 print "<tr class=\"dark\">\n";
1192 } else {
1193 print "<tr class=\"light\">\n";
1195 $alternate ^= 1;
1196 if ($i-- > 0) {
1197 print "<td><i>$tag{'age'}</i></td>\n" .
1198 "<td>" .
1199 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1200 "<b>" . esc_html($tag{'name'}) . "</b>") .
1201 "</td>\n" .
1202 "<td>";
1203 if (defined($comment)) {
1204 print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1206 print "</td>\n" .
1207 "<td class=\"link\">";
1208 if ($tag{'type'} eq "tag") {
1209 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1211 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1212 if ($tag{'reftype'} eq "commit") {
1213 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1214 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log") .
1215 " | " . $cgi->a({-href => "$snapshots_url/$project-snapshot-$tag{'refid'}.tar.bz2"}, "snapshot");
1217 print "</td>\n" .
1218 "</tr>";
1219 } else {
1220 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags")}, "...") . "</td>\n" .
1221 "</tr>";
1222 last;
1225 print "</table\n>";
1228 my $headlist = git_read_refs("refs/heads");
1229 if (defined @$headlist) {
1230 print "<div>\n" .
1231 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads"), -class => "title"}, "heads") .
1232 "</div>\n";
1233 my $i = 16;
1234 print "<table cellspacing=\"0\">\n";
1235 my $alternate = 0;
1236 foreach my $entry (@$headlist) {
1237 my %tag = %$entry;
1238 if ($alternate) {
1239 print "<tr class=\"dark\">\n";
1240 } else {
1241 print "<tr class=\"light\">\n";
1243 $alternate ^= 1;
1244 if ($i-- > 0) {
1245 print "<td><i>$tag{'age'}</i></td>\n" .
1246 "<td>" .
1247 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1248 "<b>" . esc_html($tag{'name'}) . "</b>") .
1249 "</td>\n" .
1250 "<td class=\"link\">" .
1251 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1252 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1253 "</td>\n" .
1254 "</tr>";
1255 } else {
1256 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads")}, "...") . "</td>\n" .
1257 "</tr>";
1258 last;
1261 print "</table\n>";
1263 git_footer_html();
1266 sub git_tag {
1267 my $head = git_read_head($project);
1268 git_header_html();
1269 print git_navbar($project, $head, "tag", "");
1270 my %tag = git_read_tag($hash);
1271 print "<div>\n" .
1272 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($tag{'name'})) . "\n" .
1273 "</div>\n";
1274 print "<div class=\"title_text\">\n" .
1275 "<table cellspacing=\"0\">\n" .
1276 "<tr>\n" .
1277 "<td>object</td>\n" .
1278 "<td>" . $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1279 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1280 "</tr>\n";
1281 if (defined($tag{'author'})) {
1282 my %ad = date_str($tag{'epoch'}, $tag{'tz'});
1283 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
1284 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1286 print "</table>\n\n" .
1287 "</div>\n";
1288 print "<div class=\"page_body\">";
1289 my $comment = $tag{'comment'};
1290 foreach my $line (@$comment) {
1291 print esc_html($line) . "<br/>\n";
1293 print "</div>\n";
1294 git_footer_html();
1297 sub git_tags {
1298 my $head = git_read_head($project);
1299 git_header_html();
1300 print git_navbar($project, $head, "tags", "");
1301 my $taglist = git_read_refs("refs/tags");
1302 print "<div>\n" .
1303 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, "&nbsp;") .
1304 "</div>\n";
1305 print "<table cellspacing=\"0\">\n";
1306 my $alternate = 0;
1307 if (defined @$taglist) {
1308 foreach my $entry (@$taglist) {
1309 my %tag = %$entry;
1310 my $comment_lines = $tag{'comment'};
1311 my $comment = shift @$comment_lines;
1312 if (defined($comment)) {
1313 $comment = chop_str($comment, 30, 5);
1315 if ($alternate) {
1316 print "<tr class=\"dark\">\n";
1317 } else {
1318 print "<tr class=\"light\">\n";
1320 $alternate ^= 1;
1321 print "<td><i>$tag{'age'}</i></td>\n" .
1322 "<td>" .
1323 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1324 "<b>" . esc_html($tag{'name'}) . "</b>") .
1325 "</td>\n" .
1326 "<td>";
1327 if (defined($comment)) {
1328 print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1330 print "</td>\n" .
1331 "<td class=\"link\">";
1332 if ($tag{'type'} eq "tag") {
1333 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1335 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1336 if ($tag{'reftype'} eq "commit") {
1337 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1338 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log") .
1339 " | " . $cgi->a({-href => "$snapshots_url/$project-snapshot-$tag{'refid'}.tar.bz2"}, "snapshot");
1341 print "</td>\n" .
1342 "</tr>";
1345 print "</table\n>";
1346 git_footer_html();
1349 sub git_heads {
1350 my $head = git_read_head($project);
1351 git_header_html();
1352 print git_navbar($project, $head, "heads", "");
1353 my $taglist = git_read_refs("refs/heads");
1354 print "<div>\n" .
1355 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, "&nbsp;") .
1356 "</div>\n";
1357 print "<table cellspacing=\"0\">\n";
1358 my $alternate = 0;
1359 if (defined @$taglist) {
1360 foreach my $entry (@$taglist) {
1361 my %tag = %$entry;
1362 if ($alternate) {
1363 print "<tr class=\"dark\">\n";
1364 } else {
1365 print "<tr class=\"light\">\n";
1367 $alternate ^= 1;
1368 print "<td><i>$tag{'age'}</i></td>\n" .
1369 "<td>" .
1370 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
1371 "</td>\n" .
1372 "<td class=\"link\">" .
1373 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1374 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1375 "</td>\n" .
1376 "</tr>";
1379 print "</table\n>";
1380 git_footer_html();
1383 sub git_get_hash_by_path {
1384 my $base = shift;
1385 my $path = shift || return undef;
1387 my $tree = $base;
1388 my @parts = split '/', $path;
1389 while (my $part = shift @parts) {
1390 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1391 my (@entries) = map { chomp; $_ } <$fd>;
1392 close $fd or return undef;
1393 foreach my $line (@entries) {
1394 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1395 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1396 my $t_mode = $1;
1397 my $t_type = $2;
1398 my $t_hash = $3;
1399 my $t_name = validate_input(unquote($4));
1400 if ($t_name eq $part) {
1401 if (!(@parts)) {
1402 return $t_hash;
1404 if ($t_type eq "tree") {
1405 $tree = $t_hash;
1407 last;
1413 sub git_blob {
1414 if (!defined $hash && defined $file_name) {
1415 my $base = $hash_base || git_read_head($project);
1416 $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
1418 my $syntax = "txt";
1419 my $ext;
1420 foreach my $key (keys %highlight) {
1421 if ($file_name =~ /$key/) {
1422 $syntax = $highlight{$key};
1423 $ext = $key;
1424 last;
1428 my %tags;
1429 my $suffix = $ext;
1430 $suffix =~ s/\$//;
1431 my ($dpath, $prefix) = $file_name =~ m/(.*\/)?(.*)$ext/;
1432 my ($tmpfh, $tmpname) = tempfile($prefix."XXXXXX", SUFFIX => $suffix, UNLINK => 1, DIR => $git_temp) or die_error(undef, "Could not get tempfile");
1433 close $tmpfh;
1435 my $gcExit = system "$gitbin/git-cat-file blob $hash > $tmpname";
1436 if ($gcExit != 0) {
1437 die_error(undef, "Cannot read blob: git-cat-file returned $gcExit");
1440 if ($etagsbin ne "" and $ext =~ /^\./) {
1441 open my $tmpfd, "-|", "echo '$tmpname' | $etagsbin --filter=yes" or die_error(undef, "Could not read tags for $file_name");
1442 my $count = 0;
1443 while (my $line = <$tmpfd>) {
1444 # discard first 2 lines
1445 if ($count < 2) {
1446 $count++;
1447 next;
1449 my ($tag, $location) = $line =~ m/\x7f(.*)\x01(\d+),/;
1450 if (defined $tags{$location}) {
1451 push @{$tags{$location}}, $tag;
1453 else {
1454 $tags{$location} = [$tag];
1457 close $tmpfd;
1460 open my $fd, "-|", "highlight -t 4 -l -a -f -I --syntax $syntax $tmpname" or die_error(undef, "Open failed.");
1461 git_header_html();
1462 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1463 my $plainLink;
1464 if (defined $file_name) {
1465 $plainLink = $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1466 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1467 } else {
1468 $plainLink = $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1470 print git_navbar($project, $hash_base, "blob", $plainLink);
1471 print "<div>" .
1472 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
1473 "</div>\n";
1474 } else {
1475 print "<div class=\"page_nav\">\n" .
1476 "<br/><br/></div>\n" .
1477 "<div class=\"title\">$hash</div>\n";
1479 if (defined $file_name) {
1480 print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n";
1482 print "<div class=\"pre\">\n";
1483 my $nr = 0;
1484 while (my $line = <$fd>) {
1485 $nr++;
1486 chomp $line;
1487 if ($syntax =~ /txt/) {
1488 $line = "<a name=\"l_$nr\" href=\"#l_$nr\" class=\"linenr\">$nr</a> $line";
1490 else {
1491 $line =~ s/<a name=\"(.+?)\">/<a name=\"$1\" href=\"#$1\" class=\"linenr\">/;
1494 if (defined $tags{$nr}) {
1495 my @tagList = @{$tags{$nr}};
1496 foreach my $tag (@tagList) {
1497 $line =~ s/$tag/<a name=\"$tag\" href=\"#$tag\">$tag<\/a>/;
1501 printf "%s\n", $line;
1503 close $fd or print "Reading blob failed.\n";
1504 print "</div>";
1505 git_footer_html();
1508 sub git_blob_plain {
1509 my $save_as = "$hash.txt";
1510 if (defined $file_name) {
1511 $save_as = $file_name;
1513 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"$save_as\"");
1514 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1515 undef $/;
1516 print <$fd>;
1517 $/ = "\n";
1518 close $fd;
1521 sub git_tree {
1522 if (!defined $hash) {
1523 $hash = git_read_head($project);
1524 if (defined $file_name) {
1525 my $base = $hash_base || $hash;
1526 $hash = git_get_hash_by_path($base, $file_name, "tree");
1528 if (!defined $hash_base) {
1529 $hash_base = $hash;
1532 $/ = "\0";
1533 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error(undef, "Open git-ls-tree failed.");
1534 chomp (my (@entries) = <$fd>);
1535 close $fd or die_error(undef, "Reading tree failed.");
1536 $/ = "\n";
1538 my $refs = read_info_ref();
1539 my $ref = "";
1540 if (defined $refs->{$hash_base}) {
1541 $ref = " <span class=\"tag\">" . esc_html($refs->{$hash_base}) . "</span>";
1543 git_header_html();
1544 my $base_key = "";
1545 my $base = "";
1546 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1547 $base_key = ";hb=$hash_base";
1548 print git_navbar($project, $hash_base, "tree", "");
1549 print "<div>\n" .
1550 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
1551 "</div>\n";
1552 } else {
1553 print "<div class=\"page_nav\">\n";
1554 print "<br/><br/></div>\n";
1555 print "<div class=\"title\">$hash</div>\n";
1557 if (defined $file_name) {
1558 $base = esc_html("$file_name/");
1559 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n";
1560 } else {
1561 print "<div class=\"page_path\"><b>/</b></div>\n";
1563 print "<div class=\"page_body\">\n";
1564 print "<table cellspacing=\"0\">\n";
1565 my $alternate = 0;
1566 foreach my $line (@entries) {
1567 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1568 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1569 my $t_mode = $1;
1570 my $t_type = $2;
1571 my $t_hash = $3;
1572 my $t_name = validate_input($4);
1573 if ($alternate) {
1574 print "<tr class=\"dark\">\n";
1575 } else {
1576 print "<tr class=\"light\">\n";
1578 $alternate ^= 1;
1579 print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n";
1580 if ($t_type eq "blob") {
1581 print "<td class=\"list\">" .
1582 $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)) .
1583 "</td>\n" .
1584 "<td class=\"link\">" .
1585 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1586 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1587 "</td>\n";
1588 } elsif ($t_type eq "tree") {
1589 print "<td class=\"list\">" .
1590 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html($t_name)) .
1591 "</td>\n" .
1592 "<td class=\"link\">" .
1593 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1594 "</td>\n";
1596 print "</tr>\n";
1598 print "</table>\n" .
1599 "</div>";
1600 git_footer_html();
1603 sub git_rss {
1604 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1605 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed.");
1606 my (@revlist) = map { chomp; $_ } <$fd>;
1607 close $fd or die_error(undef, "Reading rev-list failed.");
1608 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1609 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1610 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1611 print "<channel>\n";
1612 print "<title>$project</title>\n".
1613 "<link>" . esc_html("$my_url?p=$project;a=summary") . "</link>\n".
1614 "<description>$project log</description>\n".
1615 "<language>en</language>\n";
1617 for (my $i = 0; $i <= $#revlist; $i++) {
1618 my $commit = $revlist[$i];
1619 my %co = git_read_commit($commit);
1620 # we read 150, we always show 30 and the ones more recent than 48 hours
1621 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1622 last;
1624 my %cd = date_str($co{'committer_epoch'});
1625 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1626 my @difftree = map { chomp; $_ } <$fd>;
1627 close $fd or next;
1628 print "<item>\n" .
1629 "<title>" .
1630 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
1631 "</title>\n" .
1632 "<author>" . esc_html($co{'author'}) . "</author>\n" .
1633 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1634 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1635 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1636 "<description>" . esc_html($co{'title'}) . "</description>\n" .
1637 "<content:encoded>" .
1638 "<![CDATA[\n";
1639 my $comment = $co{'comment'};
1640 foreach my $line (@$comment) {
1641 $line = decode("utf8", $line, Encode::FB_DEFAULT);
1642 print "$line<br/>\n";
1644 print "<br/>\n";
1645 foreach my $line (@difftree) {
1646 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1647 next;
1649 my $file = validate_input(unquote($7));
1650 $file = decode("utf8", $file, Encode::FB_DEFAULT);
1651 print "$file<br/>\n";
1653 print "]]>\n" .
1654 "</content:encoded>\n" .
1655 "</item>\n";
1657 print "</channel></rss>";
1660 sub git_opml {
1661 my @list = git_read_projects();
1663 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1664 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1665 "<opml version=\"1.0\">\n".
1666 "<head>".
1667 " <title>Git OPML Export</title>\n".
1668 "</head>\n".
1669 "<body>\n".
1670 "<outline text=\"git RSS feeds\">\n";
1672 foreach my $pr (@list) {
1673 my %proj = %$pr;
1674 my $head = git_read_head($proj{'path'});
1675 if (!defined $head) {
1676 next;
1678 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1679 my %co = git_read_commit($head);
1680 if (!%co) {
1681 next;
1684 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
1685 my $rss = "$my_url?p=$proj{'path'};a=rss";
1686 my $html = "$my_url?p=$proj{'path'};a=summary";
1687 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1689 print "</outline>\n".
1690 "</body>\n".
1691 "</opml>\n";
1694 sub git_log {
1695 my $head = git_read_head($project);
1696 if (!defined $hash) {
1697 $hash = $head;
1699 if (!defined $page) {
1700 $page = 0;
1702 my $refs = read_info_ref();
1703 git_header_html();
1704 my $navExtra = "";
1705 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1706 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1707 my (@revlist) = map { chomp; $_ } <$fd>;
1708 close $fd;
1710 if ($hash ne $head || $page) {
1711 $navExtra .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "HEAD");
1712 } else {
1713 $navExtra .= "HEAD";
1715 if ($page > 0) {
1716 $navExtra .= " &sdot; " .
1717 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
1718 } else {
1719 $navExtra .= " &sdot; prev";
1721 if ($#revlist >= (100 * ($page+1)-1)) {
1722 $navExtra .= " &sdot; " .
1723 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
1724 } else {
1725 $navExtra .= " &sdot; next";
1727 print git_navbar($project, $hash, "log", $navExtra);
1728 if (!@revlist) {
1729 print "<div>\n" .
1730 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, "&nbsp;") .
1731 "</div>\n";
1732 my %co = git_read_commit($hash);
1733 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1735 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1736 my $commit = $revlist[$i];
1737 my $ref = "";
1738 if (defined $refs->{$commit}) {
1739 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
1741 my %co = git_read_commit($commit);
1742 next if !%co;
1743 my %ad = date_str($co{'author_epoch'});
1744 print "<div>\n" .
1745 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "title"},
1746 "<span class=\"age\">$co{'age_string'}</span>" . esc_html($co{'title'}) . $ref) . "\n";
1747 print "</div>\n";
1748 print "<div class=\"title_text\">\n" .
1749 "<div class=\"log_link\">\n" .
1750 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1751 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1752 " | " . $cgi->a({-href => "$snapshots_url/$project-snapshot-$commit.tar.bz2"}, "snapshot") .
1753 "<br/>\n" .
1754 "</div>\n" .
1755 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1756 "</div>\n" .
1757 "<div class=\"log_body\">\n";
1758 my $comment = $co{'comment'};
1759 my $empty = 0;
1760 foreach my $line (@$comment) {
1761 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1762 next;
1764 if ($line eq "") {
1765 if ($empty) {
1766 next;
1768 $empty = 1;
1769 } else {
1770 $empty = 0;
1772 print format_log_line_html($line) . "<br/>\n";
1774 if (!$empty) {
1775 print "<br/>\n";
1777 print "</div>\n";
1779 git_footer_html();
1782 sub git_commit {
1783 my %co = git_read_commit($hash);
1784 if (!%co) {
1785 die_error(undef, "Unknown commit object.");
1787 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1788 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1790 my @difftree;
1791 my $root = "";
1792 my $parent = $co{'parent'};
1793 if (!defined $parent) {
1794 $root = " --root";
1795 $parent = "";
1797 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed.");
1798 @difftree = map { chomp; $_ } <$fd>;
1799 close $fd or die_error(undef, "Reading diff-tree failed.");
1801 # non-textual hash id's can be cached
1802 my $expires;
1803 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1804 $expires = "+1d";
1806 my $refs = read_info_ref();
1807 my $ref = "";
1808 if (defined $refs->{$co{'id'}}) {
1809 $ref = " <span class=\"tag\">" . esc_html($refs->{$co{'id'}}) . "</span>";
1811 git_header_html(undef, $expires);
1812 # git_navbar omitted here - commitdiff link a bit weird o_O
1813 print "<div class=\"page_nav\">\n" .
1814 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1815 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1816 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
1817 " | commit";
1818 if (defined $co{'parent'}) {
1819 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1821 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1822 "<br/><br/></div>\n";
1823 if (defined $co{'parent'}) {
1824 print "<div>\n" .
1825 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
1826 "</div>\n";
1827 } else {
1828 print "<div>\n" .
1829 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1830 "</div>\n";
1832 print "<div class=\"title_text\">\n" .
1833 "<table cellspacing=\"0\">\n";
1834 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
1835 "<tr>" .
1836 "<td></td><td> $ad{'rfc2822'}";
1837 if ($ad{'hour_local'} < 6) {
1838 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1839 } else {
1840 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1842 print "</td>" .
1843 "</tr>\n";
1844 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
1845 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1846 print "<tr><td>commit</td><td style=\"font-family:monospace\">$co{'id'}</td></tr>\n";
1847 print "<tr>" .
1848 "<td>tree</td>" .
1849 "<td style=\"font-family:monospace\">" .
1850 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1851 "</td>" .
1852 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1853 "</td>" .
1854 "</tr>\n";
1855 my $parents = $co{'parents'};
1856 foreach my $par (@$parents) {
1857 print "<tr>" .
1858 "<td>parent</td>" .
1859 "<td style=\"font-family:monospace\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1860 "<td class=\"link\">" .
1861 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par")}, "commit") .
1862 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1863 "</td>" .
1864 "</tr>\n";
1866 print "<tr><td>snapshot</td>".
1867 "<td><a href=\"$snapshots_url/$project-snapshot-$hash.tar.bz2\">$hash</a></td></tr>";
1868 print "</table>".
1869 "</div>\n";
1870 print "<div class=\"page_body\">\n";
1871 my $comment = $co{'comment'};
1872 my $empty = 0;
1873 my $signed = 0;
1874 foreach my $line (@$comment) {
1875 # print only one empty line
1876 if ($line eq "") {
1877 if ($empty || $signed) {
1878 next;
1880 $empty = 1;
1881 } else {
1882 $empty = 0;
1884 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1885 $signed = 1;
1886 print "<span style=\"color: #888888\">" . esc_html($line) . "</span><br/>\n";
1887 } else {
1888 $signed = 0;
1889 print format_log_line_html($line) . "<br/>\n";
1892 print "</div>\n";
1893 print "<div class=\"list_head\">\n";
1894 if ($#difftree > 10) {
1895 print(($#difftree + 1) . " files changed:\n");
1897 print "</div>\n";
1898 print "<table cellspacing=\"0\">\n";
1899 my $alternate = 0;
1900 foreach my $line (@difftree) {
1901 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1902 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1903 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1904 next;
1906 my $from_mode = $1;
1907 my $to_mode = $2;
1908 my $from_id = $3;
1909 my $to_id = $4;
1910 my $status = $5;
1911 my $similarity = $6;
1912 my $file = validate_input(unquote($7));
1913 if ($alternate) {
1914 print "<tr class=\"dark\">\n";
1915 } else {
1916 print "<tr class=\"light\">\n";
1918 $alternate ^= 1;
1919 if ($status eq "A") {
1920 my $mode_chng = "";
1921 if (S_ISREG(oct $to_mode)) {
1922 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1924 print "<td>" .
1925 $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" .
1926 "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1927 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
1928 } elsif ($status eq "D") {
1929 print "<td>" .
1930 $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" .
1931 "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1932 "<td class=\"link\">" .
1933 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
1934 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") .
1935 "</td>\n"
1936 } elsif ($status eq "M" || $status eq "T") {
1937 my $mode_chnge = "";
1938 if ($from_mode != $to_mode) {
1939 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1940 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1941 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1943 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1944 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1945 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1946 } elsif (S_ISREG($to_mode)) {
1947 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1950 $mode_chnge .= "]</span>\n";
1952 print "<td>";
1953 if ($to_id ne $from_id) {
1954 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));
1955 } else {
1956 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
1958 print "</td>\n" .
1959 "<td>$mode_chnge</td>\n" .
1960 "<td class=\"link\">";
1961 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
1962 if ($to_id ne $from_id) {
1963 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
1965 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
1966 print "</td>\n";
1967 } elsif ($status eq "R") {
1968 my ($from_file, $to_file) = split "\t", $file;
1969 my $mode_chng = "";
1970 if ($from_mode != $to_mode) {
1971 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1973 print "<td>" .
1974 $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" .
1975 "<td><span style=\"color: #777777;\">[moved from " .
1976 $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)) .
1977 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1978 "<td class=\"link\">" .
1979 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
1980 if ($to_id ne $from_id) {
1981 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
1983 print "</td>\n";
1985 print "</tr>\n";
1987 print "</table>\n";
1988 git_footer_html();
1991 sub git_blobdiff {
1992 mkdir($git_temp, 0700);
1993 git_header_html();
1994 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1995 print git_navbar($project, $hash_base, "blobdiff", $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain"));
1996 print "<div>\n" .
1997 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1998 "</div>\n";
1999 } else {
2000 print "<div class=\"page_nav\">\n" .
2001 "<br/><br/></div>\n" .
2002 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2004 if (defined $file_name) {
2005 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n";
2007 print "<div class=\"page_body\">\n" .
2008 "<div class=\"diff_info\">blob:" .
2009 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2010 " -> blob:" .
2011 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2012 "</div>\n";
2013 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2014 print "</div>";
2015 git_footer_html();
2018 sub git_blobdiff_plain {
2019 mkdir($git_temp, 0700);
2020 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
2021 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2024 sub git_commitdiff {
2025 mkdir($git_temp, 0700);
2026 my %co = git_read_commit($hash);
2027 if (!%co) {
2028 die_error(undef, "Unknown commit object.");
2030 if (!defined $hash_parent) {
2031 $hash_parent = $co{'parent'};
2033 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
2034 my (@difftree) = map { chomp; $_ } <$fd>;
2035 close $fd or die_error(undef, "Reading diff-tree failed.");
2037 # non-textual hash id's can be cached
2038 my $expires;
2039 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2040 $expires = "+1d";
2042 my $refs = read_info_ref();
2043 my $ref = "";
2044 if (defined $refs->{$co{'id'}}) {
2045 $ref = " <span class=\"tag\">" . esc_html($refs->{$co{'id'}}) . "</span>";
2047 git_header_html(undef, $expires);
2048 print git_navbar($project, $hash, "commitdiff", $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain"));
2049 print "<div class=\"title\">\n" .
2050 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, committags_real(esc_html($co{'title'}), "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), "title_cdiff") . $ref) . "\n" .
2051 "</div>\n";
2052 print "<div class=\"page_body\">\n";
2053 my $comment = $co{'comment'};
2054 my $empty = 0;
2055 my $signed = 0;
2056 my @log = @$comment;
2057 # remove first and empty lines after that
2058 shift @log;
2059 while (defined $log[0] && $log[0] eq "") {
2060 shift @log;
2062 foreach my $line (@log) {
2063 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2064 next;
2066 if ($line eq "") {
2067 if ($empty) {
2068 next;
2070 $empty = 1;
2071 } else {
2072 $empty = 0;
2074 print format_log_line_html($line) . "<br/>\n";
2076 print "<br/>\n";
2077 foreach my $line (@difftree) {
2078 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2079 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2080 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2081 my $from_mode = $1;
2082 my $to_mode = $2;
2083 my $from_id = $3;
2084 my $to_id = $4;
2085 my $status = $5;
2086 my $file = validate_input(unquote($6));
2087 if ($status eq "A") {
2088 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
2089 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2090 "</div>\n";
2091 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
2092 } elsif ($status eq "D") {
2093 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
2094 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2095 "</div>\n";
2096 git_diff_print($from_id, "a/$file", undef, "/dev/null");
2097 } elsif ($status eq "M") {
2098 if ($from_id ne $to_id) {
2099 print "<div class=\"diff_info\">" .
2100 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2101 " -> " .
2102 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2103 print "</div>\n";
2104 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
2108 print "<br/>\n" .
2109 "</div>";
2110 git_footer_html();
2113 sub git_commitdiff_plain {
2114 mkdir($git_temp, 0700);
2115 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
2116 my (@difftree) = map { chomp; $_ } <$fd>;
2117 close $fd or die_error(undef, "Reading diff-tree failed.");
2119 # try to figure out the next tag after this commit
2120 my $tagname;
2121 my $refs = read_info_ref("tags");
2122 open $fd, "-|", "$gitbin/git-rev-list HEAD";
2123 chomp (my (@commits) = <$fd>);
2124 close $fd;
2125 foreach my $commit (@commits) {
2126 if (defined $refs->{$commit}) {
2127 $tagname = $refs->{$commit}
2129 if ($commit eq $hash) {
2130 last;
2134 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2135 my %co = git_read_commit($hash);
2136 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
2137 my $comment = $co{'comment'};
2138 print "From: $co{'author'}\n" .
2139 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2140 "Subject: $co{'title'}\n";
2141 if (defined $tagname) {
2142 print "X-Git-Tag: $tagname\n";
2144 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2145 "\n";
2147 foreach my $line (@$comment) {;
2148 print "$line\n";
2150 print "---\n\n";
2152 foreach my $line (@difftree) {
2153 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2154 my $from_id = $3;
2155 my $to_id = $4;
2156 my $status = $5;
2157 my $file = $6;
2158 if ($status eq "A") {
2159 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
2160 } elsif ($status eq "D") {
2161 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
2162 } elsif ($status eq "M") {
2163 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
2168 sub git_history {
2169 if (!defined $hash) {
2170 $hash = git_read_head($project);
2172 my %co = git_read_commit($hash);
2173 if (!%co) {
2174 die_error(undef, "Unknown commit object.");
2176 my $refs = read_info_ref();
2177 git_header_html();
2178 print git_navbar($project, $hash, "history", "");
2179 print "<div>\n" .
2180 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, committags(esc_html($co{'title'}))) . "\n" .
2181 "</div>\n";
2182 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b><br/></div>\n";
2184 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin \'$file_name\'";
2185 my $commit;
2186 print "<table cellspacing=\"0\">\n";
2187 my $alternate = 0;
2188 while (my $line = <$fd>) {
2189 if ($line =~ m/^([0-9a-fA-F]{40})/){
2190 $commit = $1;
2191 next;
2193 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2194 my %co = git_read_commit($commit);
2195 if (!%co) {
2196 next;
2198 my $ref = "";
2199 if (defined $refs->{$commit}) {
2200 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
2202 if ($alternate) {
2203 print "<tr class=\"dark\">\n";
2204 } else {
2205 print "<tr class=\"light\">\n";
2207 $alternate ^= 1;
2208 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2209 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2210 "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2211 committags(esc_html(chop_str($co{'title'}, 50))) . "$ref</b>") . "</td>\n" .
2212 "<td class=\"link\">" .
2213 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2214 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2215 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2216 my $blob = git_get_hash_by_path($hash, $file_name);
2217 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2218 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2219 print " | " .
2220 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2221 "diff to current");
2223 print "</td>\n" .
2224 "</tr>\n";
2225 undef $commit;
2228 print "</table>\n";
2229 close $fd;
2230 git_footer_html();
2233 sub git_search {
2234 if (!defined $searchtext) {
2235 die_error("", "Text field empty.");
2237 if (!defined $hash) {
2238 $hash = git_read_head($project);
2240 my %co = git_read_commit($hash);
2241 if (!%co) {
2242 die_error(undef, "Unknown commit object.");
2244 # pickaxe may take all resources of your box and run for several minutes
2245 # with every query - so decide by yourself how public you make this feature :)
2246 my $commit_search = 1;
2247 my $author_search = 0;
2248 my $committer_search = 0;
2249 my $pickaxe_search = 0;
2250 if ($searchtext =~ s/^author\\://i) {
2251 $author_search = 1;
2252 } elsif ($searchtext =~ s/^committer\\://i) {
2253 $committer_search = 1;
2254 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2255 $commit_search = 0;
2256 $pickaxe_search = 1;
2258 git_header_html();
2259 print git_navbar($project, $hash, "search", "");
2261 print "<div>\n" .
2262 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2263 "</div>\n";
2264 print "<table cellspacing=\"0\">\n";
2265 my $alternate = 0;
2266 if ($commit_search) {
2267 $/ = "\0";
2268 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2269 while (my $commit_text = <$fd>) {
2270 if (!grep m/$searchtext/i, $commit_text) {
2271 next;
2273 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2274 next;
2276 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2277 next;
2279 my @commit_lines = split "\n", $commit_text;
2280 my %co = git_read_commit(undef, \@commit_lines);
2281 if (!%co) {
2282 next;
2284 if ($alternate) {
2285 print "<tr class=\"dark\">\n";
2286 } else {
2287 print "<tr class=\"light\">\n";
2289 $alternate ^= 1;
2290 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2291 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2292 "<td>" .
2293 $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/>");
2294 my $comment = $co{'comment'};
2295 foreach my $line (@$comment) {
2296 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2297 my $lead = esc_html($1) || "";
2298 $lead = chop_str($lead, 30, 10);
2299 my $match = esc_html($2) || "";
2300 my $trail = esc_html($3) || "";
2301 $trail = chop_str($trail, 30, 10);
2302 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
2303 print chop_str($text, 80, 5) . "<br/>\n";
2306 print "</td>\n" .
2307 "<td class=\"link\">" .
2308 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2309 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2310 print "</td>\n" .
2311 "</tr>\n";
2313 close $fd;
2316 if ($pickaxe_search) {
2317 $/ = "\n";
2318 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2319 undef %co;
2320 my @files;
2321 while (my $line = <$fd>) {
2322 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2323 my %set;
2324 $set{'file'} = $6;
2325 $set{'from_id'} = $3;
2326 $set{'to_id'} = $4;
2327 $set{'id'} = $set{'to_id'};
2328 if ($set{'id'} =~ m/0{40}/) {
2329 $set{'id'} = $set{'from_id'};
2331 if ($set{'id'} =~ m/0{40}/) {
2332 next;
2334 push @files, \%set;
2335 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2336 if (%co) {
2337 if ($alternate) {
2338 print "<tr class=\"dark\">\n";
2339 } else {
2340 print "<tr class=\"light\">\n";
2342 $alternate ^= 1;
2343 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2344 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2345 "<td>" .
2346 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2347 esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2348 while (my $setref = shift @files) {
2349 my %set = %$setref;
2350 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2351 "<span style=\"color:#e00000\">" . esc_html($set{'file'}) . "</span>") .
2352 "<br/>\n";
2354 print "</td>\n" .
2355 "<td class=\"link\">" .
2356 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2357 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2358 print "</td>\n" .
2359 "</tr>\n";
2361 %co = git_read_commit($1);
2364 close $fd;
2366 print "</table>\n";
2367 git_footer_html();
2370 sub git_shortlog {
2371 my $head = git_read_head($project);
2372 if (!defined $hash) {
2373 $hash = $head;
2375 if (!defined $page) {
2376 $page = 0;
2378 my $refs = read_info_ref();
2379 git_header_html();
2381 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2382 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
2383 my (@revlist) = map { chomp; $_ } <$fd>;
2384 close $fd;
2386 my $navExtra = "";
2387 if ($hash ne $head || $page) {
2388 $navExtra .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "HEAD");
2389 } else {
2390 $navExtra .= "HEAD";
2392 if ($page > 0) {
2393 $navExtra .= " &sdot; " .
2394 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
2395 } else {
2396 $navExtra .= " &sdot; prev";
2398 if ($#revlist >= (100 * ($page+1)-1)) {
2399 $navExtra .= " &sdot; " .
2400 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
2401 } else {
2402 $navExtra .= " &sdot; next";
2404 print git_navbar($project, $hash, "shortlog", $navExtra);
2405 print "<div>\n" .
2406 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, "&nbsp;") .
2407 "</div>\n";
2408 print "<table cellspacing=\"0\">\n";
2409 my $alternate = 0;
2410 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2411 my $commit = $revlist[$i];
2412 my $ref = "";
2413 if (defined $refs->{$commit}) {
2414 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
2416 my %co = git_read_commit($commit);
2417 my %ad = date_str($co{'author_epoch'});
2418 if ($alternate) {
2419 print "<tr class=\"dark\">\n";
2420 } else {
2421 print "<tr class=\"light\">\n";
2423 $alternate ^= 1;
2424 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2425 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2426 "<td>";
2427 if (length($co{'title_short'}) < length($co{'title'})) {
2428 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
2429 "<b>" . committags_shortlog(esc_html($co{'title_short'}), ("$my_uri?" . esc_param("p=$project;a=commit;h=$commit"))) . "$ref</b>");
2430 } else {
2431 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
2432 "<b>" . committags_shortlog(esc_html($co{'title_short'}), ("$my_uri?" . esc_param("p=$project;a=commit;h=$commit"))) . "$ref</b>");
2434 print "</td>\n" .
2435 "<td class=\"link\">" .
2436 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2437 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2438 " | " . $cgi->a({-href => "$snapshots_url/$project-snapshot-$commit.tar.bz2"}, "snapshot") .
2439 "</td>\n" .
2440 "</tr>";
2442 if ($#revlist >= (100 * ($page+1)-1)) {
2443 print "<tr>\n" .
2444 "<td>" .
2445 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title => "Alt-n"}, "next") .
2446 "</td>\n" .
2447 "</tr>\n";
2449 print "</table\n>";
2450 git_footer_html();