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);
17 binmode STDOUT, ':utf8';
21 my $my_url = $cgi->url();
22 my $my_uri = $cgi->url(-absolute => 1);
25 # absolute fs-path which will be prepended to the project path
26 #my $projectroot = "/pub/scm";
27 my $projectroot = "/home/kay/public_html/pub/scm";
29 # location of the git-core binaries
30 my $gitbin = "/usr/bin";
32 # location for temporary files needed for diffs
33 my $git_temp = "/tmp/gitweb";
35 # target of the home link on top of all pages
36 my $home_link = $my_uri;
38 # html text to include at home page
39 my $home_text = "indextext.html";
41 # source of projects list
42 #my $projects_list = $projectroot;
43 my $projects_list = "index/index.aux";
45 # input validation and dispatch
46 my $action = $cgi->param('a');
47 if (defined $action) {
48 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
50 die_error(undef, "Invalid action parameter.");
52 if ($action eq "git-logo.png") {
55 } elsif ($action eq "opml") {
61 my $order = $cgi->param('o');
63 if ($order =~ m/[^0-9a-zA-Z_]/) {
65 die_error(undef, "Invalid order parameter.");
69 my $project = $cgi->param('p');
70 if (defined $project) {
71 $project = validate_input($project);
72 if (!defined($project)) {
73 die_error(undef, "Invalid project parameter.");
75 if (!(-d "$projectroot/$project")) {
77 die_error(undef, "No such directory.");
79 if (!(-e "$projectroot/$project/HEAD")) {
81 die_error(undef, "No such project.");
83 $rss_link = "<link rel=\"alternate\" title=\"" . esc_url($project) . " log\" href=\"" .
84 esc_url("$my_uri?p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
85 $ENV{'GIT_DIR'} = "$projectroot/$project";
91 my $file_name = $cgi->param('f');
92 if (defined $file_name) {
93 $file_name = validate_input($file_name);
94 if (!defined($file_name)) {
95 die_error(undef, "Invalid file parameter.");
99 my $hash = $cgi->param('h');
101 $hash = validate_input($hash);
102 if (!defined($hash)) {
103 die_error(undef, "Invalid hash parameter.");
107 my $hash_parent = $cgi->param('hp');
108 if (defined $hash_parent) {
109 $hash_parent = validate_input($hash_parent);
110 if (!defined($hash_parent)) {
111 die_error(undef, "Invalid hash parent parameter.");
115 my $hash_base = $cgi->param('hb');
116 if (defined $hash_base) {
117 $hash_base = validate_input($hash_base);
118 if (!defined($hash_base)) {
119 die_error(undef, "Invalid hash base parameter.");
123 my $page = $cgi->param('pg');
125 if ($page =~ m/[^0-9]$/) {
127 die_error(undef, "Invalid page parameter.");
131 my $searchtext = $cgi->param('s');
132 if (defined $searchtext) {
133 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
135 die_error(undef, "Invalid search parameter.");
137 $searchtext = quotemeta $searchtext;
143 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
146 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
149 if ($input =~ m/[^a-zA-Z0-9_ \.\/\-\+\#\~]/) {
155 if (!defined $action || $action eq "summary") {
158 } elsif ($action eq "heads") {
161 } elsif ($action eq "tags") {
164 } elsif ($action eq "blob") {
167 } elsif ($action eq "blob_plain") {
170 } elsif ($action eq "tree") {
173 } elsif ($action eq "rss") {
176 } elsif ($action eq "commit") {
179 } elsif ($action eq "log") {
182 } elsif ($action eq "blobdiff") {
185 } elsif ($action eq "blobdiff_plain") {
186 git_blobdiff_plain();
188 } elsif ($action eq "commitdiff") {
191 } elsif ($action eq "commitdiff_plain") {
192 git_commitdiff_plain();
194 } elsif ($action eq "history") {
197 } elsif ($action eq "search") {
200 } elsif ($action eq "shortlog") {
203 } elsif ($action eq "tag") {
208 die_error(undef, "Unknown action.");
221 $str = decode("utf8", $str, Encode::FB_DEFAULT);
222 $str = escapeHTML($str);
226 sub git_header_html {
227 my $status = shift || "200 OK";
231 if (defined $project) {
232 $title .= " - $project";
233 if (defined $action) {
234 $title .= "/$action";
237 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires);
239 <?xml version="1.0" encoding="utf-8"?>
240 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
241 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
242 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
244 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
245 <meta name="robots" content="index, nofollow"/>
246 <title>$title</title>
248 <style type="text/css">
249 body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
251 a:hover, a:visited, a:active { color:#880000; }
252 div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; }
253 div.page_header a:visited, a.header { color:#0000cc; }
254 div.page_header a:hover { color:#880000; }
255 div.page_nav { padding:8px; }
256 div.page_nav a:visited { color:#0000cc; }
257 div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
258 div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
259 div.page_footer_text { float:left; color:#555555; font-style:italic; }
260 div.page_body { padding:8px; }
262 display:block; padding:6px 8px;
263 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
265 a.title:hover { background-color: #d9d8d1; }
266 div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; }
267 div.log_body { padding:8px 8px 8px 150px; }
268 span.age { position:relative; float:left; width:142px; font-style:italic; }
271 font-size:10px; font-family:sans-serif; font-style:normal;
272 position:relative; float:left; width:136px;
274 div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; }
275 a.list { text-decoration:none; color:#000000; }
276 a.list:hover { text-decoration:underline; color:#880000; }
277 a.text { text-decoration:none; color:#0000cc; }
278 a.text:visited { text-decoration:none; color:#880000; }
279 a.text:hover { text-decoration:underline; color:#880000; }
280 table { padding:8px 4px; }
281 th { padding:2px 5px; font-size:12px; text-align:left; }
282 tr.light:hover { background-color:#edece6; }
283 tr.dark { background-color:#f6f6f0; }
284 tr.dark:hover { background-color:#edece6; }
285 td { padding:2px 5px; font-size:12px; vertical-align:top; }
286 td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; }
287 div.pre { font-family:monospace; font-size:12px; white-space:pre; }
288 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
289 div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
290 div.search { margin:4px 8px; position:absolute; top:56px; right:12px }
291 a.linenr { color:#999999; text-decoration:none }
293 float:right; padding:3px 0px; width:35px; line-height:10px;
294 border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
295 color:#ffffff; background-color:#ff6600;
296 font-weight:bold; font-family:sans-serif; font-size:10px;
297 text-align:center; text-decoration:none;
299 a.rss_logo:hover { background-color:#ee5500; }
304 print "<div class=\"page_header\">\n" .
305 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
306 "<img src=\"" . esc_url("$my_uri?a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
308 print $cgi->a({-href => esc_url($home_link)}, "projects") . " / ";
309 if (defined $project) {
310 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, esc_html($project));
311 if (defined $action) {
315 if (!defined $searchtext) {
320 $search_hash = $hash;
322 $search_hash = "HEAD";
324 $cgi->param("a", "search");
325 $cgi->param("h", $search_hash);
326 print $cgi->startform(-method => "get", -action => $my_uri) .
327 "<div class=\"search\">\n" .
328 $cgi->hidden(-name => "p") . "\n" .
329 $cgi->hidden(-name => "a") . "\n" .
330 $cgi->hidden(-name => "h") . "\n" .
331 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
333 $cgi->end_form() . "\n";
338 sub git_footer_html {
339 print "<div class=\"page_footer\">\n";
340 if (defined $project) {
341 my $descr = git_read_description($project);
342 if (defined $descr) {
343 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
345 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
347 print $cgi->a({-href => esc_url("$my_uri?a=opml"), -class => "rss_logo"}, "OPML") . "\n";
355 my $status = shift || "403 Forbidden";
356 my $error = shift || "Malformed query, file missing or permission denied";
358 git_header_html($status);
359 print "<div class=\"page_body\">\n" .
361 "$status - $error\n" .
371 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
381 open my $fd, "$projectroot/$path" or return undef;
385 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
390 sub git_read_description {
393 open my $fd, "$projectroot/$path/description" or return undef;
405 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
406 $tag{'id'} = $tag_id;
407 while (my $line = <$fd>) {
409 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
411 } elsif ($line =~ m/^type (.+)$/) {
413 } elsif ($line =~ m/^tag (.+)$/) {
415 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
419 } elsif ($line =~ m/--BEGIN/) {
420 push @comment, $line;
422 } elsif ($line eq "") {
426 push @comment, <$fd>;
427 $tag{'comment'} = \@comment;
429 if (!defined $tag{'name'}) {
439 if ($age > 60*60*24*365*2) {
440 $age_str = (int $age/60/60/24/365);
441 $age_str .= " years ago";
442 } elsif ($age > 60*60*24*(365/12)*2) {
443 $age_str = int $age/60/60/24/(365/12);
444 $age_str .= " months ago";
445 } elsif ($age > 60*60*24*7*2) {
446 $age_str = int $age/60/60/24/7;
447 $age_str .= " weeks ago";
448 } elsif ($age > 60*60*24*2) {
449 $age_str = int $age/60/60/24;
450 $age_str .= " days ago";
451 } elsif ($age > 60*60*2) {
452 $age_str = int $age/60/60;
453 $age_str .= " hours ago";
454 } elsif ($age > 60*2) {
455 $age_str = int $age/60;
456 $age_str .= " min ago";
459 $age_str .= " sec ago";
461 $age_str .= " right now";
466 sub git_read_commit {
467 my $commit_id = shift;
468 my $commit_text = shift;
473 if (defined $commit_text) {
474 @commit_lines = @$commit_text;
477 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
478 @commit_lines = split '\n', <$fd>;
483 my $header = shift @commit_lines;
484 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
487 ($co{'id'}, my @parents) = split ' ', $header;
488 $co{'parents'} = \@parents;
489 $co{'parent'} = $parents[0];
490 while (my $line = shift @commit_lines) {
491 last if $line eq "\n";
492 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
494 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
496 $co{'author_epoch'} = $2;
497 $co{'author_tz'} = $3;
498 if ($co{'author'} =~ m/^([^<]+) </) {
499 $co{'author_name'} = $1;
501 $co{'author_name'} = $co{'author'};
503 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
504 $co{'committer'} = $1;
505 $co{'committer_epoch'} = $2;
506 $co{'committer_tz'} = $3;
507 $co{'committer_name'} = $co{'committer'};
508 $co{'committer_name'} =~ s/ <.*//;
511 if (!defined $co{'tree'}) {
515 foreach my $title (@commit_lines) {
517 $co{'title'} = chop_str($title, 80, 5);
518 # remove leading stuff of merges to make the interesting part visible
519 if (length($title) > 50) {
520 $title =~ s/^Automatic //;
521 $title =~ s/^merge (of|with) /Merge ... /i;
522 if (length($title) > 50) {
523 $title =~ s/(http|rsync):\/\///;
525 if (length($title) > 50) {
526 $title =~ s/(master|www|rsync)\.//;
528 if (length($title) > 50) {
529 $title =~ s/kernel.org:?//;
531 if (length($title) > 50) {
532 $title =~ s/\/pub\/scm//;
535 $co{'title_short'} = chop_str($title, 50, 5);
539 # remove added spaces
540 foreach my $line (@commit_lines) {
543 $co{'comment'} = \@commit_lines;
545 my $age = time - $co{'committer_epoch'};
547 $co{'age_string'} = age_string($age);
548 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
549 if ($age > 60*60*24*7*2) {
550 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
551 $co{'age_string_age'} = $co{'age_string'};
553 $co{'age_string_date'} = $co{'age_string'};
554 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
561 my $from_name = shift;
564 my $format = shift || "html";
566 my $from_tmp = "/dev/null";
567 my $to_tmp = "/dev/null";
570 # create tmp from-file
572 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
573 open my $fd2, "> $from_tmp";
574 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
583 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
584 open my $fd2, "> $to_tmp";
585 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
592 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
593 if ($format eq "plain") {
598 while (my $line = <$fd>) {
600 my $char = substr($line, 0, 1);
603 $color = " style=\"color:#008800;\"";
604 } elsif ($char eq "-") {
605 $color = " style=\"color:#cc0000;\"";
606 } elsif ($char eq "@") {
607 $color = " style=\"color:#990099;\"";
608 } elsif ($char eq "\\") {
612 while ((my $pos = index($line, "\t")) != -1) {
613 if (my $count = (8 - (($pos-1) % 8))) {
614 my $spaces = ' ' x $count;
615 $line =~ s/\t/$spaces/;
618 print "<div class=\"pre\"$color>" . esc_html($line) . "</div>\n";
632 my $mode = oct shift;
634 if (S_ISDIR($mode & S_IFMT)) {
636 } elsif (S_ISLNK($mode)) {
638 } elsif (S_ISREG($mode)) {
639 # git cares only about the executable bit
640 if ($mode & S_IXUSR) {
653 my $add_len = shift || 10;
655 # allow only $len chars, but don't cut a word if it would fit in $add_len
656 # if it doesn't fit, cut it if it's still longer than the dots we would add
657 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
660 if (length($tail) > 4) {
667 my $mode = oct shift;
669 if (S_ISDIR($mode & S_IFMT)) {
671 } elsif (S_ISLNK($mode)) {
673 } elsif (S_ISREG($mode)) {
680 sub format_log_line_html {
683 $line = esc_html($line);
684 $line =~ s/ / /g;
685 if ($line =~ m/([0-9a-fA-F]{40})/) {
687 if (git_get_type($hash_text) eq "commit") {
688 my $link = $cgi->a({-class => "text", -href => esc_url("$my_uri?p=$project;a=commit;h=$hash_text")}, $hash_text);
689 $line =~ s/$hash_text/$link/;
697 my $tz = shift || "-0000";
700 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
701 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
702 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
703 $date{'hour'} = $hour;
704 $date{'minute'} = $min;
705 $date{'mday'} = $mday;
706 $date{'day'} = $days[$wday];
707 $date{'month'} = $months[$mon];
708 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
709 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
711 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
712 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
713 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
714 $date{'hour_local'} = $hour;
715 $date{'minute_local'} = $min;
716 $date{'tz_local'} = $tz;
720 # git-logo (cached in browser for one day)
722 print $cgi->header(-type => 'image/png', -expires => '+1d');
723 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
724 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
725 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
726 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
727 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
728 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
729 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
730 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
731 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
732 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
733 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
734 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
735 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
736 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
742 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
743 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
744 if (!defined $gcos) {
748 $owner =~ s/[,;].*$//;
752 sub git_read_projects {
755 if (-d $projects_list) {
756 # search in directory
757 my $dir = $projects_list;
758 opendir my $dh, $dir or return undef;
759 while (my $dir = readdir($dh)) {
760 if (-e "$projectroot/$dir/HEAD") {
768 } elsif (-f $projects_list) {
769 # read from file(url-encoded):
770 # 'git%2Fgit.git Linus+Torvalds'
771 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
772 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
773 open my $fd , $projects_list or return undef;
774 while (my $line = <$fd>) {
776 my ($path, $owner) = split ' ', $line;
777 $path = unescape($path);
778 $owner = unescape($owner);
779 if (!defined $path) {
782 if (-e "$projectroot/$path/HEAD") {
792 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
796 sub git_project_list {
797 my @list = git_read_projects();
800 die_error(undef, "No project found.");
802 foreach my $pr (@list) {
803 my $head = git_read_hash("$pr->{'path'}/HEAD");
804 if (!defined $head) {
807 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
808 my %co = git_read_commit($head);
812 $pr->{'commit'} = \%co;
813 if (!defined $pr->{'descr'}) {
814 my $descr = git_read_description($pr->{'path'}) || "";
815 $pr->{'descr'} = chop_str($descr, 25, 5);
817 if (!defined $pr->{'owner'}) {
818 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
824 print "<div class=\"index_include\">\n";
825 open (my $fd, $home_text);
830 print "<table cellspacing=\"0\">\n" .
832 if (!defined($order) || (defined($order) && ($order eq "project"))) {
833 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
834 print "<th>Project</th>\n";
836 print "<th>" . $cgi->a({-class => "header", -href => esc_url("$my_uri?o=project")}, "Project") . "</th>\n";
838 if (defined($order) && ($order eq "descr")) {
839 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
840 print "<th>Description</th>\n";
842 print "<th>" . $cgi->a({-class => "header", -href => esc_url("$my_uri?o=descr")}, "Description") . "</th>\n";
844 if (defined($order) && ($order eq "owner")) {
845 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
846 print "<th>Owner</th>\n";
848 print "<th>" . $cgi->a({-class => "header", -href => esc_url("$my_uri?o=owner")}, "Owner") . "</th>\n";
850 if (defined($order) && ($order eq "age")) {
851 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
852 print "<th>Last Change</th>\n";
854 print "<th>" . $cgi->a({-class => "header", -href => esc_url("$my_uri?o=age")}, "Last Change") . "</th>\n";
856 print "<th></th>\n" .
859 foreach my $pr (@projects) {
861 print "<tr class=\"dark\">\n";
863 print "<tr class=\"light\">\n";
866 print "<td>" . $cgi->a({-href => esc_url("$my_uri?p=$pr->{'path'};a=summary"), -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
867 "<td>$pr->{'descr'}</td>\n" .
868 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
870 if ($pr->{'commit'}{'age'} < 60*60*2) {
871 $colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>";
872 } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {
873 $colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>";
875 $colored_age = "<i>$pr->{'commit'}{'age_string'}</i>";
877 print "<td>$colored_age</td>\n" .
878 "<td class=\"link\">" .
879 $cgi->a({-href => esc_url("$my_uri?p=$pr->{'path'};a=summary")}, "summary") .
880 " | " . $cgi->a({-href => esc_url("$my_uri?p=$pr->{'path'};a=shortlog")}, "shortlog") .
881 " | " . $cgi->a({-href => esc_url("$my_uri?p=$pr->{'path'};a=log")}, "log") .
894 opendir my $dh, "$projectroot/$project/$ref_dir";
895 while (my $dir = readdir($dh)) {
896 if ($dir =~ m/^\./) {
899 if (-d "$projectroot/$project/$ref_dir/$dir") {
900 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
901 my @subdirs = grep !m/^\./, readdir $dh2;
903 foreach my $subdir (@subdirs) {
904 push @refs, "$dir/$subdir"
911 foreach my $ref_file (@refs) {
912 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
913 my $type = git_get_type($ref_id) || next;
916 $ref_item{'type'} = $type;
917 $ref_item{'id'} = $ref_id;
918 $ref_item{'epoch'} = 0;
919 $ref_item{'age'} = "unknown";
920 if ($type eq "tag") {
921 my %tag = git_read_tag($ref_id);
922 $ref_item{'comment'} = $tag{'comment'};
923 if ($tag{'type'} eq "commit") {
924 %co = git_read_commit($tag{'object'});
925 $ref_item{'epoch'} = $co{'committer_epoch'};
926 $ref_item{'age'} = $co{'age_string'};
927 } elsif (defined($tag{'epoch'})) {
928 my $age = time - $tag{'epoch'};
929 $ref_item{'epoch'} = $tag{'epoch'};
930 $ref_item{'age'} = age_string($age);
932 $ref_item{'reftype'} = $tag{'type'};
933 $ref_item{'name'} = $tag{'name'};
934 $ref_item{'refid'} = $tag{'object'};
935 } elsif ($type eq "commit"){
936 %co = git_read_commit($ref_id);
937 $ref_item{'reftype'} = "commit";
938 $ref_item{'name'} = $ref_file;
939 $ref_item{'title'} = $co{'title'};
940 $ref_item{'refid'} = $ref_id;
941 $ref_item{'epoch'} = $co{'committer_epoch'};
942 $ref_item{'age'} = $co{'age_string'};
945 push @reflist, \%ref_item;
948 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
953 my $descr = git_read_description($project) || "none";
954 my $head = git_read_hash("$project/HEAD");
955 my %co = git_read_commit($head);
956 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
959 if (-f $projects_list) {
960 open (my $fd , $projects_list);
961 while (my $line = <$fd>) {
963 my ($pr, $ow) = split ' ', $line;
966 if ($pr eq $project) {
973 if (!defined $owner) {
974 $owner = get_file_owner("$projectroot/$project");
978 print "<div class=\"page_nav\">\n" .
980 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
981 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
982 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$head")}, "commit") .
983 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$head")}, "commitdiff") .
984 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree")}, "tree") .
987 print "<div class=\"title\"> </div>\n";
988 print "<table cellspacing=\"0\">\n" .
989 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
990 "<tr><td>owner</td><td>$owner</td></tr>\n" .
991 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
993 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
994 my (@revlist) = map { chomp; $_ } <$fd>;
997 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1000 print "<table cellspacing=\"0\">\n";
1002 foreach my $commit (@revlist) {
1003 my %co = git_read_commit($commit);
1004 my %ad = date_str($co{'author_epoch'});
1006 print "<tr class=\"dark\">\n";
1008 print "<tr class=\"light\">\n";
1012 print "<td><i>$co{'age_string'}</i></td>\n" .
1013 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1015 if (length($co{'title_short'}) < length($co{'title'})) {
1016 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
1017 "<b>" . esc_html($co{'title_short'}) . "</b>");
1019 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit"), -class => "list"},
1020 "<b>" . esc_html($co{'title'}) . "</b>");
1023 "<td class=\"link\">" .
1024 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit")}, "commit") .
1025 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1029 print "<td>" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "...") . "</td>\n" .
1036 my $taglist = git_read_refs("refs/tags");
1037 if (defined @$taglist) {
1039 $cgi->a({-href => esc_url("$my_uri?p=$project;a=tags"), -class => "title"}, "tags") .
1042 print "<table cellspacing=\"0\">\n";
1044 foreach my $entry (@$taglist) {
1046 my $comment_lines = $tag{'comment'};
1047 my $comment = shift @$comment_lines;
1048 if (defined($comment)) {
1049 $comment = chop_str($comment, 30, 5);
1052 print "<tr class=\"dark\">\n";
1054 print "<tr class=\"light\">\n";
1058 print "<td><i>$tag{'age'}</i></td>\n" .
1060 $cgi->a({-href => esc_url("$my_uri?p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1061 "<b>" . esc_html($tag{'name'}) . "</b>") .
1064 if (defined($comment)) {
1065 print $cgi->a({-class => "list", -href => esc_url("$my_uri?p=$project;a=tag;h=$tag{'id'}")}, $comment);
1068 "<td class=\"link\">";
1069 if ($tag{'type'} eq "tag") {
1070 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1072 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1073 if ($tag{'reftype'} eq "commit") {
1074 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1075 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$tag{'refid'}")}, "log");
1080 print "<td>" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tags")}, "...") . "</td>\n" .
1088 my $headlist = git_read_refs("refs/heads");
1089 if (defined @$headlist) {
1091 $cgi->a({-href => esc_url("$my_uri?p=$project;a=heads"), -class => "title"}, "heads") .
1094 print "<table cellspacing=\"0\">\n";
1096 foreach my $entry (@$headlist) {
1099 print "<tr class=\"dark\">\n";
1101 print "<tr class=\"light\">\n";
1105 print "<td><i>$tag{'age'}</i></td>\n" .
1107 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1108 "<b>" . esc_html($tag{'name'}) . "</b>") .
1110 "<td class=\"link\">" .
1111 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1112 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$tag{'name'}")}, "log") .
1116 print "<td>" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=heads")}, "...") . "</td>\n" .
1127 my $head = git_read_hash("$project/HEAD");
1129 print "<div class=\"page_nav\">\n" .
1130 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1131 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1132 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
1133 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$head")}, "commit") .
1134 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1135 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1138 my %tag = git_read_tag($hash);
1140 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($tag{'name'})) . "\n" .
1142 print "<div class=\"title_text\">\n" .
1143 "<table cellspacing=\"0\">\n" .
1145 "<td>object</td>\n" .
1146 "<td>" . $cgi->a({-class => "list", -href => esc_url("$my_uri?p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1147 "<td class=\"link\">" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1149 if (defined($tag{'author'})) {
1150 my %ad = date_str($tag{'epoch'}, $tag{'tz'});
1151 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
1152 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1154 print "</table>\n\n" .
1156 print "<div class=\"page_body\">";
1157 my $comment = $tag{'comment'};
1158 foreach my $line (@$comment) {
1159 print esc_html($line) . "<br/>\n";
1166 my $head = git_read_hash("$project/HEAD");
1168 print "<div class=\"page_nav\">\n" .
1169 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1170 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1171 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
1172 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$head")}, "commit") .
1173 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1174 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1177 my $taglist = git_read_refs("refs/tags");
1179 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary"), -class => "title"}, " ") .
1181 print "<table cellspacing=\"0\">\n";
1183 if (defined @$taglist) {
1184 foreach my $entry (@$taglist) {
1186 my $comment_lines = $tag{'comment'};
1187 my $comment = shift @$comment_lines;
1188 if (defined($comment)) {
1189 $comment = chop_str($comment, 30, 5);
1192 print "<tr class=\"dark\">\n";
1194 print "<tr class=\"light\">\n";
1197 print "<td><i>$tag{'age'}</i></td>\n" .
1199 $cgi->a({-href => esc_url("$my_uri?p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1200 "<b>" . esc_html($tag{'name'}) . "</b>") .
1203 if (defined($comment)) {
1204 print $cgi->a({-class => "list", -href => esc_url("$my_uri?p=$project;a=tag;h=$tag{'id'}")}, $comment);
1207 "<td class=\"link\">";
1208 if ($tag{'type'} eq "tag") {
1209 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1211 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1212 if ($tag{'reftype'} eq "commit") {
1213 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1214 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$tag{'refid'}")}, "log");
1225 my $head = git_read_hash("$project/HEAD");
1227 print "<div class=\"page_nav\">\n" .
1228 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1229 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1230 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
1231 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$head")}, "commit") .
1232 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1233 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1236 my $taglist = git_read_refs("refs/heads");
1238 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary"), -class => "title"}, " ") .
1240 print "<table cellspacing=\"0\">\n";
1242 if (defined @$taglist) {
1243 foreach my $entry (@$taglist) {
1246 print "<tr class=\"dark\">\n";
1248 print "<tr class=\"light\">\n";
1251 print "<td><i>$tag{'age'}</i></td>\n" .
1253 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
1255 "<td class=\"link\">" .
1256 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1257 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$tag{'name'}")}, "log") .
1266 sub git_get_hash_by_path {
1268 my $path = shift || return undef;
1271 my @parts = split '/', $path;
1272 while (my $part = shift @parts) {
1273 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1274 my (@entries) = map { chomp; $_ } <$fd>;
1275 close $fd or return undef;
1276 foreach my $line (@entries) {
1277 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1278 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1283 if ($t_name eq $part) {
1287 if ($t_type eq "tree") {
1297 if (!defined $hash && defined $file_name) {
1298 my $base = $hash_base || git_read_hash("$project/HEAD");
1299 $hash = git_get_hash_by_path($base, $file_name, "blob");
1301 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1303 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1304 print "<div class=\"page_nav\">\n" .
1305 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1306 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1307 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
1308 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash_base")}, "commit") .
1309 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1310 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1311 if (defined $file_name) {
1312 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1313 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1315 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1319 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
1322 print "<div class=\"page_nav\">\n" .
1323 "<br/><br/></div>\n" .
1324 "<div class=\"title\">$hash</div>\n";
1326 if (defined $file_name) {
1327 print "<div class=\"page_path\"><b>$file_name</b></div>\n";
1329 print "<div class=\"page_body\">\n";
1331 while (my $line = <$fd>) {
1334 while ((my $pos = index($line, "\t")) != -1) {
1335 if (my $count = (8 - ($pos % 8))) {
1336 my $spaces = ' ' x $count;
1337 $line =~ s/\t/$spaces/;
1340 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line);
1342 close $fd or print "Reading blob failed.\n";
1347 sub git_blob_plain {
1348 my $save_as = "$hash.txt";
1349 if (defined $file_name) {
1350 $save_as = $file_name;
1352 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"$save_as\"");
1353 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1361 if (!defined $hash) {
1362 $hash = git_read_hash("$project/HEAD");
1363 if (defined $file_name) {
1364 my $base = $hash_base || git_read_hash("$project/HEAD");
1365 $hash = git_get_hash_by_path($base, $file_name, "tree");
1367 if (!defined $hash_base) {
1368 $hash_base = git_read_hash("$project/HEAD");
1371 open my $fd, "-|", "$gitbin/git-ls-tree $hash" or die_error(undef, "Open git-ls-tree failed.");
1372 my (@entries) = map { chomp; $_ } <$fd>;
1373 close $fd or die_error(undef, "Reading tree failed.");
1379 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1380 $base_key = ";hb=$hash_base";
1381 print "<div class=\"page_nav\">\n" .
1382 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1383 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1384 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash_base")}, "log") .
1385 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash_base")}, "commit") .
1386 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1391 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1394 print "<div class=\"page_nav\">\n";
1395 print "<br/><br/></div>\n";
1396 print "<div class=\"title\">$hash</div>\n";
1398 if (defined $file_name) {
1399 $base = "$file_name/";
1400 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1402 print "<div class=\"page_path\"><b>/</b></div>\n";
1404 print "<div class=\"page_body\">\n";
1405 print "<table cellspacing=\"0\">\n";
1407 foreach my $line (@entries) {
1408 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1409 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1414 $file_key = ";f=$base$t_name";
1416 print "<tr class=\"dark\">\n";
1418 print "<tr class=\"light\">\n";
1421 print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n";
1422 if ($t_type eq "blob") {
1423 print "<td class=\"list\">" .
1424 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key), -class => "list"}, $t_name) .
1426 "<td class=\"link\">" .
1427 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key)}, "blob") .
1428 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=history;h=$hash_base" . $file_key)}, "history") .
1430 } elsif ($t_type eq "tree") {
1431 print "<td class=\"list\">" .
1432 $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key)}, $t_name) .
1434 "<td class=\"link\">" .
1435 $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key)}, "tree") .
1440 print "</table>\n" .
1446 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1447 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
1448 my (@revlist) = map { chomp; $_ } <$fd>;
1449 close $fd or die_error(undef, "Reading rev-list failed.");
1450 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1451 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1452 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1453 print "<channel>\n";
1454 print "<title>$project</title>\n".
1455 "<link>" . esc_html("$my_url?p=$project;a=summary") . "</link>\n".
1456 "<description>$project log</description>\n".
1457 "<language>en</language>\n";
1459 for (my $i = 0; $i <= $#revlist; $i++) {
1460 my $commit = $revlist[$i];
1461 my %co = git_read_commit($commit);
1462 # we read 150, we always show 30 and the ones more recent than 48 hours
1463 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1466 my %cd = date_str($co{'committer_epoch'});
1467 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1468 my @difftree = map { chomp; $_ } <$fd>;
1472 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
1474 "<author>" . esc_html($co{'author'}) . "</author>\n" .
1475 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1476 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1477 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1478 "<description>" . esc_html($co{'title'}) . "</description>\n" .
1479 "<content:encoded>" .
1481 my $comment = $co{'comment'};
1482 foreach my $line (@$comment) {
1483 $line = decode("utf8", $line, Encode::FB_DEFAULT);
1484 print "$line<br/>\n";
1487 foreach my $line (@difftree) {
1488 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1492 print "$file<br/>\n";
1495 "</content:encoded>\n" .
1498 print "</channel></rss>";
1502 my @list = git_read_projects();
1504 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1505 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1506 "<opml version=\"1.0\">\n".
1508 " <title>Git OPML Export</title>\n".
1511 "<outline text=\"git RSS feeds\">\n";
1513 foreach my $pr (@list) {
1515 my $head = git_read_hash("$proj{'path'}/HEAD");
1516 if (!defined $head) {
1519 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1520 my %co = git_read_commit($head);
1525 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
1526 my $rss = "$my_url?p=$proj{'path'};a=rss";
1527 my $html = "$my_url?p=$proj{'path'};a=summary";
1528 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1530 print "</outline>\n".
1536 my $head = git_read_hash("$project/HEAD");
1537 if (!defined $hash) {
1540 if (!defined $page) {
1544 print "<div class=\"page_nav\">\n";
1545 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1546 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash")}, "shortlog") .
1548 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
1549 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1550 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1552 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1553 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1554 my (@revlist) = map { chomp; $_ } <$fd>;
1557 if ($hash ne $head || $page) {
1558 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "HEAD");
1564 $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
1566 print " ⋅ prev";
1568 if ($#revlist >= (100 * ($page+1)-1)) {
1570 $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
1572 print " ⋅ next";
1578 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary"), -class => "title"}, " ") .
1580 my %co = git_read_commit($hash);
1581 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1583 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1584 my $commit = $revlist[$i];
1585 my %co = git_read_commit($commit);
1587 my %ad = date_str($co{'author_epoch'});
1589 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit"), -class => "title"},
1590 "<span class=\"age\">$co{'age_string'}</span>" . esc_html($co{'title'})) . "\n" .
1592 print "<div class=\"title_text\">\n" .
1593 "<div class=\"log_link\">\n" .
1594 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit")}, "commit") .
1595 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1598 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1600 "<div class=\"log_body\">\n";
1601 my $comment = $co{'comment'};
1603 foreach my $line (@$comment) {
1604 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1615 print format_log_line_html($line) . "<br/>\n";
1626 my %co = git_read_commit($hash);
1628 die_error(undef, "Unknown commit object.");
1630 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1631 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1635 my $parent = $co{'parent'};
1636 if (!defined $parent) {
1640 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed.");
1641 @difftree = map { chomp; $_ } <$fd>;
1642 close $fd or die_error(undef, "Reading diff-tree failed.");
1644 # non-textual hash id's can be cached
1646 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1649 git_header_html(undef, $expires);
1650 print "<div class=\"page_nav\">\n" .
1651 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1652 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash")}, "shortlog") .
1653 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash")}, "log") .
1655 if (defined $co{'parent'}) {
1656 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1658 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1659 "<br/><br/></div>\n";
1660 if (defined $co{'parent'}) {
1662 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1666 $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1669 print "<div class=\"title_text\">\n" .
1670 "<table cellspacing=\"0\">\n";
1671 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
1673 "<td></td><td> $ad{'rfc2822'}";
1674 if ($ad{'hour_local'} < 6) {
1675 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1677 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1681 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
1682 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1683 print "<tr><td>commit</td><td style=\"font-family:monospace\">$co{'id'}</td></tr>\n";
1686 "<td style=\"font-family:monospace\">" .
1687 $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1689 "<td class=\"link\">" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1692 my $parents = $co{'parents'};
1693 foreach my $par (@$parents) {
1696 "<td style=\"font-family:monospace\">" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1697 "<td class=\"link\">" .
1698 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$par")}, "commit") .
1699 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1705 print "<div class=\"page_body\">\n";
1706 my $comment = $co{'comment'};
1709 foreach my $line (@$comment) {
1710 # print only one empty line
1712 if ($empty || $signed) {
1719 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1721 print "<span style=\"color: #888888\">" . esc_html($line) . "</span><br/>\n";
1724 print format_log_line_html($line) . "<br/>\n";
1728 print "<div class=\"list_head\">\n";
1729 if ($#difftree > 10) {
1730 print(($#difftree + 1) . " files changed:\n");
1733 print "<table cellspacing=\"0\">\n";
1735 foreach my $line (@difftree) {
1736 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1737 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1738 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1746 my $similarity = $6;
1749 print "<tr class=\"dark\">\n";
1751 print "<tr class=\"light\">\n";
1754 if ($status eq "A") {
1756 if (S_ISREG(oct $to_mode)) {
1757 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1760 $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" .
1761 "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1762 "<td class=\"link\">" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
1763 } elsif ($status eq "D") {
1765 $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" .
1766 "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1767 "<td class=\"link\">" .
1768 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
1769 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=history;h=$hash;f=$file")}, "history") .
1771 } elsif ($status eq "M" || $status eq "T") {
1772 my $mode_chnge = "";
1773 if ($from_mode != $to_mode) {
1774 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1775 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1776 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1778 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1779 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1780 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1781 } elsif (S_ISREG($to_mode)) {
1782 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1785 $mode_chnge .= "]</span>\n";
1788 if ($to_id ne $from_id) {
1789 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));
1791 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
1794 "<td>$mode_chnge</td>\n" .
1795 "<td class=\"link\">";
1796 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
1797 if ($to_id ne $from_id) {
1798 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
1800 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
1802 } elsif ($status eq "R") {
1803 my ($from_file, $to_file) = split "\t", $file;
1805 if ($from_mode != $to_mode) {
1806 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1809 $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" .
1810 "<td><span style=\"color: #777777;\">[moved from " .
1811 $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)) .
1812 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1813 "<td class=\"link\">" .
1814 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
1815 if ($to_id ne $from_id) {
1816 print " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
1827 mkdir($git_temp, 0700);
1829 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1830 print "<div class=\"page_nav\">\n" .
1831 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1832 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1833 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
1834 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash_base")}, "commit") .
1835 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1836 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
1838 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
1841 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1844 print "<div class=\"page_nav\">\n" .
1845 "<br/><br/></div>\n" .
1846 "<div class=\"title\">$hash vs $hash_parent</div>\n";
1848 if (defined $file_name) {
1849 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1851 print "<div class=\"page_body\">\n" .
1852 "<div class=\"diff_info\">blob:" .
1853 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
1855 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
1857 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
1862 sub git_blobdiff_plain {
1863 mkdir($git_temp, 0700);
1864 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1865 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
1868 sub git_commitdiff {
1869 mkdir($git_temp, 0700);
1870 my %co = git_read_commit($hash);
1872 die_error(undef, "Unknown commit object.");
1874 if (!defined $hash_parent) {
1875 $hash_parent = $co{'parent'};
1877 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1878 my (@difftree) = map { chomp; $_ } <$fd>;
1879 close $fd or die_error(undef, "Reading diff-tree failed.");
1881 # non-textual hash id's can be cached
1883 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1886 git_header_html(undef, $expires);
1887 print "<div class=\"page_nav\">\n" .
1888 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
1889 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash")}, "shortlog") .
1890 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash")}, "log") .
1891 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
1893 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
1894 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
1897 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1899 print "<div class=\"page_body\">\n";
1900 my $comment = $co{'comment'};
1903 my @log = @$comment;
1904 # remove first and empty lines after that
1906 while (defined $log[0] && $log[0] eq "") {
1909 foreach my $line (@log) {
1910 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1921 print format_log_line_html($line) . "<br/>\n";
1924 foreach my $line (@difftree) {
1925 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1926 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1927 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1934 if ($status eq "A") {
1935 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
1936 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
1938 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
1939 } elsif ($status eq "D") {
1940 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
1941 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
1943 git_diff_print($from_id, "a/$file", undef, "/dev/null");
1944 } elsif ($status eq "M") {
1945 if ($from_id ne $to_id) {
1946 print "<div class=\"diff_info\">" .
1947 file_type($from_mode) . ":" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
1949 file_type($to_mode) . ":" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
1951 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
1960 sub git_commitdiff_plain {
1961 mkdir($git_temp, 0700);
1962 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1963 my (@difftree) = map { chomp; $_ } <$fd>;
1964 close $fd or die_error(undef, "Reading diff-tree failed.");
1966 # try to figure out the next tag after this commit
1969 my $tags = git_read_refs("refs/tags");
1970 foreach my $entry (@$tags) {
1972 $taghash{$tag{'refid'}} = $tag{'name'};
1974 open $fd, "-|", "$gitbin/git-rev-list HEAD";
1975 while (my $commit = <$fd>) {
1977 if ($taghash{$commit}) {
1978 $tagname = $taghash{$commit};
1980 if ($commit eq $hash) {
1986 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
1987 my %co = git_read_commit($hash);
1988 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1989 my $comment = $co{'comment'};
1990 print "From: $co{'author'}\n" .
1991 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
1992 "Subject: $co{'title'}\n";
1993 if (defined $tagname) {
1994 print "X-Git-Tag: $tagname\n";
1996 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
1999 foreach my $line (@$comment) {;
2004 foreach my $line (@difftree) {
2005 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2010 if ($status eq "A") {
2011 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
2012 } elsif ($status eq "D") {
2013 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
2014 } elsif ($status eq "M") {
2015 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
2021 if (!defined $hash) {
2022 $hash = git_read_hash("$project/HEAD");
2024 my %co = git_read_commit($hash);
2026 die_error(undef, "Unknown commit object.");
2029 print "<div class=\"page_nav\">\n" .
2030 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
2031 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
2032 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log")}, "log") .
2033 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
2034 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2035 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2039 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2041 print "<div class=\"page_path\"><b>/$file_name</b><br/></div>\n";
2043 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin \'$file_name\'";
2045 print "<table cellspacing=\"0\">\n";
2047 while (my $line = <$fd>) {
2048 if ($line =~ m/^([0-9a-fA-F]{40})/){
2052 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2053 my %co = git_read_commit($commit);
2058 print "<tr class=\"dark\">\n";
2060 print "<tr class=\"light\">\n";
2063 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2064 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2065 "<td>" . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2066 esc_html(chop_str($co{'title'}, 50)) . "</b>") . "</td>\n" .
2067 "<td class=\"link\">" .
2068 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit")}, "commit") .
2069 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2070 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2071 my $blob = git_get_hash_by_path($hash, $file_name);
2072 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2073 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2075 $cgi->a({-href => esc_url("$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2089 if (!defined $searchtext) {
2090 die_error("", "Text field empty.");
2092 if (!defined $hash) {
2093 $hash = git_read_hash("$project/HEAD");
2095 my %co = git_read_commit($hash);
2097 die_error(undef, "Unknown commit object.");
2099 # pickaxe may take all resources of your box and run for several minutes
2100 # with every query - so decide by yourself how public you make this feature :)
2101 my $commit_search = 1;
2102 my $author_search = 0;
2103 my $committer_search = 0;
2104 my $pickaxe_search = 0;
2105 if ($searchtext =~ s/^author\\://i) {
2107 } elsif ($searchtext =~ s/^committer\\://i) {
2108 $committer_search = 1;
2109 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2111 $pickaxe_search = 1;
2114 print "<div class=\"page_nav\">\n" .
2115 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary;h=$hash")}, "summary") .
2116 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "shortlog") .
2117 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash")}, "log") .
2118 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
2119 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2120 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2125 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2127 print "<table cellspacing=\"0\">\n";
2129 if ($commit_search) {
2131 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2132 while (my $commit_text = <$fd>) {
2133 if (!grep m/$searchtext/i, $commit_text) {
2136 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2139 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2142 my @commit_lines = split "\n", $commit_text;
2143 my %co = git_read_commit(undef, \@commit_lines);
2148 print "<tr class=\"dark\">\n";
2150 print "<tr class=\"light\">\n";
2153 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2154 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2156 $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/>");
2157 my $comment = $co{'comment'};
2158 foreach my $line (@$comment) {
2159 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2160 my $lead = esc_html($1) || "";
2161 $lead = chop_str($lead, 30, 10);
2162 my $match = esc_html($2) || "";
2163 my $trail = esc_html($3) || "";
2164 $trail = chop_str($trail, 30, 10);
2165 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
2166 print chop_str($text, 80, 5) . "<br/>\n";
2170 "<td class=\"link\">" .
2171 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$co{'id'}")}, "commit") .
2172 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2179 if ($pickaxe_search) {
2181 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2184 while (my $line = <$fd>) {
2185 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2188 $set{'from_id'} = $3;
2190 $set{'id'} = $set{'to_id'};
2191 if ($set{'id'} =~ m/0{40}/) {
2192 $set{'id'} = $set{'from_id'};
2194 if ($set{'id'} =~ m/0{40}/) {
2198 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2201 print "<tr class=\"dark\">\n";
2203 print "<tr class=\"light\">\n";
2206 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2207 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2209 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2210 esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2211 while (my $setref = shift @files) {
2213 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2214 "<span style=\"color:#e00000\">" . esc_html($set{'file'}) . "</span>") .
2218 "<td class=\"link\">" .
2219 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$co{'id'}")}, "commit") .
2220 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2224 %co = git_read_commit($1);
2234 my $head = git_read_hash("$project/HEAD");
2235 if (!defined $hash) {
2238 if (!defined $page) {
2242 print "<div class=\"page_nav\">\n" .
2243 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary")}, "summary") .
2245 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=log;h=$hash")}, "log") .
2246 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
2247 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2248 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2250 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2251 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
2252 my (@revlist) = map { chomp; $_ } <$fd>;
2255 if ($hash ne $head || $page) {
2256 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog")}, "HEAD");
2262 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
2264 print " ⋅ prev";
2266 if ($#revlist >= (100 * ($page+1)-1)) {
2268 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
2270 print " ⋅ next";
2275 $cgi->a({-href => esc_url("$my_uri?p=$project;a=summary"), -class => "title"}, " ") .
2277 print "<table cellspacing=\"0\">\n";
2279 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2280 my $commit = $revlist[$i];
2281 my %co = git_read_commit($commit);
2282 my %ad = date_str($co{'author_epoch'});
2284 print "<tr class=\"dark\">\n";
2286 print "<tr class=\"light\">\n";
2289 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2290 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2292 if (length($co{'title_short'}) < length($co{'title'})) {
2293 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
2294 "<b>" . esc_html($co{'title_short'}) . "</b>");
2296 print $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit"), -class => "list"},
2297 "<b>" . esc_html($co{'title_short'}) . "</b>");
2300 "<td class=\"link\">" .
2301 $cgi->a({-href => esc_url("$my_uri?p=$project;a=commit;h=$commit")}, "commit") .
2302 " | " . $cgi->a({-href => esc_url("$my_uri?p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2306 if ($#revlist >= (100 * ($page+1)-1)) {
2309 $cgi->a({-href => esc_url("$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title => "Alt-n"}, "next") .