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);
19 my $my_url = $cgi->url();
20 my $my_uri = $cgi->url(-absolute => 1);
23 # absolute fs-path which will be prepended to the project path
24 #my $projectroot = "/pub/scm";
25 my $projectroot = "/home/kay/public_html/pub/scm";
27 # location of the git-core binaries
28 my $gitbin = "/usr/bin";
30 # location for temporary files needed for diffs
31 my $git_temp = "/tmp/gitweb";
33 # target of the home link on top of all pages
34 my $home_link = $my_uri;
36 # html text to include at home page
37 my $home_text = "indextext.html";
39 # source of projects list
40 #my $projects_list = $projectroot;
41 my $projects_list = "index/index.aux";
43 # input validation and dispatch
44 my $action = $cgi->param('a');
45 if (defined $action) {
46 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
48 die_error(undef, "Invalid action parameter.");
50 if ($action eq "git-logo.png") {
53 } elsif ($action eq "opml") {
59 my $order = $cgi->param('o');
61 if ($order =~ m/[^0-9a-zA-Z_]/) {
63 die_error(undef, "Invalid order parameter.");
67 my $project = $cgi->param('p');
68 if (defined $project) {
69 $project = validate_input($project);
70 if (!defined($project)) {
71 die_error(undef, "Invalid project parameter.");
73 if (!(-d "$projectroot/$project")) {
75 die_error(undef, "No such directory.");
77 if (!(-e "$projectroot/$project/HEAD")) {
79 die_error(undef, "No such project.");
81 $rss_link = "<link rel=\"alternate\" title=\"" . esc($project) . " log\" href=\"" .
82 esc("$my_uri?p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
83 $ENV{'GIT_DIR'} = "$projectroot/$project";
89 my $file_name = $cgi->param('f');
90 if (defined $file_name) {
91 $file_name = validate_input($file_name);
92 if (!defined($file_name)) {
93 die_error(undef, "Invalid file parameter.");
97 my $hash = $cgi->param('h');
99 $hash = validate_input($hash);
100 if (!defined($hash)) {
101 die_error(undef, "Invalid hash parameter.");
105 my $hash_parent = $cgi->param('hp');
106 if (defined $hash_parent) {
107 $hash_parent = validate_input($hash_parent);
108 if (!defined($hash_parent)) {
109 die_error(undef, "Invalid hash parent parameter.");
113 my $hash_base = $cgi->param('hb');
114 if (defined $hash_base) {
115 $hash_base = validate_input($hash_base);
116 if (!defined($hash_base)) {
117 die_error(undef, "Invalid hash base parameter.");
121 my $page = $cgi->param('pg');
123 if ($page =~ m/[^0-9]$/) {
125 die_error(undef, "Invalid page parameter.");
129 my $searchtext = $cgi->param('s');
130 if (defined $searchtext) {
131 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
133 die_error(undef, "Invalid search parameter.");
135 $searchtext = quotemeta $searchtext;
141 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
144 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
147 if ($input =~ m/[^a-zA-Z0-9_ \.\/\-\+\#\~]/) {
153 if (!defined $action || $action eq "summary") {
156 } elsif ($action eq "heads") {
159 } elsif ($action eq "tags") {
162 } elsif ($action eq "blob") {
165 } elsif ($action eq "blob_plain") {
168 } elsif ($action eq "tree") {
171 } elsif ($action eq "rss") {
174 } elsif ($action eq "commit") {
177 } elsif ($action eq "log") {
180 } elsif ($action eq "blobdiff") {
183 } elsif ($action eq "blobdiff_plain") {
184 git_blobdiff_plain();
186 } elsif ($action eq "commitdiff") {
189 } elsif ($action eq "commitdiff_plain") {
190 git_commitdiff_plain();
192 } elsif ($action eq "history") {
195 } elsif ($action eq "search") {
198 } elsif ($action eq "shortlog") {
201 } elsif ($action eq "tag") {
206 die_error(undef, "Unknown action.");
217 sub git_header_html {
218 my $status = shift || "200 OK";
222 if (defined $project) {
223 $title .= " - $project";
224 if (defined $action) {
225 $title .= "/$action";
228 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires);
230 <?xml version="1.0" encoding="utf-8"?>
231 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
232 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
233 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
235 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
236 <meta name="robots" content="index, nofollow"/>
237 <title>$title</title>
239 <style type="text/css">
240 body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
242 a:hover, a:visited, a:active { color:#880000; }
243 div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; }
244 div.page_header a:visited, a.header { color:#0000cc; }
245 div.page_header a:hover { color:#880000; }
246 div.page_nav { padding:8px; }
247 div.page_nav a:visited { color:#0000cc; }
248 div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
249 div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
250 div.page_footer_text { float:left; color:#555555; font-style:italic; }
251 div.page_body { padding:8px; }
253 display:block; padding:6px 8px;
254 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
256 a.title:hover { background-color: #d9d8d1; }
257 div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; }
258 div.log_body { padding:8px 8px 8px 150px; }
259 span.age { position:relative; float:left; width:142px; font-style:italic; }
262 font-size:10px; font-family:sans-serif; font-style:normal;
263 position:relative; float:left; width:136px;
265 div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; }
266 a.list { text-decoration:none; color:#000000; }
267 a.list:hover { text-decoration:underline; color:#880000; }
268 a.text { text-decoration:none; color:#0000cc; }
269 a.text:visited { text-decoration:none; color:#880000; }
270 a.text:hover { text-decoration:underline; color:#880000; }
271 table { padding:8px 4px; }
272 th { padding:2px 5px; font-size:12px; text-align:left; }
273 tr.light:hover { background-color:#edece6; }
274 tr.dark { background-color:#f6f6f0; }
275 tr.dark:hover { background-color:#edece6; }
276 td { padding:2px 5px; font-size:12px; vertical-align:top; }
277 td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; }
278 div.pre { font-family:monospace; font-size:12px; white-space:pre; }
279 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
280 div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
281 div.search { margin:4px 8px; position:absolute; top:56px; right:12px }
282 a.linenr { color:#999999; text-decoration:none }
284 float:right; padding:3px 0px; width:35px; line-height:10px;
285 border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
286 color:#ffffff; background-color:#ff6600;
287 font-weight:bold; font-family:sans-serif; font-size:10px;
288 text-align:center; text-decoration:none;
290 a.rss_logo:hover { background-color:#ee5500; }
295 print "<div class=\"page_header\">\n" .
296 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
297 "<img src=\"" . esc("$my_uri?a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
299 print $cgi->a({-href => esc($home_link)}, "projects") . " / ";
300 if (defined $project) {
301 print $cgi->a({-href => esc("$my_uri?p=$project;a=summary")}, escapeHTML($project));
302 if (defined $action) {
306 if (!defined $searchtext) {
311 $search_hash = $hash;
313 $search_hash = "HEAD";
315 $cgi->param("a", "search");
316 $cgi->param("h", $search_hash);
317 print $cgi->startform(-method => "get", -action => $my_uri) .
318 "<div class=\"search\">\n" .
319 $cgi->hidden(-name => "p") . "\n" .
320 $cgi->hidden(-name => "a") . "\n" .
321 $cgi->hidden(-name => "h") . "\n" .
322 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
324 $cgi->end_form() . "\n";
329 sub git_footer_html {
330 print "<div class=\"page_footer\">\n";
331 if (defined $project) {
332 my $descr = git_read_description($project);
333 if (defined $descr) {
334 print "<div class=\"page_footer_text\">" . escapeHTML($descr) . "</div>\n";
336 print $cgi->a({-href => esc("$my_uri?p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
338 print $cgi->a({-href => esc("$my_uri?a=opml"), -class => "rss_logo"}, "OPML") . "\n";
346 my $status = shift || "403 Forbidden";
347 my $error = shift || "Malformed query, file missing or permission denied";
349 git_header_html($status);
350 print "<div class=\"page_body\">\n" .
352 "$status - $error\n" .
362 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
372 open my $fd, "$projectroot/$path" or return undef;
376 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
381 sub git_read_description {
384 open my $fd, "$projectroot/$path/description" or return undef;
396 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
397 $tag{'id'} = $tag_id;
398 while (my $line = <$fd>) {
400 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
402 } elsif ($line =~ m/^type (.+)$/) {
404 } elsif ($line =~ m/^tag (.+)$/) {
406 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
410 } elsif ($line =~ m/--BEGIN/) {
411 push @comment, $line;
413 } elsif ($line eq "") {
417 push @comment, <$fd>;
418 $tag{'comment'} = \@comment;
420 if (!defined $tag{'name'}) {
430 if ($age > 60*60*24*365*2) {
431 $age_str = (int $age/60/60/24/365);
432 $age_str .= " years ago";
433 } elsif ($age > 60*60*24*(365/12)*2) {
434 $age_str = int $age/60/60/24/(365/12);
435 $age_str .= " months ago";
436 } elsif ($age > 60*60*24*7*2) {
437 $age_str = int $age/60/60/24/7;
438 $age_str .= " weeks ago";
439 } elsif ($age > 60*60*24*2) {
440 $age_str = int $age/60/60/24;
441 $age_str .= " days ago";
442 } elsif ($age > 60*60*2) {
443 $age_str = int $age/60/60;
444 $age_str .= " hours ago";
445 } elsif ($age > 60*2) {
446 $age_str = int $age/60;
447 $age_str .= " min ago";
450 $age_str .= " sec ago";
452 $age_str .= " right now";
457 sub git_read_commit {
458 my $commit_id = shift;
459 my $commit_text = shift;
464 if (defined $commit_text) {
465 @commit_lines = @$commit_text;
468 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
469 @commit_lines = split '\n', <$fd>;
474 my $header = shift @commit_lines;
475 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
478 ($co{'id'}, my @parents) = split ' ', $header;
479 $co{'parents'} = \@parents;
480 $co{'parent'} = $parents[0];
481 while (my $line = shift @commit_lines) {
482 last if $line eq "\n";
483 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
485 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
487 $co{'author_epoch'} = $2;
488 $co{'author_tz'} = $3;
489 if ($co{'author'} =~ m/^([^<]+) </) {
490 $co{'author_name'} = $1;
492 $co{'author_name'} = $co{'author'};
494 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
495 $co{'committer'} = $1;
496 $co{'committer_epoch'} = $2;
497 $co{'committer_tz'} = $3;
498 $co{'committer_name'} = $co{'committer'};
499 $co{'committer_name'} =~ s/ <.*//;
502 if (!defined $co{'tree'}) {
506 foreach my $title (@commit_lines) {
508 $co{'title'} = chop_str($title, 80, 5);
509 # remove leading stuff of merges to make the interesting part visible
510 if (length($title) > 50) {
511 $title =~ s/^Automatic //;
512 $title =~ s/^merge (of|with) /Merge ... /i;
513 if (length($title) > 50) {
514 $title =~ s/(http|rsync):\/\///;
516 if (length($title) > 50) {
517 $title =~ s/(master|www|rsync)\.//;
519 if (length($title) > 50) {
520 $title =~ s/kernel.org:?//;
522 if (length($title) > 50) {
523 $title =~ s/\/pub\/scm//;
526 $co{'title_short'} = chop_str($title, 50, 5);
530 # remove added spaces
531 foreach my $line (@commit_lines) {
534 $co{'comment'} = \@commit_lines;
536 my $age = time - $co{'committer_epoch'};
538 $co{'age_string'} = age_string($age);
539 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
540 if ($age > 60*60*24*7*2) {
541 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
542 $co{'age_string_age'} = $co{'age_string'};
544 $co{'age_string_date'} = $co{'age_string'};
545 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
552 my $from_name = shift;
555 my $format = shift || "html";
557 my $from_tmp = "/dev/null";
558 my $to_tmp = "/dev/null";
561 # create tmp from-file
563 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
564 open my $fd2, "> $from_tmp";
565 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
574 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
575 open my $fd2, "> $to_tmp";
576 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
583 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
584 if ($format eq "plain") {
589 while (my $line = <$fd>) {
591 my $char = substr($line, 0, 1);
594 $color = " style=\"color:#008800;\"";
595 } elsif ($char eq "-") {
596 $color = " style=\"color:#cc0000;\"";
597 } elsif ($char eq "@") {
598 $color = " style=\"color:#990099;\"";
599 } elsif ($char eq "\\") {
603 while ((my $pos = index($line, "\t")) != -1) {
604 if (my $count = (8 - (($pos-1) % 8))) {
605 my $spaces = ' ' x $count;
606 $line =~ s/\t/$spaces/;
609 print "<div class=\"pre\"$color>" . escapeHTML($line) . "</div>\n";
623 my $mode = oct shift;
625 if (S_ISDIR($mode & S_IFMT)) {
627 } elsif (S_ISLNK($mode)) {
629 } elsif (S_ISREG($mode)) {
630 # git cares only about the executable bit
631 if ($mode & S_IXUSR) {
644 my $add_len = shift || 10;
646 # allow only $len chars, but don't cut a word if it would fit in $add_len
647 # if it doesn't fit, cut it if it's still longer than the dots we would add
648 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
651 if (length($tail) > 4) {
658 my $mode = oct shift;
660 if (S_ISDIR($mode & S_IFMT)) {
662 } elsif (S_ISLNK($mode)) {
664 } elsif (S_ISREG($mode)) {
671 sub format_log_line_html {
674 $line = escapeHTML($line);
675 $line =~ s/ / /g;
676 if ($line =~ m/([0-9a-fA-F]{40})/) {
678 if (git_get_type($hash_text) eq "commit") {
679 my $link = $cgi->a({-class => "text", -href => esc("$my_uri?p=$project;a=commit;h=$hash_text")}, $hash_text);
680 $line =~ s/$hash_text/$link/;
688 my $tz = shift || "-0000";
691 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
692 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
693 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
694 $date{'hour'} = $hour;
695 $date{'minute'} = $min;
696 $date{'mday'} = $mday;
697 $date{'day'} = $days[$wday];
698 $date{'month'} = $months[$mon];
699 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
700 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
702 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
703 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
704 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
705 $date{'hour_local'} = $hour;
706 $date{'minute_local'} = $min;
707 $date{'tz_local'} = $tz;
711 # git-logo (cached in browser for one day)
713 print $cgi->header(-type => 'image/png', -expires => '+1d');
714 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
715 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
716 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
717 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
718 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
719 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
720 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
721 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
722 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
723 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
724 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
725 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
726 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
727 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
733 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
734 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
735 if (!defined $gcos) {
739 $owner =~ s/[,;].*$//;
743 sub git_read_projects {
746 if (-d $projects_list) {
747 # search in directory
748 my $dir = $projects_list;
749 opendir my $dh, $dir or return undef;
750 while (my $dir = readdir($dh)) {
751 if (-e "$projectroot/$dir/HEAD") {
759 } elsif (-f $projects_list) {
760 # read from file(url-encoded):
761 # 'git%2Fgit.git Linus+Torvalds'
762 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
763 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
764 open my $fd , $projects_list or return undef;
765 while (my $line = <$fd>) {
767 my ($path, $owner) = split ' ', $line;
768 $path = unescape($path);
769 $owner = unescape($owner);
770 if (!defined $path) {
773 if (-e "$projectroot/$path/HEAD") {
783 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
787 sub git_project_list {
788 my @list = git_read_projects();
791 die_error(undef, "No project found.");
793 foreach my $pr (@list) {
794 my $head = git_read_hash("$pr->{'path'}/HEAD");
795 if (!defined $head) {
798 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
799 my %co = git_read_commit($head);
803 $pr->{'commit'} = \%co;
804 if (!defined $pr->{'descr'}) {
805 my $descr = git_read_description($pr->{'path'}) || "";
806 $pr->{'descr'} = chop_str($descr, 25, 5);
808 if (!defined $pr->{'owner'}) {
809 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
815 print "<div class=\"index_include\">\n";
816 open (my $fd, $home_text);
821 print "<table cellspacing=\"0\">\n" .
823 if (!defined($order) || (defined($order) && ($order eq "project"))) {
824 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
825 print "<th>Project</th>\n";
827 print "<th>" . $cgi->a({-class => "header", -href => esc("$my_uri?o=project")}, "Project") . "</th>\n";
829 if (defined($order) && ($order eq "descr")) {
830 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
831 print "<th>Description</th>\n";
833 print "<th>" . $cgi->a({-class => "header", -href => esc("$my_uri?o=descr")}, "Description") . "</th>\n";
835 if (defined($order) && ($order eq "owner")) {
836 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
837 print "<th>Owner</th>\n";
839 print "<th>" . $cgi->a({-class => "header", -href => esc("$my_uri?o=owner")}, "Owner") . "</th>\n";
841 if (defined($order) && ($order eq "age")) {
842 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
843 print "<th>Last Change</th>\n";
845 print "<th>" . $cgi->a({-class => "header", -href => esc("$my_uri?o=age")}, "Last Change") . "</th>\n";
847 print "<th></th>\n" .
850 foreach my $pr (@projects) {
852 print "<tr class=\"dark\">\n";
854 print "<tr class=\"light\">\n";
857 print "<td>" . $cgi->a({-href => esc("$my_uri?p=$pr->{'path'};a=summary"), -class => "list"}, escapeHTML($pr->{'path'})) . "</td>\n" .
858 "<td>$pr->{'descr'}</td>\n" .
859 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
861 if ($pr->{'commit'}{'age'} < 60*60*2) {
862 $colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>";
863 } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {
864 $colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>";
866 $colored_age = "<i>$pr->{'commit'}{'age_string'}</i>";
868 print "<td>$colored_age</td>\n" .
869 "<td class=\"link\">" .
870 $cgi->a({-href => esc("$my_uri?p=$pr->{'path'};a=summary")}, "summary") .
871 " | " . $cgi->a({-href => esc("$my_uri?p=$pr->{'path'};a=shortlog")}, "shortlog") .
872 " | " . $cgi->a({-href => esc("$my_uri?p=$pr->{'path'};a=log")}, "log") .
885 opendir my $dh, "$projectroot/$project/$ref_dir";
886 while (my $dir = readdir($dh)) {
887 if ($dir =~ m/^\./) {
890 if (-d "$projectroot/$project/$ref_dir/$dir") {
891 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
892 my @subdirs = grep !m/^\./, readdir $dh2;
894 foreach my $subdir (@subdirs) {
895 push @refs, "$dir/$subdir"
902 foreach my $ref_file (@refs) {
903 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
904 my $type = git_get_type($ref_id) || next;
907 $ref_item{'type'} = $type;
908 $ref_item{'id'} = $ref_id;
909 $ref_item{'epoch'} = 0;
910 $ref_item{'age'} = "unknown";
911 if ($type eq "tag") {
912 my %tag = git_read_tag($ref_id);
913 $ref_item{'comment'} = $tag{'comment'};
914 if ($tag{'type'} eq "commit") {
915 %co = git_read_commit($tag{'object'});
916 $ref_item{'epoch'} = $co{'committer_epoch'};
917 $ref_item{'age'} = $co{'age_string'};
918 } elsif (defined($tag{'epoch'})) {
919 my $age = time - $tag{'epoch'};
920 $ref_item{'epoch'} = $tag{'epoch'};
921 $ref_item{'age'} = age_string($age);
923 $ref_item{'reftype'} = $tag{'type'};
924 $ref_item{'name'} = $tag{'name'};
925 $ref_item{'refid'} = $tag{'object'};
926 } elsif ($type eq "commit"){
927 %co = git_read_commit($ref_id);
928 $ref_item{'reftype'} = "commit";
929 $ref_item{'name'} = $ref_file;
930 $ref_item{'title'} = $co{'title'};
931 $ref_item{'refid'} = $ref_id;
932 $ref_item{'epoch'} = $co{'committer_epoch'};
933 $ref_item{'age'} = $co{'age_string'};
936 push @reflist, \%ref_item;
939 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
944 my $descr = git_read_description($project) || "none";
945 my $head = git_read_hash("$project/HEAD");
946 my %co = git_read_commit($head);
947 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
950 if (-f $projects_list) {
951 open (my $fd , $projects_list);
952 while (my $line = <$fd>) {
954 my ($pr, $ow) = split ' ', $line;
957 if ($pr eq $project) {
964 if (!defined $owner) {
965 $owner = get_file_owner("$projectroot/$project");
969 print "<div class=\"page_nav\">\n" .
971 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog")}, "shortlog") .
972 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log")}, "log") .
973 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$head")}, "commit") .
974 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$head")}, "commitdiff") .
975 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree")}, "tree") .
978 print "<div class=\"title\"> </div>\n";
979 print "<table cellspacing=\"0\">\n" .
980 "<tr><td>description</td><td>" . escapeHTML($descr) . "</td></tr>\n" .
981 "<tr><td>owner</td><td>$owner</td></tr>\n" .
982 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
984 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
985 my (@revlist) = map { chomp; $_ } <$fd>;
988 $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog"), -class => "title"}, "shortlog") .
991 print "<table cellspacing=\"0\">\n";
993 foreach my $commit (@revlist) {
994 my %co = git_read_commit($commit);
995 my %ad = date_str($co{'author_epoch'});
997 print "<tr class=\"dark\">\n";
999 print "<tr class=\"light\">\n";
1003 print "<td><i>$co{'age_string'}</i></td>\n" .
1004 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1006 if (length($co{'title_short'}) < length($co{'title'})) {
1007 print $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
1008 "<b>" . escapeHTML($co{'title_short'}) . "</b>");
1010 print $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$commit"), -class => "list"},
1011 "<b>" . escapeHTML($co{'title'}) . "</b>");
1014 "<td class=\"link\">" .
1015 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$commit")}, "commit") .
1016 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1020 print "<td>" . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog")}, "...") . "</td>\n" .
1027 my $taglist = git_read_refs("refs/tags");
1028 if (defined @$taglist) {
1030 $cgi->a({-href => esc("$my_uri?p=$project;a=tags"), -class => "title"}, "tags") .
1033 print "<table cellspacing=\"0\">\n";
1035 foreach my $entry (@$taglist) {
1037 my $comment_lines = $tag{'comment'};
1038 my $comment = shift @$comment_lines;
1039 if (defined($comment)) {
1040 $comment = chop_str($comment, 30, 5);
1043 print "<tr class=\"dark\">\n";
1045 print "<tr class=\"light\">\n";
1049 print "<td><i>$tag{'age'}</i></td>\n" .
1051 $cgi->a({-href => esc("$my_uri?p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1052 "<b>" . escapeHTML($tag{'name'}) . "</b>") .
1055 if (defined($comment)) {
1056 print $cgi->a({-class => "list", -href => esc("$my_uri?p=$project;a=tag;h=$tag{'id'}")}, $comment);
1059 "<td class=\"link\">";
1060 if ($tag{'type'} eq "tag") {
1061 print $cgi->a({-href => esc("$my_uri?p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1063 print $cgi->a({-href => esc("$my_uri?p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1064 if ($tag{'reftype'} eq "commit") {
1065 print " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1066 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log;h=$tag{'refid'}")}, "log");
1071 print "<td>" . $cgi->a({-href => esc("$my_uri?p=$project;a=tags")}, "...") . "</td>\n" .
1079 my $headlist = git_read_refs("refs/heads");
1080 if (defined @$headlist) {
1082 $cgi->a({-href => esc("$my_uri?p=$project;a=heads"), -class => "title"}, "heads") .
1085 print "<table cellspacing=\"0\">\n";
1087 foreach my $entry (@$headlist) {
1090 print "<tr class=\"dark\">\n";
1092 print "<tr class=\"light\">\n";
1096 print "<td><i>$tag{'age'}</i></td>\n" .
1098 $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1099 "<b>" . escapeHTML($tag{'name'}) . "</b>") .
1101 "<td class=\"link\">" .
1102 $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1103 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log;h=$tag{'name'}")}, "log") .
1107 print "<td>" . $cgi->a({-href => esc("$my_uri?p=$project;a=heads")}, "...") . "</td>\n" .
1118 my $head = git_read_hash("$project/HEAD");
1120 print "<div class=\"page_nav\">\n" .
1121 $cgi->a({-href => esc("$my_uri?p=$project;a=summary")}, "summary") .
1122 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1123 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log")}, "log") .
1124 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$head")}, "commit") .
1125 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1126 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1129 my %tag = git_read_tag($hash);
1131 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash"), -class => "title"}, escapeHTML($tag{'name'})) . "\n" .
1133 print "<div class=\"title_text\">\n" .
1134 "<table cellspacing=\"0\">\n" .
1136 "<td>object</td>\n" .
1137 "<td>" . $cgi->a({-class => "list", -href => esc("$my_uri?p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1138 "<td class=\"link\">" . $cgi->a({-href => esc("$my_uri?p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1140 if (defined($tag{'author'})) {
1141 my %ad = date_str($tag{'epoch'}, $tag{'tz'});
1142 print "<tr><td>author</td><td>" . escapeHTML($tag{'author'}) . "</td></tr>\n";
1143 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1145 print "</table>\n\n" .
1147 print "<div class=\"page_body\">";
1148 my $comment = $tag{'comment'};
1149 foreach my $line (@$comment) {
1150 print escapeHTML($line) . "<br/>\n";
1157 my $head = git_read_hash("$project/HEAD");
1159 print "<div class=\"page_nav\">\n" .
1160 $cgi->a({-href => esc("$my_uri?p=$project;a=summary")}, "summary") .
1161 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1162 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log")}, "log") .
1163 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$head")}, "commit") .
1164 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1165 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1168 my $taglist = git_read_refs("refs/tags");
1170 $cgi->a({-href => esc("$my_uri?p=$project;a=summary"), -class => "title"}, " ") .
1172 print "<table cellspacing=\"0\">\n";
1174 if (defined @$taglist) {
1175 foreach my $entry (@$taglist) {
1177 my $comment_lines = $tag{'comment'};
1178 my $comment = shift @$comment_lines;
1179 if (defined($comment)) {
1180 $comment = chop_str($comment, 30, 5);
1183 print "<tr class=\"dark\">\n";
1185 print "<tr class=\"light\">\n";
1188 print "<td><i>$tag{'age'}</i></td>\n" .
1190 $cgi->a({-href => esc("$my_uri?p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1191 "<b>" . escapeHTML($tag{'name'}) . "</b>") .
1194 if (defined($comment)) {
1195 print $cgi->a({-class => "list", -href => esc("$my_uri?p=$project;a=tag;h=$tag{'id'}")}, $comment);
1198 "<td class=\"link\">";
1199 if ($tag{'type'} eq "tag") {
1200 print $cgi->a({-href => esc("$my_uri?p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1202 print $cgi->a({-href => esc("$my_uri?p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1203 if ($tag{'reftype'} eq "commit") {
1204 print " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1205 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log;h=$tag{'refid'}")}, "log");
1216 my $head = git_read_hash("$project/HEAD");
1218 print "<div class=\"page_nav\">\n" .
1219 $cgi->a({-href => esc("$my_uri?p=$project;a=summary")}, "summary") .
1220 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1221 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log")}, "log") .
1222 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$head")}, "commit") .
1223 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1224 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1227 my $taglist = git_read_refs("refs/heads");
1229 $cgi->a({-href => esc("$my_uri?p=$project;a=summary"), -class => "title"}, " ") .
1231 print "<table cellspacing=\"0\">\n";
1233 if (defined @$taglist) {
1234 foreach my $entry (@$taglist) {
1237 print "<tr class=\"dark\">\n";
1239 print "<tr class=\"light\">\n";
1242 print "<td><i>$tag{'age'}</i></td>\n" .
1244 $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . escapeHTML($tag{'name'}) . "</b>") .
1246 "<td class=\"link\">" .
1247 $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1248 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log;h=$tag{'name'}")}, "log") .
1257 sub git_get_hash_by_path {
1259 my $path = shift || return undef;
1262 my @parts = split '/', $path;
1263 while (my $part = shift @parts) {
1264 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1265 my (@entries) = map { chomp; $_ } <$fd>;
1266 close $fd or return undef;
1267 foreach my $line (@entries) {
1268 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1269 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1274 if ($t_name eq $part) {
1278 if ($t_type eq "tree") {
1288 if (!defined $hash && defined $file_name) {
1289 my $base = $hash_base || git_read_hash("$project/HEAD");
1290 $hash = git_get_hash_by_path($base, $file_name, "blob");
1292 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1294 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1295 print "<div class=\"page_nav\">\n" .
1296 $cgi->a({-href => esc("$my_uri?p=$project;a=summary")}, "summary") .
1297 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1298 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log")}, "log") .
1299 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash_base")}, "commit") .
1300 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1301 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1302 if (defined $file_name) {
1303 print $cgi->a({-href => esc("$my_uri?p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") . "<br/>\n";
1305 print $cgi->a({-href => esc("$my_uri?p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1309 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash_base"), -class => "title"}, escapeHTML($co{'title'})) .
1312 print "<div class=\"page_nav\">\n" .
1313 "<br/><br/></div>\n" .
1314 "<div class=\"title\">$hash</div>\n";
1316 if (defined $file_name) {
1317 print "<div class=\"page_path\"><b>$file_name</b></div>\n";
1319 print "<div class=\"page_body\">\n";
1321 while (my $line = <$fd>) {
1324 while ((my $pos = index($line, "\t")) != -1) {
1325 if (my $count = (8 - ($pos % 8))) {
1326 my $spaces = ' ' x $count;
1327 $line =~ s/\t/$spaces/;
1330 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, escapeHTML($line);
1332 close $fd or print "Reading blob failed.\n";
1337 sub git_blob_plain {
1338 my $save_as = "$hash.txt";
1339 if (defined $file_name) {
1340 $save_as = $file_name;
1342 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"$save_as\"");
1343 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1351 if (!defined $hash) {
1352 $hash = git_read_hash("$project/HEAD");
1353 if (defined $file_name) {
1354 my $base = $hash_base || git_read_hash("$project/HEAD");
1355 $hash = git_get_hash_by_path($base, $file_name, "tree");
1357 if (!defined $hash_base) {
1358 $hash_base = git_read_hash("$project/HEAD");
1361 open my $fd, "-|", "$gitbin/git-ls-tree $hash" or die_error(undef, "Open git-ls-tree failed.");
1362 my (@entries) = map { chomp; $_ } <$fd>;
1363 close $fd or die_error(undef, "Reading tree failed.");
1369 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1370 $base_key = ";hb=$hash_base";
1371 print "<div class=\"page_nav\">\n" .
1372 $cgi->a({-href => esc("$my_uri?p=$project;a=summary")}, "summary") .
1373 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1374 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log;h=$hash_base")}, "log") .
1375 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash_base")}, "commit") .
1376 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1381 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash_base"), -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1384 print "<div class=\"page_nav\">\n";
1385 print "<br/><br/></div>\n";
1386 print "<div class=\"title\">$hash</div>\n";
1388 if (defined $file_name) {
1389 $base = "$file_name/";
1390 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1392 print "<div class=\"page_path\"><b>/</b></div>\n";
1394 print "<div class=\"page_body\">\n";
1395 print "<table cellspacing=\"0\">\n";
1397 foreach my $line (@entries) {
1398 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1399 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1404 $file_key = ";f=$base$t_name";
1406 print "<tr class=\"dark\">\n";
1408 print "<tr class=\"light\">\n";
1411 print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n";
1412 if ($t_type eq "blob") {
1413 print "<td class=\"list\">" .
1414 $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key), -class => "list"}, $t_name) .
1416 "<td class=\"link\">" .
1417 $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key)}, "blob") .
1418 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=history;h=$hash_base" . $file_key)}, "history") .
1420 } elsif ($t_type eq "tree") {
1421 print "<td class=\"list\">" .
1422 $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key)}, $t_name) .
1424 "<td class=\"link\">" .
1425 $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key)}, "tree") .
1430 print "</table>\n" .
1436 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1437 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
1438 my (@revlist) = map { chomp; $_ } <$fd>;
1439 close $fd or die_error(undef, "Reading rev-list failed.");
1440 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1441 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1442 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1443 print "<channel>\n";
1444 print "<title>$project</title>\n".
1445 "<link>" . escapeHTML("$my_url?p=$project;a=summary") . "</link>\n".
1446 "<description>$project log</description>\n".
1447 "<language>en</language>\n";
1449 for (my $i = 0; $i <= $#revlist; $i++) {
1450 my $commit = $revlist[$i];
1451 my %co = git_read_commit($commit);
1452 # we read 150, we always show 30 and the ones more recent than 48 hours
1453 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1456 my %cd = date_str($co{'committer_epoch'});
1457 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1458 my @difftree = map { chomp; $_ } <$fd>;
1462 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . escapeHTML($co{'title'}) .
1464 "<author>" . escapeHTML($co{'author'}) . "</author>\n" .
1465 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1466 "<guid isPermaLink=\"true\">" . escapeHTML("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1467 "<link>" . escapeHTML("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1468 "<description>" . escapeHTML($co{'title'}) . "</description>\n" .
1469 "<content:encoded>" .
1471 my $comment = $co{'comment'};
1472 foreach my $line (@$comment) {
1473 print "$line<br/>\n";
1476 foreach my $line (@difftree) {
1477 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1481 print "$file<br/>\n";
1484 "</content:encoded>\n" .
1487 print "</channel></rss>";
1491 my @list = git_read_projects();
1493 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1494 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1495 "<opml version=\"1.0\">\n".
1497 " <title>Git OPML Export</title>\n".
1500 "<outline text=\"git RSS feeds\">\n";
1502 foreach my $pr (@list) {
1504 my $head = git_read_hash("$proj{'path'}/HEAD");
1505 if (!defined $head) {
1508 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1509 my %co = git_read_commit($head);
1514 my $path = escapeHTML(chop_str($proj{'path'}, 25, 5));
1515 my $rss = "$my_url?p=$proj{'path'};a=rss";
1516 my $html = "$my_url?p=$proj{'path'};a=summary";
1517 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1519 print "</outline>\n".
1525 my $head = git_read_hash("$project/HEAD");
1526 if (!defined $hash) {
1529 if (!defined $page) {
1533 print "<div class=\"page_nav\">\n";
1534 print $cgi->a({-href => esc("$my_uri?p=$project;a=summary")}, "summary") .
1535 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$hash")}, "shortlog") .
1537 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
1538 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1539 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1541 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1542 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1543 my (@revlist) = map { chomp; $_ } <$fd>;
1546 if ($hash ne $head || $page) {
1547 print $cgi->a({-href => esc("$my_uri?p=$project;a=log")}, "HEAD");
1553 $cgi->a({-href => esc("$my_uri?p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
1555 print " ⋅ prev";
1557 if ($#revlist >= (100 * ($page+1)-1)) {
1559 $cgi->a({-href => esc("$my_uri?p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
1561 print " ⋅ next";
1567 $cgi->a({-href => esc("$my_uri?p=$project;a=summary"), -class => "title"}, " ") .
1569 my %co = git_read_commit($hash);
1570 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1572 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1573 my $commit = $revlist[$i];
1574 my %co = git_read_commit($commit);
1576 my %ad = date_str($co{'author_epoch'});
1578 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$commit"), -class => "title"},
1579 "<span class=\"age\">$co{'age_string'}</span>" . escapeHTML($co{'title'})) . "\n" .
1581 print "<div class=\"title_text\">\n" .
1582 "<div class=\"log_link\">\n" .
1583 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$commit")}, "commit") .
1584 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1587 "<i>" . escapeHTML($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1589 "<div class=\"log_body\">\n";
1590 my $comment = $co{'comment'};
1592 foreach my $line (@$comment) {
1593 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1604 print format_log_line_html($line) . "<br/>\n";
1615 my %co = git_read_commit($hash);
1617 die_error(undef, "Unknown commit object.");
1619 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1620 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1624 my $parent = $co{'parent'};
1625 if (!defined $parent) {
1629 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed.");
1630 @difftree = map { chomp; $_ } <$fd>;
1631 close $fd or die_error(undef, "Reading diff-tree failed.");
1633 # non-textual hash id's can be cached
1635 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1638 git_header_html(undef, $expires);
1639 print "<div class=\"page_nav\">\n" .
1640 $cgi->a({-href => esc("$my_uri?p=$project;a=summary")}, "summary") .
1641 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$hash")}, "shortlog") .
1642 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log;h=$hash")}, "log") .
1644 if (defined $co{'parent'}) {
1645 print " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1647 print " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1648 "<br/><br/></div>\n";
1649 if (defined $co{'parent'}) {
1651 $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$hash"), -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1655 $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1658 print "<div class=\"title_text\">\n" .
1659 "<table cellspacing=\"0\">\n";
1660 print "<tr><td>author</td><td>" . escapeHTML($co{'author'}) . "</td></tr>\n".
1662 "<td></td><td> $ad{'rfc2822'}";
1663 if ($ad{'hour_local'} < 6) {
1664 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1666 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1670 print "<tr><td>committer</td><td>" . escapeHTML($co{'committer'}) . "</td></tr>\n";
1671 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1672 print "<tr><td>commit</td><td style=\"font-family:monospace\">$co{'id'}</td></tr>\n";
1675 "<td style=\"font-family:monospace\">" .
1676 $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1678 "<td class=\"link\">" . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1681 my $parents = $co{'parents'};
1682 foreach my $par (@$parents) {
1685 "<td style=\"font-family:monospace\">" . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1686 "<td class=\"link\">" .
1687 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$par")}, "commit") .
1688 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1694 print "<div class=\"page_body\">\n";
1695 my $comment = $co{'comment'};
1698 foreach my $line (@$comment) {
1699 # print only one empty line
1701 if ($empty || $signed) {
1708 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1710 print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
1713 print format_log_line_html($line) . "<br/>\n";
1717 print "<div class=\"list_head\">\n";
1718 if ($#difftree > 10) {
1719 print(($#difftree + 1) . " files changed:\n");
1722 print "<table cellspacing=\"0\">\n";
1724 foreach my $line (@difftree) {
1725 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1726 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1727 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1735 my $similarity = $6;
1738 print "<tr class=\"dark\">\n";
1740 print "<tr class=\"light\">\n";
1743 if ($status eq "A") {
1745 if (S_ISREG(oct $to_mode)) {
1746 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1749 $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, escapeHTML($file)) . "</td>\n" .
1750 "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1751 "<td class=\"link\">" . $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
1752 } elsif ($status eq "D") {
1754 $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"), -class => "list"}, escapeHTML($file)) . "</td>\n" .
1755 "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1756 "<td class=\"link\">" .
1757 $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
1758 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=history;h=$hash;f=$file")}, "history") .
1760 } elsif ($status eq "M" || $status eq "T") {
1761 my $mode_chnge = "";
1762 if ($from_mode != $to_mode) {
1763 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1764 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1765 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1767 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1768 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1769 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1770 } elsif (S_ISREG($to_mode)) {
1771 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1774 $mode_chnge .= "]</span>\n";
1777 if ($to_id ne $from_id) {
1778 print $cgi->a({-href => esc("$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"), -class => "list"}, escapeHTML($file));
1780 print $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, escapeHTML($file));
1783 "<td>$mode_chnge</td>\n" .
1784 "<td class=\"link\">";
1785 print $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
1786 if ($to_id ne $from_id) {
1787 print " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
1789 print " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
1791 } elsif ($status eq "R") {
1792 my ($from_file, $to_file) = split "\t", $file;
1794 if ($from_mode != $to_mode) {
1795 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1798 $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"), -class => "list"}, escapeHTML($to_file)) . "</td>\n" .
1799 "<td><span style=\"color: #777777;\">[moved from " .
1800 $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file"), -class => "list"}, escapeHTML($from_file)) .
1801 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1802 "<td class=\"link\">" .
1803 $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
1804 if ($to_id ne $from_id) {
1805 print " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
1816 mkdir($git_temp, 0700);
1818 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1819 print "<div class=\"page_nav\">\n" .
1820 $cgi->a({-href => esc("$my_uri?p=$project;a=summary")}, "summary") .
1821 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog")}, "shortlog") .
1822 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log")}, "log") .
1823 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash_base")}, "commit") .
1824 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1825 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
1827 print $cgi->a({-href => esc("$my_uri?p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
1830 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash_base"), -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1833 print "<div class=\"page_nav\">\n" .
1834 "<br/><br/></div>\n" .
1835 "<div class=\"title\">$hash vs $hash_parent</div>\n";
1837 if (defined $file_name) {
1838 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1840 print "<div class=\"page_body\">\n" .
1841 "<div class=\"diff_info\">blob:" .
1842 $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
1844 $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
1846 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
1851 sub git_blobdiff_plain {
1852 mkdir($git_temp, 0700);
1853 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1854 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
1857 sub git_commitdiff {
1858 mkdir($git_temp, 0700);
1859 my %co = git_read_commit($hash);
1861 die_error(undef, "Unknown commit object.");
1863 if (!defined $hash_parent) {
1864 $hash_parent = $co{'parent'};
1866 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1867 my (@difftree) = map { chomp; $_ } <$fd>;
1868 close $fd or die_error(undef, "Reading diff-tree failed.");
1870 # non-textual hash id's can be cached
1872 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1875 git_header_html(undef, $expires);
1876 print "<div class=\"page_nav\">\n" .
1877 $cgi->a({-href => esc("$my_uri?p=$project;a=summary")}, "summary") .
1878 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$hash")}, "shortlog") .
1879 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log;h=$hash")}, "log") .
1880 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
1882 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
1883 print $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
1886 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash"), -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1888 print "<div class=\"page_body\">\n";
1889 my $comment = $co{'comment'};
1892 my @log = @$comment;
1893 # remove first and empty lines after that
1895 while (defined $log[0] && $log[0] eq "") {
1898 foreach my $line (@log) {
1899 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1910 print format_log_line_html($line) . "<br/>\n";
1913 foreach my $line (@difftree) {
1914 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1915 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1916 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1923 if ($status eq "A") {
1924 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
1925 $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
1927 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
1928 } elsif ($status eq "D") {
1929 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
1930 $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
1932 git_diff_print($from_id, "a/$file", undef, "/dev/null");
1933 } elsif ($status eq "M") {
1934 if ($from_id ne $to_id) {
1935 print "<div class=\"diff_info\">" .
1936 file_type($from_mode) . ":" . $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
1938 file_type($to_mode) . ":" . $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
1940 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
1949 sub git_commitdiff_plain {
1950 mkdir($git_temp, 0700);
1951 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1952 my (@difftree) = map { chomp; $_ } <$fd>;
1953 close $fd or die_error(undef, "Reading diff-tree failed.");
1955 # try to figure out the next tag after this commit
1958 my $tags = git_read_refs("refs/tags");
1959 foreach my $entry (@$tags) {
1961 $taghash{$tag{'refid'}} = $tag{'name'};
1963 open $fd, "-|", "$gitbin/git-rev-list HEAD";
1964 while (my $commit = <$fd>) {
1966 if ($taghash{$commit}) {
1967 $tagname = $taghash{$commit};
1969 if ($commit eq $hash) {
1975 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
1976 my %co = git_read_commit($hash);
1977 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1978 my $comment = $co{'comment'};
1979 print "From: $co{'author'}\n" .
1980 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
1981 "Subject: $co{'title'}\n";
1982 if (defined $tagname) {
1983 print "X-Git-Tag: $tagname\n";
1985 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
1988 foreach my $line (@$comment) {;
1993 foreach my $line (@difftree) {
1994 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1999 if ($status eq "A") {
2000 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
2001 } elsif ($status eq "D") {
2002 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
2003 } elsif ($status eq "M") {
2004 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
2010 if (!defined $hash) {
2011 $hash = git_read_hash("$project/HEAD");
2013 my %co = git_read_commit($hash);
2015 die_error(undef, "Unknown commit object.");
2018 print "<div class=\"page_nav\">\n" .
2019 $cgi->a({-href => esc("$my_uri?p=$project;a=summary")}, "summary") .
2020 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog")}, "shortlog") .
2021 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log")}, "log") .
2022 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
2023 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2024 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2028 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash"), -class => "title"}, escapeHTML($co{'title'})) . "\n" .
2030 print "<div class=\"page_path\"><b>/$file_name</b><br/></div>\n";
2032 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin \'$file_name\'";
2034 print "<table cellspacing=\"0\">\n";
2036 while (my $line = <$fd>) {
2037 if ($line =~ m/^([0-9a-fA-F]{40})/){
2041 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2042 my %co = git_read_commit($commit);
2047 print "<tr class=\"dark\">\n";
2049 print "<tr class=\"light\">\n";
2052 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2053 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2054 "<td>" . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2055 escapeHTML(chop_str($co{'title'}, 50)) . "</b>") . "</td>\n" .
2056 "<td class=\"link\">" .
2057 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$commit")}, "commit") .
2058 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2059 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2060 my $blob = git_get_hash_by_path($hash, $file_name);
2061 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2062 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2064 $cgi->a({-href => esc("$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2078 if (!defined $searchtext) {
2079 die_error("", "Text field empty.");
2081 if (!defined $hash) {
2082 $hash = git_read_hash("$project/HEAD");
2084 my %co = git_read_commit($hash);
2086 die_error(undef, "Unknown commit object.");
2088 # pickaxe may take all resources of your box and run for several minutes
2089 # with every query - so decide by yourself how public you make this feature :)
2090 my $commit_search = 1;
2091 my $author_search = 0;
2092 my $committer_search = 0;
2093 my $pickaxe_search = 0;
2094 if ($searchtext =~ s/^author\\://i) {
2096 } elsif ($searchtext =~ s/^committer\\://i) {
2097 $committer_search = 1;
2098 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2100 $pickaxe_search = 1;
2103 print "<div class=\"page_nav\">\n" .
2104 $cgi->a({-href => esc("$my_uri?p=$project;a=summary;h=$hash")}, "summary") .
2105 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog")}, "shortlog") .
2106 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log;h=$hash")}, "log") .
2107 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
2108 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2109 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2114 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash"), -class => "title"}, escapeHTML($co{'title'})) . "\n" .
2116 print "<table cellspacing=\"0\">\n";
2118 if ($commit_search) {
2120 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2121 while (my $commit_text = <$fd>) {
2122 if (!grep m/$searchtext/i, $commit_text) {
2125 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2128 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2131 my @commit_lines = split "\n", $commit_text;
2132 my %co = git_read_commit(undef, \@commit_lines);
2137 print "<tr class=\"dark\">\n";
2139 print "<tr class=\"light\">\n";
2142 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2143 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2145 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" . escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
2146 my $comment = $co{'comment'};
2147 foreach my $line (@$comment) {
2148 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2149 my $lead = escapeHTML($1) || "";
2150 $lead = chop_str($lead, 30, 10);
2151 my $match = escapeHTML($2) || "";
2152 my $trail = escapeHTML($3) || "";
2153 $trail = chop_str($trail, 30, 10);
2154 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
2155 print chop_str($text, 80, 5) . "<br/>\n";
2159 "<td class=\"link\">" .
2160 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$co{'id'}")}, "commit") .
2161 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2168 if ($pickaxe_search) {
2170 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S$searchtext";
2173 while (my $line = <$fd>) {
2174 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2177 $set{'from_id'} = $3;
2179 $set{'id'} = $set{'to_id'};
2180 if ($set{'id'} =~ m/0{40}/) {
2181 $set{'id'} = $set{'from_id'};
2183 if ($set{'id'} =~ m/0{40}/) {
2187 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2190 print "<tr class=\"dark\">\n";
2192 print "<tr class=\"light\">\n";
2195 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2196 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2198 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2199 escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
2200 while (my $setref = shift @files) {
2202 print $cgi->a({-href => esc("$my_uri?p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2203 "<span style=\"color:#e00000\">" . escapeHTML($set{'file'}) . "</span>") .
2207 "<td class=\"link\">" .
2208 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$co{'id'}")}, "commit") .
2209 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2213 %co = git_read_commit($1);
2223 my $head = git_read_hash("$project/HEAD");
2224 if (!defined $hash) {
2227 if (!defined $page) {
2231 print "<div class=\"page_nav\">\n" .
2232 $cgi->a({-href => esc("$my_uri?p=$project;a=summary")}, "summary") .
2234 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=log;h=$hash")}, "log") .
2235 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$hash")}, "commit") .
2236 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2237 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2239 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2240 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
2241 my (@revlist) = map { chomp; $_ } <$fd>;
2244 if ($hash ne $head || $page) {
2245 print $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog")}, "HEAD");
2251 $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
2253 print " ⋅ prev";
2255 if ($#revlist >= (100 * ($page+1)-1)) {
2257 $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
2259 print " ⋅ next";
2264 $cgi->a({-href => esc("$my_uri?p=$project;a=summary"), -class => "title"}, " ") .
2266 print "<table cellspacing=\"0\">\n";
2268 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2269 my $commit = $revlist[$i];
2270 my %co = git_read_commit($commit);
2271 my %ad = date_str($co{'author_epoch'});
2273 print "<tr class=\"dark\">\n";
2275 print "<tr class=\"light\">\n";
2278 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2279 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2281 if (length($co{'title_short'}) < length($co{'title'})) {
2282 print $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
2283 "<b>" . escapeHTML($co{'title_short'}) . "</b>");
2285 print $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$commit"), -class => "list"},
2286 "<b>" . escapeHTML($co{'title_short'}) . "</b>");
2289 "<td class=\"link\">" .
2290 $cgi->a({-href => esc("$my_uri?p=$project;a=commit;h=$commit")}, "commit") .
2291 " | " . $cgi->a({-href => esc("$my_uri?p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2295 if ($#revlist >= (100 * ($page+1)-1)) {
2298 $cgi->a({-href => esc("$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title => "Alt-n"}, "next") .