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
12 use CGI qw(:standard :escapeHTML -nosticky);
13 use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
20 my $my_url = $cgi->url();
21 my $my_uri = $cgi->url(-absolute => 1);
24 # absolute fs-path which will be prepended to the project path
25 #my $projectroot = "/pub/scm";
26 my $projectroot = "/home/kay/public_html/pub/scm";
28 # location of the git-core binaries
29 my $gitbin = "/usr/bin";
31 # location for temporary files needed for diffs
32 my $git_temp = "/tmp/gitweb";
34 # target of the home link on top of all pages
35 my $home_link = $my_uri;
37 # html text to include at home page
38 my $home_text = "indextext.html";
40 # source of projects list
41 #my $projects_list = $projectroot;
42 my $projects_list = "index/index.aux";
44 # input validation and dispatch
45 my $action = $cgi->param('a');
46 if (defined $action) {
47 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
49 die_error(undef, "Invalid action parameter.");
51 if ($action eq "git-logo.png") {
54 } elsif ($action eq "opml") {
60 my $order = $cgi->param('o');
62 if ($order =~ m/[^0-9a-zA-Z_]/) {
64 die_error(undef, "Invalid order parameter.");
68 my $project = $cgi->param('p');
69 if (defined $project) {
70 $project = validate_input($project);
71 if (!defined($project)) {
72 die_error(undef, "Invalid project parameter.");
74 if (!(-d "$projectroot/$project")) {
76 die_error(undef, "No such directory.");
78 if (!(-e "$projectroot/$project/HEAD")) {
80 die_error(undef, "No such project.");
82 $rss_link = "<link rel=\"alternate\" title=\"" . esc_url($project) . " log\" href=\"" .
83 esc_url("$my_uri?p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
84 $ENV{'GIT_DIR'} = "$projectroot/$project";
90 my $file_name = $cgi->param('f');
91 if (defined $file_name) {
92 $file_name = validate_input($file_name);
93 if (!defined($file_name)) {
94 die_error(undef, "Invalid file parameter.");
98 my $hash = $cgi->param('h');
100 $hash = validate_input($hash);
101 if (!defined($hash)) {
102 die_error(undef, "Invalid hash parameter.");
106 my $hash_parent = $cgi->param('hp');
107 if (defined $hash_parent) {
108 $hash_parent = validate_input($hash_parent);
109 if (!defined($hash_parent)) {
110 die_error(undef, "Invalid hash parent parameter.");
114 my $hash_base = $cgi->param('hb');
115 if (defined $hash_base) {
116 $hash_base = validate_input($hash_base);
117 if (!defined($hash_base)) {
118 die_error(undef, "Invalid hash base parameter.");
122 my $page = $cgi->param('pg');
124 if ($page =~ m/[^0-9]$/) {
126 die_error(undef, "Invalid page parameter.");
130 my $searchtext = $cgi->param('s');
131 if (defined $searchtext) {
132 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
134 die_error(undef, "Invalid search parameter.");
136 $searchtext = quotemeta $searchtext;
142 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
145 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
148 if ($input =~ m/[^a-zA-Z0-9_ \.\/\-\+\#\~]/) {
154 if (!defined $action || $action eq "summary") {
157 } elsif ($action eq "heads") {
160 } elsif ($action eq "tags") {
163 } elsif ($action eq "blob") {
166 } elsif ($action eq "blob_plain") {
169 } elsif ($action eq "tree") {
172 } elsif ($action eq "rss") {
175 } elsif ($action eq "commit") {
178 } elsif ($action eq "log") {
181 } elsif ($action eq "blobdiff") {
184 } elsif ($action eq "blobdiff_plain") {
185 git_blobdiff_plain();
187 } elsif ($action eq "commitdiff") {
190 } elsif ($action eq "commitdiff_plain") {
191 git_commitdiff_plain();
193 } elsif ($action eq "history") {
196 } elsif ($action eq "search") {
199 } elsif ($action eq "shortlog") {
202 } elsif ($action eq "tag") {
207 die_error(undef, "Unknown action.");
220 $str = escapeHTML($str);
221 $str = decode("utf8", $str, Encode::FB_DEFAULT);
225 sub git_header_html {
226 my $status = shift || "200 OK";
230 if (defined $project) {
231 $title .= " - $project";
232 if (defined $action) {
233 $title .= "/$action";
236 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires);
238 <?xml version="1.0" encoding="utf-8"?>
239 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
240 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
241 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
243 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
244 <meta name="robots" content="index, nofollow"/>
245 <title>$title</title>
247 <style type="text/css">
248 body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
250 a:hover, a:visited, a:active { color:#880000; }
251 div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; }
252 div.page_header a:visited, a.header { color:#0000cc; }
253 div.page_header a:hover { color:#880000; }
254 div.page_nav { padding:8px; }
255 div.page_nav a:visited { color:#0000cc; }
256 div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
257 div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
258 div.page_footer_text { float:left; color:#555555; font-style:italic; }
259 div.page_body { padding:8px; }
261 display:block; padding:6px 8px;
262 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
264 a.title:hover { background-color: #d9d8d1; }
265 div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; }
266 div.log_body { padding:8px 8px 8px 150px; }
267 span.age { position:relative; float:left; width:142px; font-style:italic; }
270 font-size:10px; font-family:sans-serif; font-style:normal;
271 position:relative; float:left; width:136px;
273 div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; }
274 a.list { text-decoration:none; color:#000000; }
275 a.list:hover { text-decoration:underline; color:#880000; }
276 a.text { text-decoration:none; color:#0000cc; }
277 a.text:visited { text-decoration:none; color:#880000; }
278 a.text:hover { text-decoration:underline; color:#880000; }
279 table { padding:8px 4px; }
280 th { padding:2px 5px; font-size:12px; text-align:left; }
281 tr.light:hover { background-color:#edece6; }
282 tr.dark { background-color:#f6f6f0; }
283 tr.dark:hover { background-color:#edece6; }
284 td { padding:2px 5px; font-size:12px; vertical-align:top; }
285 td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; }
286 div.pre { font-family:monospace; font-size:12px; white-space:pre; }
287 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
288 div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
289 div.search { margin:4px 8px; position:absolute; top:56px; right:12px }
290 a.linenr { color:#999999; text-decoration:none }
292 float:right; padding:3px 0px; width:35px; line-height:10px;
293 border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
294 color:#ffffff; background-color:#ff6600;
295 font-weight:bold; font-family:sans-serif; font-size:10px;
296 text-align:center; text-decoration:none;
298 a.rss_logo:hover { background-color:#ee5500; }
303 print "<div class=\"page_header\">\n" .
304 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
305 "<img src=\"" . esc_url("$my_uri?a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
307 print $cgi->a({-href => esc_url($home_link)}, "projects") . " / ";
308 if (defined $project) {
309 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, esc_html($project));
310 if (defined $action) {
314 if (!defined $searchtext) {
319 $search_hash = $hash;
321 $search_hash = "HEAD";
323 $cgi->param("a", "search");
324 $cgi->param("h", $search_hash);
325 print $cgi->startform(-method => "get", -action => $my_uri) .
326 "<div class=\"search\">\n" .
327 $cgi->hidden(-name => "p") . "\n" .
328 $cgi->hidden(-name => "a") . "\n" .
329 $cgi->hidden(-name => "h") . "\n" .
330 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
332 $cgi->end_form() . "\n";
337 sub git_footer_html {
338 print "<div class=\"page_footer\">\n";
339 if (defined $project) {
340 my $descr = git_read_description($project);
341 if (defined $descr) {
342 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
344 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
346 print $cgi->a({-href => esc_url("$my_uri?a=opml"), -class => "rss_logo"}, "OPML") . "\n";
354 my $status = shift || "403 Forbidden";
355 my $error = shift || "Malformed query, file missing or permission denied";
357 git_header_html($status);
358 print "<div class=\"page_body\">\n" .
360 "$status - $error\n" .
370 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
380 open my $fd, "$projectroot/$path" or return undef;
384 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
389 sub git_read_description {
392 open my $fd, "$projectroot/$path/description" or return undef;
404 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
405 $tag{'id'} = $tag_id;
406 while (my $line = <$fd>) {
408 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
410 } elsif ($line =~ m/^type (.+)$/) {
412 } elsif ($line =~ m/^tag (.+)$/) {
414 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
418 } elsif ($line =~ m/--BEGIN/) {
419 push @comment, $line;
421 } elsif ($line eq "") {
425 push @comment, <$fd>;
426 $tag{'comment'} = \@comment;
428 if (!defined $tag{'name'}) {
438 if ($age > 60*60*24*365*2) {
439 $age_str = (int $age/60/60/24/365);
440 $age_str .= " years ago";
441 } elsif ($age > 60*60*24*(365/12)*2) {
442 $age_str = int $age/60/60/24/(365/12);
443 $age_str .= " months ago";
444 } elsif ($age > 60*60*24*7*2) {
445 $age_str = int $age/60/60/24/7;
446 $age_str .= " weeks ago";
447 } elsif ($age > 60*60*24*2) {
448 $age_str = int $age/60/60/24;
449 $age_str .= " days ago";
450 } elsif ($age > 60*60*2) {
451 $age_str = int $age/60/60;
452 $age_str .= " hours ago";
453 } elsif ($age > 60*2) {
454 $age_str = int $age/60;
455 $age_str .= " min ago";
458 $age_str .= " sec ago";
460 $age_str .= " right now";
465 sub git_read_commit {
466 my $commit_id = shift;
467 my $commit_text = shift;
472 if (defined $commit_text) {
473 @commit_lines = @$commit_text;
476 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
477 @commit_lines = split '\n', <$fd>;
482 my $header = shift @commit_lines;
483 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
486 ($co{'id'}, my @parents) = split ' ', $header;
487 $co{'parents'} = \@parents;
488 $co{'parent'} = $parents[0];
489 while (my $line = shift @commit_lines) {
490 last if $line eq "\n";
491 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
493 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
495 $co{'author_epoch'} = $2;
496 $co{'author_tz'} = $3;
497 if ($co{'author'} =~ m/^([^<]+) </) {
498 $co{'author_name'} = $1;
500 $co{'author_name'} = $co{'author'};
502 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
503 $co{'committer'} = $1;
504 $co{'committer_epoch'} = $2;
505 $co{'committer_tz'} = $3;
506 $co{'committer_name'} = $co{'committer'};
507 $co{'committer_name'} =~ s/ <.*//;
510 if (!defined $co{'tree'}) {
514 foreach my $title (@commit_lines) {
516 $co{'title'} = chop_str($title, 80, 5);
517 # remove leading stuff of merges to make the interesting part visible
518 if (length($title) > 50) {
519 $title =~ s/^Automatic //;
520 $title =~ s/^merge (of|with) /Merge ... /i;
521 if (length($title) > 50) {
522 $title =~ s/(http|rsync):\/\///;
524 if (length($title) > 50) {
525 $title =~ s/(master|www|rsync)\.//;
527 if (length($title) > 50) {
528 $title =~ s/kernel.org:?//;
530 if (length($title) > 50) {
531 $title =~ s/\/pub\/scm//;
534 $co{'title_short'} = chop_str($title, 50, 5);
538 # remove added spaces
539 foreach my $line (@commit_lines) {
542 $co{'comment'} = \@commit_lines;
544 my $age = time - $co{'committer_epoch'};
546 $co{'age_string'} = age_string($age);
547 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
548 if ($age > 60*60*24*7*2) {
549 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
550 $co{'age_string_age'} = $co{'age_string'};
552 $co{'age_string_date'} = $co{'age_string'};
553 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
560 my $from_name = shift;
563 my $format = shift || "html";
565 my $from_tmp = "/dev/null";
566 my $to_tmp = "/dev/null";
569 # create tmp from-file
571 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
572 open my $fd2, "> $from_tmp";
573 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
582 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
583 open my $fd2, "> $to_tmp";
584 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
591 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
592 if ($format eq "plain") {
597 while (my $line = <$fd>) {
599 my $char = substr($line, 0, 1);
602 $color = " style=\"color:#008800;\"";
603 } elsif ($char eq "-") {
604 $color = " style=\"color:#cc0000;\"";
605 } elsif ($char eq "@") {
606 $color = " style=\"color:#990099;\"";
607 } elsif ($char eq "\\") {
611 while ((my $pos = index($line, "\t")) != -1) {
612 if (my $count = (8 - (($pos-1) % 8))) {
613 my $spaces = ' ' x $count;
614 $line =~ s/\t/$spaces/;
617 print "<div class=\"pre\"$color>" . esc_html($line) . "</div>\n";
631 my $mode = oct shift;
633 if (S_ISDIR($mode & S_IFMT)) {
635 } elsif (S_ISLNK($mode)) {
637 } elsif (S_ISREG($mode)) {
638 # git cares only about the executable bit
639 if ($mode & S_IXUSR) {
652 my $add_len = shift || 10;
654 # allow only $len chars, but don't cut a word if it would fit in $add_len
655 # if it doesn't fit, cut it if it's still longer than the dots we would add
656 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
659 if (length($tail) > 4) {
666 my $mode = oct shift;
668 if (S_ISDIR($mode & S_IFMT)) {
670 } elsif (S_ISLNK($mode)) {
672 } elsif (S_ISREG($mode)) {
679 sub format_log_line_html {
682 $line = esc_html($line);
683 $line =~ s/ / /g;
684 if ($line =~ m/([0-9a-fA-F]{40})/) {
686 if (git_get_type($hash_text) eq "commit") {
687 my $link = $cgi->a({-class => "text", -href => esc_url("$my_uri?p=$project;a=commit;h=$hash_text")}, $hash_text);
688 $line =~ s/$hash_text/$link/;
696 my $tz = shift || "-0000";
699 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
700 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
701 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
702 $date{'hour'} = $hour;
703 $date{'minute'} = $min;
704 $date{'mday'} = $mday;
705 $date{'day'} = $days[$wday];
706 $date{'month'} = $months[$mon];
707 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
708 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
710 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
711 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
712 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
713 $date{'hour_local'} = $hour;
714 $date{'minute_local'} = $min;
715 $date{'tz_local'} = $tz;
719 # git-logo (cached in browser for one day)
721 print $cgi->header(-type => 'image/png', -expires => '+1d');
722 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
723 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
724 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
725 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
726 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
727 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
728 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
729 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
730 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
731 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
732 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
733 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
734 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
735 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
741 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
742 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
743 if (!defined $gcos) {
747 $owner =~ s/[,;].*$//;
751 sub git_read_projects {
754 if (-d $projects_list) {
755 # search in directory
756 my $dir = $projects_list;
757 opendir my $dh, $dir or return undef;
758 while (my $dir = readdir($dh)) {
759 if (-e "$projectroot/$dir/HEAD") {
767 } elsif (-f $projects_list) {
768 # read from file(url-encoded):
769 # 'git%2Fgit.git Linus+Torvalds'
770 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
771 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
772 open my $fd , $projects_list or return undef;
773 while (my $line = <$fd>) {
775 my ($path, $owner) = split ' ', $line;
776 $path = unescape($path);
777 $owner = unescape($owner);
778 if (!defined $path) {
781 if (-e "$projectroot/$path/HEAD") {
791 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
795 sub git_project_list {
796 my @list = git_read_projects();
799 die_error(undef, "No project found.");
801 foreach my $pr (@list) {
802 my $head = git_read_hash("$pr->{'path'}/HEAD");
803 if (!defined $head) {
806 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
807 my %co = git_read_commit($head);
811 $pr->{'commit'} = \%co;
812 if (!defined $pr->{'descr'}) {
813 my $descr = git_read_description($pr->{'path'}) || "";
814 $pr->{'descr'} = chop_str($descr, 25, 5);
816 if (!defined $pr->{'owner'}) {
817 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
823 print "<div class=\"index_include\">\n";
824 open (my $fd, $home_text);
829 print "<table cellspacing=\"0\">\n" .
831 if (!defined($order) || (defined($order) && ($order eq "project"))) {
832 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
833 print "<th>Project</th>\n";
835 print "<th>" . $cgi->a({-class => "header", -href => esc_url("$my_uri?o=project")}, "Project") . "</th>\n";
837 if (defined($order) && ($order eq "descr")) {
838 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
839 print "<th>Description</th>\n";
841 print "<th>" . $cgi->a({-class => "header", -href => esc_url("$my_uri?o=descr")}, "Description") . "</th>\n";
843 if (defined($order) && ($order eq "owner")) {
844 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
845 print "<th>Owner</th>\n";
847 print "<th>" . $cgi->a({-class => "header", -href => esc_url("$my_uri?o=owner")}, "Owner") . "</th>\n";
849 if (defined($order) && ($order eq "age")) {
850 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
851 print "<th>Last Change</th>\n";
853 print "<th>" . $cgi->a({-class => "header", -href => esc_url("$my_uri?o=age")}, "Last Change") . "</th>\n";
855 print "<th></th>\n" .
858 foreach my $pr (@projects) {
860 print "<tr class=\"dark\">\n";
862 print "<tr class=\"light\">\n";
865 print "<td>" . $cgi->a({-href => esc_url("$my_uri?p=$pr->{'path'};a=summary"), -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
866 "<td>$pr->{'descr'}</td>\n" .
867 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
869 if ($pr->{'commit'}{'age'} < 60*60*2) {
870 $colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>";
871 } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {
872 $colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>";
874 $colored_age = "<i>$pr->{'commit'}{'age_string'}</i>";
876 print "<td>$colored_age</td>\n" .
877 "<td class=\"link\">" .
878 $cgi->a({-href => esc_url("$my_uri?p=$pr->{'path'};a=summary")}, "summary") .
879 " | " . $cgi->a({-href => esc_url("$my_uri?p=$pr->{'path'};a=shortlog")}, "shortlog") .
880 " | " . $cgi->a({-href => esc_url("$my_uri?p=$pr->{'path'};a=log")}, "log") .
893 opendir my $dh, "$projectroot/$project/$ref_dir";
894 while (my $dir = readdir($dh)) {
895 if ($dir =~ m/^\./) {
898 if (-d "$projectroot/$project/$ref_dir/$dir") {
899 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
900 my @subdirs = grep !m/^\./, readdir $dh2;
902 foreach my $subdir (@subdirs) {
903 push @refs, "$dir/$subdir"
910 foreach my $ref_file (@refs) {
911 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
912 my $type = git_get_type($ref_id) || next;
915 $ref_item{'type'} = $type;
916 $ref_item{'id'} = $ref_id;
917 $ref_item{'epoch'} = 0;
918 $ref_item{'age'} = "unknown";
919 if ($type eq "tag") {
920 my %tag = git_read_tag($ref_id);
921 $ref_item{'comment'} = $tag{'comment'};
922 if ($tag{'type'} eq "commit") {
923 %co = git_read_commit($tag{'object'});
924 $ref_item{'epoch'} = $co{'committer_epoch'};
925 $ref_item{'age'} = $co{'age_string'};
926 } elsif (defined($tag{'epoch'})) {
927 my $age = time - $tag{'epoch'};
928 $ref_item{'epoch'} = $tag{'epoch'};
929 $ref_item{'age'} = age_string($age);
931 $ref_item{'reftype'} = $tag{'type'};
932 $ref_item{'name'} = $tag{'name'};
933 $ref_item{'refid'} = $tag{'object'};
934 } elsif ($type eq "commit"){
935 %co = git_read_commit($ref_id);
936 $ref_item{'reftype'} = "commit";
937 $ref_item{'name'} = $ref_file;
938 $ref_item{'title'} = $co{'title'};
939 $ref_item{'refid'} = $ref_id;
940 $ref_item{'epoch'} = $co{'committer_epoch'};
941 $ref_item{'age'} = $co{'age_string'};
944 push @reflist, \%ref_item;
947 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
952 my $descr = git_read_description($project) || "none";
953 my $head = git_read_hash("$project/HEAD");
954 my %co = git_read_commit($head);
955 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
958 if (-f $projects_list) {
959 open (my $fd , $projects_list);
960 while (my $line = <$fd>) {
962 my ($pr, $ow) = split ' ', $line;
965 if ($pr eq $project) {
972 if (!defined $owner) {
973 $owner = get_file_owner("$projectroot/$project");
977 print "<div class=\"page_nav\">\n" .
979 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
980 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
981 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$head")}, "commit") .
982 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$head")}, "commitdiff") .
983 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree")}, "tree") .
986 print "<div class=\"title\"> </div>\n";
987 print "<table cellspacing=\"0\">\n" .
988 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
989 "<tr><td>owner</td><td>$owner</td></tr>\n" .
990 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
992 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
993 my (@revlist) = map { chomp; $_ } <$fd>;
996 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog"), -class => "title"}, "shortlog") .
999 print "<table cellspacing=\"0\">\n";
1001 foreach my $commit (@revlist) {
1002 my %co = git_read_commit($commit);
1003 my %ad = date_str($co{'author_epoch'});
1005 print "<tr class=\"dark\">\n";
1007 print "<tr class=\"light\">\n";
1011 print "<td><i>$co{'age_string'}</i></td>\n" .
1012 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1014 if (length($co{'title_short'}) < length($co{'title'})) {
1015 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
1016 "<b>" . esc_html($co{'title_short'}) . "</b>");
1018 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit"), -class => "list"},
1019 "<b>" . esc_html($co{'title'}) . "</b>");
1022 "<td class=\"link\">" .
1023 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit")}, "commit") .
1024 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1028 print "<td>" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "...") . "</td>\n" .
1035 my $taglist = git_read_refs("refs/tags");
1036 if (defined @$taglist) {
1038 $cgi->a({-href => esc_url("$my_uri?p=$project;a=tags"), -class => "title"}, "tags") .
1041 print "<table cellspacing=\"0\">\n";
1043 foreach my $entry (@$taglist) {
1045 my $comment_lines = $tag{'comment'};
1046 my $comment = shift @$comment_lines;
1047 if (defined($comment)) {
1048 $comment = chop_str($comment, 30, 5);
1051 print "<tr class=\"dark\">\n";
1053 print "<tr class=\"light\">\n";
1057 print "<td><i>$tag{'age'}</i></td>\n" .
1059 $cgi->a({-href => esc_url("$my_uri?p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1060 "<b>" . esc_html($tag{'name'}) . "</b>") .
1063 if (defined($comment)) {
1064 print $cgi->a({-class => "list", -href => esc_url("$my_uri?p=$project;a=tag;h=$tag{'id'}")}, $comment);
1067 "<td class=\"link\">";
1068 if ($tag{'type'} eq "tag") {
1069 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1071 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1072 if ($tag{'reftype'} eq "commit") {
1073 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1074 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$tag{'refid'}")}, "log");
1079 print "<td>" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tags")}, "...") . "</td>\n" .
1087 my $headlist = git_read_refs("refs/heads");
1088 if (defined @$headlist) {
1090 $cgi->a({-href => esc_url("$my_uri?p=$project;a=heads"), -class => "title"}, "heads") .
1093 print "<table cellspacing=\"0\">\n";
1095 foreach my $entry (@$headlist) {
1098 print "<tr class=\"dark\">\n";
1100 print "<tr class=\"light\">\n";
1104 print "<td><i>$tag{'age'}</i></td>\n" .
1106 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1107 "<b>" . esc_html($tag{'name'}) . "</b>") .
1109 "<td class=\"link\">" .
1110 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1111 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$tag{'name'}")}, "log") .
1115 print "<td>" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=heads")}, "...") . "</td>\n" .
1126 my $head = git_read_hash("$project/HEAD");
1128 print "<div class=\"page_nav\">\n" .
1129 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1130 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1131 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
1132 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$head")}, "commit") .
1133 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1134 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1137 my %tag = git_read_tag($hash);
1139 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($tag{'name'})) . "\n" .
1141 print "<div class=\"title_text\">\n" .
1142 "<table cellspacing=\"0\">\n" .
1144 "<td>object</td>\n" .
1145 "<td>" . $cgi->a({-class => "list", -href => esc_url("$my_uri?p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1146 "<td class=\"link\">" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1148 if (defined($tag{'author'})) {
1149 my %ad = date_str($tag{'epoch'}, $tag{'tz'});
1150 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
1151 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1153 print "</table>\n\n" .
1155 print "<div class=\"page_body\">";
1156 my $comment = $tag{'comment'};
1157 foreach my $line (@$comment) {
1158 print esc_html($line) . "<br/>\n";
1165 my $head = git_read_hash("$project/HEAD");
1167 print "<div class=\"page_nav\">\n" .
1168 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1169 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1170 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
1171 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$head")}, "commit") .
1172 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1173 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1176 my $taglist = git_read_refs("refs/tags");
1178 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary"), -class => "title"}, " ") .
1180 print "<table cellspacing=\"0\">\n";
1182 if (defined @$taglist) {
1183 foreach my $entry (@$taglist) {
1185 my $comment_lines = $tag{'comment'};
1186 my $comment = shift @$comment_lines;
1187 if (defined($comment)) {
1188 $comment = chop_str($comment, 30, 5);
1191 print "<tr class=\"dark\">\n";
1193 print "<tr class=\"light\">\n";
1196 print "<td><i>$tag{'age'}</i></td>\n" .
1198 $cgi->a({-href => esc_url("$my_uri?p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1199 "<b>" . esc_html($tag{'name'}) . "</b>") .
1202 if (defined($comment)) {
1203 print $cgi->a({-class => "list", -href => esc_url("$my_uri?p=$project;a=tag;h=$tag{'id'}")}, $comment);
1206 "<td class=\"link\">";
1207 if ($tag{'type'} eq "tag") {
1208 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1210 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1211 if ($tag{'reftype'} eq "commit") {
1212 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1213 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$tag{'refid'}")}, "log");
1224 my $head = git_read_hash("$project/HEAD");
1226 print "<div class=\"page_nav\">\n" .
1227 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1228 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1229 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
1230 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$head")}, "commit") .
1231 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1232 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1235 my $taglist = git_read_refs("refs/heads");
1237 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary"), -class => "title"}, " ") .
1239 print "<table cellspacing=\"0\">\n";
1241 if (defined @$taglist) {
1242 foreach my $entry (@$taglist) {
1245 print "<tr class=\"dark\">\n";
1247 print "<tr class=\"light\">\n";
1250 print "<td><i>$tag{'age'}</i></td>\n" .
1252 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
1254 "<td class=\"link\">" .
1255 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1256 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$tag{'name'}")}, "log") .
1265 sub git_get_hash_by_path {
1267 my $path = shift || return undef;
1270 my @parts = split '/', $path;
1271 while (my $part = shift @parts) {
1272 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1273 my (@entries) = map { chomp; $_ } <$fd>;
1274 close $fd or return undef;
1275 foreach my $line (@entries) {
1276 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1277 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1282 if ($t_name eq $part) {
1286 if ($t_type eq "tree") {
1296 if (!defined $hash && defined $file_name) {
1297 my $base = $hash_base || git_read_hash("$project/HEAD");
1298 $hash = git_get_hash_by_path($base, $file_name, "blob");
1300 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1302 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1303 print "<div class=\"page_nav\">\n" .
1304 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1305 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1306 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
1307 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash_base")}, "commit") .
1308 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1309 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1310 if (defined $file_name) {
1311 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") . "<br/>\n";
1313 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1317 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
1320 print "<div class=\"page_nav\">\n" .
1321 "<br/><br/></div>\n" .
1322 "<div class=\"title\">$hash</div>\n";
1324 if (defined $file_name) {
1325 print "<div class=\"page_path\"><b>$file_name</b></div>\n";
1327 print "<div class=\"page_body\">\n";
1329 while (my $line = <$fd>) {
1332 while ((my $pos = index($line, "\t")) != -1) {
1333 if (my $count = (8 - ($pos % 8))) {
1334 my $spaces = ' ' x $count;
1335 $line =~ s/\t/$spaces/;
1338 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line);
1340 close $fd or print "Reading blob failed.\n";
1345 sub git_blob_plain {
1346 my $save_as = "$hash.txt";
1347 if (defined $file_name) {
1348 $save_as = $file_name;
1350 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"$save_as\"");
1351 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1359 if (!defined $hash) {
1360 $hash = git_read_hash("$project/HEAD");
1361 if (defined $file_name) {
1362 my $base = $hash_base || git_read_hash("$project/HEAD");
1363 $hash = git_get_hash_by_path($base, $file_name, "tree");
1365 if (!defined $hash_base) {
1366 $hash_base = git_read_hash("$project/HEAD");
1369 open my $fd, "-|", "$gitbin/git-ls-tree $hash" or die_error(undef, "Open git-ls-tree failed.");
1370 my (@entries) = map { chomp; $_ } <$fd>;
1371 close $fd or die_error(undef, "Reading tree failed.");
1377 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1378 $base_key = ";hb=$hash_base";
1379 print "<div class=\"page_nav\">\n" .
1380 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1381 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1382 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash_base")}, "log") .
1383 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash_base")}, "commit") .
1384 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1389 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1392 print "<div class=\"page_nav\">\n";
1393 print "<br/><br/></div>\n";
1394 print "<div class=\"title\">$hash</div>\n";
1396 if (defined $file_name) {
1397 $base = "$file_name/";
1398 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1400 print "<div class=\"page_path\"><b>/</b></div>\n";
1402 print "<div class=\"page_body\">\n";
1403 print "<table cellspacing=\"0\">\n";
1405 foreach my $line (@entries) {
1406 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1407 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1412 $file_key = ";f=$base$t_name";
1414 print "<tr class=\"dark\">\n";
1416 print "<tr class=\"light\">\n";
1419 print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n";
1420 if ($t_type eq "blob") {
1421 print "<td class=\"list\">" .
1422 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key), -class => "list"}, $t_name) .
1424 "<td class=\"link\">" .
1425 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key)}, "blob") .
1426 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=history;h=$hash_base" . $file_key)}, "history") .
1428 } elsif ($t_type eq "tree") {
1429 print "<td class=\"list\">" .
1430 $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key)}, $t_name) .
1432 "<td class=\"link\">" .
1433 $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key)}, "tree") .
1438 print "</table>\n" .
1444 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1445 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
1446 my (@revlist) = map { chomp; $_ } <$fd>;
1447 close $fd or die_error(undef, "Reading rev-list failed.");
1448 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1449 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1450 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1451 print "<channel>\n";
1452 print "<title>$project</title>\n".
1453 "<link>" . esc_html("$my_url?p=$project;a=summary") . "</link>\n".
1454 "<description>$project log</description>\n".
1455 "<language>en</language>\n";
1457 for (my $i = 0; $i <= $#revlist; $i++) {
1458 my $commit = $revlist[$i];
1459 my %co = git_read_commit($commit);
1460 # we read 150, we always show 30 and the ones more recent than 48 hours
1461 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1464 my %cd = date_str($co{'committer_epoch'});
1465 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1466 my @difftree = map { chomp; $_ } <$fd>;
1470 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
1472 "<author>" . esc_html($co{'author'}) . "</author>\n" .
1473 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1474 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1475 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1476 "<description>" . esc_html($co{'title'}) . "</description>\n" .
1477 "<content:encoded>" .
1479 my $comment = $co{'comment'};
1480 foreach my $line (@$comment) {
1481 $line = decode("utf8", $line, Encode::FB_DEFAULT);
1482 print "$line<br/>\n";
1485 foreach my $line (@difftree) {
1486 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1490 print "$file<br/>\n";
1493 "</content:encoded>\n" .
1496 print "</channel></rss>";
1500 my @list = git_read_projects();
1502 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1503 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1504 "<opml version=\"1.0\">\n".
1506 " <title>Git OPML Export</title>\n".
1509 "<outline text=\"git RSS feeds\">\n";
1511 foreach my $pr (@list) {
1513 my $head = git_read_hash("$proj{'path'}/HEAD");
1514 if (!defined $head) {
1517 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1518 my %co = git_read_commit($head);
1523 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
1524 my $rss = "$my_url?p=$proj{'path'};a=rss";
1525 my $html = "$my_url?p=$proj{'path'};a=summary";
1526 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1528 print "</outline>\n".
1534 my $head = git_read_hash("$project/HEAD");
1535 if (!defined $hash) {
1538 if (!defined $page) {
1542 print "<div class=\"page_nav\">\n";
1543 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1544 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash")}, "shortlog") .
1546 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
1547 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1548 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1550 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1551 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1552 my (@revlist) = map { chomp; $_ } <$fd>;
1555 if ($hash ne $head || $page) {
1556 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "HEAD");
1562 $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
1564 print " ⋅ prev";
1566 if ($#revlist >= (100 * ($page+1)-1)) {
1568 $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
1570 print " ⋅ next";
1576 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary"), -class => "title"}, " ") .
1578 my %co = git_read_commit($hash);
1579 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1581 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1582 my $commit = $revlist[$i];
1583 my %co = git_read_commit($commit);
1585 my %ad = date_str($co{'author_epoch'});
1587 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit"), -class => "title"},
1588 "<span class=\"age\">$co{'age_string'}</span>" . esc_html($co{'title'})) . "\n" .
1590 print "<div class=\"title_text\">\n" .
1591 "<div class=\"log_link\">\n" .
1592 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit")}, "commit") .
1593 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1596 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1598 "<div class=\"log_body\">\n";
1599 my $comment = $co{'comment'};
1601 foreach my $line (@$comment) {
1602 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1613 print format_log_line_html($line) . "<br/>\n";
1624 my %co = git_read_commit($hash);
1626 die_error(undef, "Unknown commit object.");
1628 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1629 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1633 my $parent = $co{'parent'};
1634 if (!defined $parent) {
1638 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed.");
1639 @difftree = map { chomp; $_ } <$fd>;
1640 close $fd or die_error(undef, "Reading diff-tree failed.");
1642 # non-textual hash id's can be cached
1644 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1647 git_header_html(undef, $expires);
1648 print "<div class=\"page_nav\">\n" .
1649 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1650 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash")}, "shortlog") .
1651 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash")}, "log") .
1653 if (defined $co{'parent'}) {
1654 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1656 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1657 "<br/><br/></div>\n";
1658 if (defined $co{'parent'}) {
1660 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1664 $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1667 print "<div class=\"title_text\">\n" .
1668 "<table cellspacing=\"0\">\n";
1669 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
1671 "<td></td><td> $ad{'rfc2822'}";
1672 if ($ad{'hour_local'} < 6) {
1673 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1675 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1679 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
1680 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1681 print "<tr><td>commit</td><td style=\"font-family:monospace\">$co{'id'}</td></tr>\n";
1684 "<td style=\"font-family:monospace\">" .
1685 $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1687 "<td class=\"link\">" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1690 my $parents = $co{'parents'};
1691 foreach my $par (@$parents) {
1694 "<td style=\"font-family:monospace\">" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1695 "<td class=\"link\">" .
1696 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$par")}, "commit") .
1697 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1703 print "<div class=\"page_body\">\n";
1704 my $comment = $co{'comment'};
1707 foreach my $line (@$comment) {
1708 # print only one empty line
1710 if ($empty || $signed) {
1717 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1719 print "<span style=\"color: #888888\">" . esc_html($line) . "</span><br/>\n";
1722 print format_log_line_html($line) . "<br/>\n";
1726 print "<div class=\"list_head\">\n";
1727 if ($#difftree > 10) {
1728 print(($#difftree + 1) . " files changed:\n");
1731 print "<table cellspacing=\"0\">\n";
1733 foreach my $line (@difftree) {
1734 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1735 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1736 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1744 my $similarity = $6;
1747 print "<tr class=\"dark\">\n";
1749 print "<tr class=\"light\">\n";
1752 if ($status eq "A") {
1754 if (S_ISREG(oct $to_mode)) {
1755 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1758 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file)) . "</td>\n" .
1759 "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1760 "<td class=\"link\">" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
1761 } elsif ($status eq "D") {
1763 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file)) . "</td>\n" .
1764 "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1765 "<td class=\"link\">" .
1766 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
1767 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=history;h=$hash;f=$file")}, "history") .
1769 } elsif ($status eq "M" || $status eq "T") {
1770 my $mode_chnge = "";
1771 if ($from_mode != $to_mode) {
1772 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1773 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1774 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1776 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1777 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1778 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1779 } elsif (S_ISREG($to_mode)) {
1780 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1783 $mode_chnge .= "]</span>\n";
1786 if ($to_id ne $from_id) {
1787 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
1789 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
1792 "<td>$mode_chnge</td>\n" .
1793 "<td class=\"link\">";
1794 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
1795 if ($to_id ne $from_id) {
1796 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
1798 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
1800 } elsif ($status eq "R") {
1801 my ($from_file, $to_file) = split "\t", $file;
1803 if ($from_mode != $to_mode) {
1804 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1807 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"), -class => "list"}, esc_html($to_file)) . "</td>\n" .
1808 "<td><span style=\"color: #777777;\">[moved from " .
1809 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file"), -class => "list"}, esc_html($from_file)) .
1810 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1811 "<td class=\"link\">" .
1812 $cgi->a({-href => esc_uresc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
1813 if ($to_id ne $from_id) {
1814 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
1825 mkdir($git_temp, 0700);
1827 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1828 print "<div class=\"page_nav\">\n" .
1829 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1830 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1831 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
1832 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash_base")}, "commit") .
1833 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1834 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
1836 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
1839 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1842 print "<div class=\"page_nav\">\n" .
1843 "<br/><br/></div>\n" .
1844 "<div class=\"title\">$hash vs $hash_parent</div>\n";
1846 if (defined $file_name) {
1847 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1849 print "<div class=\"page_body\">\n" .
1850 "<div class=\"diff_info\">blob:" .
1851 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
1853 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
1855 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
1860 sub git_blobdiff_plain {
1861 mkdir($git_temp, 0700);
1862 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1863 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
1866 sub git_commitdiff {
1867 mkdir($git_temp, 0700);
1868 my %co = git_read_commit($hash);
1870 die_error(undef, "Unknown commit object.");
1872 if (!defined $hash_parent) {
1873 $hash_parent = $co{'parent'};
1875 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1876 my (@difftree) = map { chomp; $_ } <$fd>;
1877 close $fd or die_error(undef, "Reading diff-tree failed.");
1879 # non-textual hash id's can be cached
1881 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1884 git_header_html(undef, $expires);
1885 print "<div class=\"page_nav\">\n" .
1886 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1887 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash")}, "shortlog") .
1888 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash")}, "log") .
1889 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
1891 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
1892 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
1895 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1897 print "<div class=\"page_body\">\n";
1898 my $comment = $co{'comment'};
1901 my @log = @$comment;
1902 # remove first and empty lines after that
1904 while (defined $log[0] && $log[0] eq "") {
1907 foreach my $line (@log) {
1908 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1919 print format_log_line_html($line) . "<br/>\n";
1922 foreach my $line (@difftree) {
1923 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1924 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1925 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1932 if ($status eq "A") {
1933 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
1934 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
1936 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
1937 } elsif ($status eq "D") {
1938 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
1939 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
1941 git_diff_print($from_id, "a/$file", undef, "/dev/null");
1942 } elsif ($status eq "M") {
1943 if ($from_id ne $to_id) {
1944 print "<div class=\"diff_info\">" .
1945 file_type($from_mode) . ":" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
1947 file_type($to_mode) . ":" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
1949 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
1958 sub git_commitdiff_plain {
1959 mkdir($git_temp, 0700);
1960 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1961 my (@difftree) = map { chomp; $_ } <$fd>;
1962 close $fd or die_error(undef, "Reading diff-tree failed.");
1964 # try to figure out the next tag after this commit
1967 my $tags = git_read_refs("refs/tags");
1968 foreach my $entry (@$tags) {
1970 $taghash{$tag{'refid'}} = $tag{'name'};
1972 open $fd, "-|", "$gitbin/git-rev-list HEAD";
1973 while (my $commit = <$fd>) {
1975 if ($taghash{$commit}) {
1976 $tagname = $taghash{$commit};
1978 if ($commit eq $hash) {
1984 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
1985 my %co = git_read_commit($hash);
1986 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1987 my $comment = $co{'comment'};
1988 print "From: $co{'author'}\n" .
1989 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
1990 "Subject: $co{'title'}\n";
1991 if (defined $tagname) {
1992 print "X-Git-Tag: $tagname\n";
1994 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
1997 foreach my $line (@$comment) {;
2002 foreach my $line (@difftree) {
2003 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2008 if ($status eq "A") {
2009 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
2010 } elsif ($status eq "D") {
2011 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
2012 } elsif ($status eq "M") {
2013 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
2019 if (!defined $hash) {
2020 $hash = git_read_hash("$project/HEAD");
2022 my %co = git_read_commit($hash);
2024 die_error(undef, "Unknown commit object.");
2027 print "<div class=\"page_nav\">\n" .
2028 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
2029 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
2030 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
2031 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
2032 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2033 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2037 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2039 print "<div class=\"page_path\"><b>/$file_name</b><br/></div>\n";
2041 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin \'$file_name\'";
2043 print "<table cellspacing=\"0\">\n";
2045 while (my $line = <$fd>) {
2046 if ($line =~ m/^([0-9a-fA-F]{40})/){
2050 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2051 my %co = git_read_commit($commit);
2056 print "<tr class=\"dark\">\n";
2058 print "<tr class=\"light\">\n";
2061 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2062 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2063 "<td>" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2064 esc_html(chop_str($co{'title'}, 50)) . "</b>") . "</td>\n" .
2065 "<td class=\"link\">" .
2066 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit")}, "commit") .
2067 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2068 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2069 my $blob = git_get_hash_by_path($hash, $file_name);
2070 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2071 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2073 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2087 if (!defined $searchtext) {
2088 die_error("", "Text field empty.");
2090 if (!defined $hash) {
2091 $hash = git_read_hash("$project/HEAD");
2093 my %co = git_read_commit($hash);
2095 die_error(undef, "Unknown commit object.");
2097 # pickaxe may take all resources of your box and run for several minutes
2098 # with every query - so decide by yourself how public you make this feature :)
2099 my $commit_search = 1;
2100 my $author_search = 0;
2101 my $committer_search = 0;
2102 my $pickaxe_search = 0;
2103 if ($searchtext =~ s/^author\\://i) {
2105 } elsif ($searchtext =~ s/^committer\\://i) {
2106 $committer_search = 1;
2107 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2109 $pickaxe_search = 1;
2112 print "<div class=\"page_nav\">\n" .
2113 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary;h=$hash")}, "summary") .
2114 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
2115 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash")}, "log") .
2116 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
2117 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2118 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2123 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2125 print "<table cellspacing=\"0\">\n";
2127 if ($commit_search) {
2129 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2130 while (my $commit_text = <$fd>) {
2131 if (!grep m/$searchtext/i, $commit_text) {
2134 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2137 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2140 my @commit_lines = split "\n", $commit_text;
2141 my %co = git_read_commit(undef, \@commit_lines);
2146 print "<tr class=\"dark\">\n";
2148 print "<tr class=\"light\">\n";
2151 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2152 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2154 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" . esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2155 my $comment = $co{'comment'};
2156 foreach my $line (@$comment) {
2157 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2158 my $lead = esc_html($1) || "";
2159 $lead = chop_str($lead, 30, 10);
2160 my $match = esc_html($2) || "";
2161 my $trail = esc_html($3) || "";
2162 $trail = chop_str($trail, 30, 10);
2163 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
2164 print chop_str($text, 80, 5) . "<br/>\n";
2168 "<td class=\"link\">" .
2169 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$co{'id'}")}, "commit") .
2170 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2177 if ($pickaxe_search) {
2179 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2182 while (my $line = <$fd>) {
2183 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2186 $set{'from_id'} = $3;
2188 $set{'id'} = $set{'to_id'};
2189 if ($set{'id'} =~ m/0{40}/) {
2190 $set{'id'} = $set{'from_id'};
2192 if ($set{'id'} =~ m/0{40}/) {
2196 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2199 print "<tr class=\"dark\">\n";
2201 print "<tr class=\"light\">\n";
2204 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2205 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2207 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2208 esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2209 while (my $setref = shift @files) {
2211 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2212 "<span style=\"color:#e00000\">" . esc_html($set{'file'}) . "</span>") .
2216 "<td class=\"link\">" .
2217 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$co{'id'}")}, "commit") .
2218 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2222 %co = git_read_commit($1);
2232 my $head = git_read_hash("$project/HEAD");
2233 if (!defined $hash) {
2236 if (!defined $page) {
2240 print "<div class=\"page_nav\">\n" .
2241 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
2243 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash")}, "log") .
2244 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
2245 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2246 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2248 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2249 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
2250 my (@revlist) = map { chomp; $_ } <$fd>;
2253 if ($hash ne $head || $page) {
2254 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "HEAD");
2260 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
2262 print " ⋅ prev";
2264 if ($#revlist >= (100 * ($page+1)-1)) {
2266 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
2268 print " ⋅ next";
2273 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary"), -class => "title"}, " ") .
2275 print "<table cellspacing=\"0\">\n";
2277 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2278 my $commit = $revlist[$i];
2279 my %co = git_read_commit($commit);
2280 my %ad = date_str($co{'author_epoch'});
2282 print "<tr class=\"dark\">\n";
2284 print "<tr class=\"light\">\n";
2287 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2288 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2290 if (length($co{'title_short'}) < length($co{'title'})) {
2291 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
2292 "<b>" . esc_html($co{'title_short'}) . "</b>");
2294 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit"), -class => "list"},
2295 "<b>" . esc_html($co{'title_short'}) . "</b>");
2298 "<td class=\"link\">" .
2299 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit")}, "commit") .
2300 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2304 if ($#revlist >= (100 * ($page+1)-1)) {
2307 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title => "Alt-n"}, "next") .