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_param($project) . " log\" href=\"" .
84 "$my_uri?" . esc_param("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_\x80-\xff\ \.\/\-\+\#\~\%]/) {
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.");
212 # quote unsafe chars, but keep the slash, even when it's not
213 # correct, but quoted slashes look too horrible in bookmarks
216 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
222 # replace invalid utf8 character with SUBSTITUTION sequence
225 $str = decode("utf8", $str, Encode::FB_DEFAULT);
226 $str = escapeHTML($str);
230 # git may return quoted and escaped filenames
233 if ($str =~ m/^"(.*)"$/) {
235 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
240 sub git_header_html {
241 my $status = shift || "200 OK";
245 if (defined $project) {
246 $title .= " - $project";
247 if (defined $action) {
248 $title .= "/$action";
251 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires);
253 <?xml version="1.0" encoding="utf-8"?>
254 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
255 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
256 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
258 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
259 <meta name="robots" content="index, nofollow"/>
260 <title>$title</title>
262 <style type="text/css">
263 body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
265 a:hover, a:visited, a:active { color:#880000; }
266 div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; }
267 div.page_header a:visited, a.header { color:#0000cc; }
268 div.page_header a:hover { color:#880000; }
269 div.page_nav { padding:8px; }
270 div.page_nav a:visited { color:#0000cc; }
271 div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
272 div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
273 div.page_footer_text { float:left; color:#555555; font-style:italic; }
274 div.page_body { padding:8px; }
276 display:block; padding:6px 8px;
277 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
279 a.title:hover { background-color: #d9d8d1; }
280 div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; }
281 div.log_body { padding:8px 8px 8px 150px; }
282 span.age { position:relative; float:left; width:142px; font-style:italic; }
285 font-size:10px; font-family:sans-serif; font-style:normal;
286 position:relative; float:left; width:136px;
288 div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; }
289 a.list { text-decoration:none; color:#000000; }
290 a.list:hover { text-decoration:underline; color:#880000; }
291 a.text { text-decoration:none; color:#0000cc; }
292 a.text:visited { text-decoration:none; color:#880000; }
293 a.text:hover { text-decoration:underline; color:#880000; }
294 table { padding:8px 4px; }
295 th { padding:2px 5px; font-size:12px; text-align:left; }
296 tr.light:hover { background-color:#edece6; }
297 tr.dark { background-color:#f6f6f0; }
298 tr.dark:hover { background-color:#edece6; }
299 td { padding:2px 5px; font-size:12px; vertical-align:top; }
300 td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; }
301 div.pre { font-family:monospace; font-size:12px; white-space:pre; }
302 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
303 div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
304 div.search { margin:4px 8px; position:absolute; top:56px; right:12px }
305 a.linenr { color:#999999; text-decoration:none }
307 float:right; padding:3px 0px; width:35px; line-height:10px;
308 border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
309 color:#ffffff; background-color:#ff6600;
310 font-weight:bold; font-family:sans-serif; font-size:10px;
311 text-align:center; text-decoration:none;
313 a.rss_logo:hover { background-color:#ee5500; }
318 print "<div class=\"page_header\">\n" .
319 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
320 "<img src=\"$my_uri?" . esc_param("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
322 print $cgi->a({-href => esc_param($home_link)}, "projects") . " / ";
323 if (defined $project) {
324 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, esc_html($project));
325 if (defined $action) {
329 if (!defined $searchtext) {
334 $search_hash = $hash;
336 $search_hash = "HEAD";
338 $cgi->param("a", "search");
339 $cgi->param("h", $search_hash);
340 print $cgi->startform(-method => "get", -action => $my_uri) .
341 "<div class=\"search\">\n" .
342 $cgi->hidden(-name => "p") . "\n" .
343 $cgi->hidden(-name => "a") . "\n" .
344 $cgi->hidden(-name => "h") . "\n" .
345 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
347 $cgi->end_form() . "\n";
352 sub git_footer_html {
353 print "<div class=\"page_footer\">\n";
354 if (defined $project) {
355 my $descr = git_read_description($project);
356 if (defined $descr) {
357 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
359 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
361 print $cgi->a({-href => "$my_uri?" . esc_param("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
369 my $status = shift || "403 Forbidden";
370 my $error = shift || "Malformed query, file missing or permission denied";
372 git_header_html($status);
373 print "<div class=\"page_body\">\n" .
375 "$status - $error\n" .
385 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
395 open my $fd, "$projectroot/$path" or return undef;
399 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
404 sub git_read_description {
407 open my $fd, "$projectroot/$path/description" or return undef;
419 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
420 $tag{'id'} = $tag_id;
421 while (my $line = <$fd>) {
423 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
425 } elsif ($line =~ m/^type (.+)$/) {
427 } elsif ($line =~ m/^tag (.+)$/) {
429 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
433 } elsif ($line =~ m/--BEGIN/) {
434 push @comment, $line;
436 } elsif ($line eq "") {
440 push @comment, <$fd>;
441 $tag{'comment'} = \@comment;
443 if (!defined $tag{'name'}) {
453 if ($age > 60*60*24*365*2) {
454 $age_str = (int $age/60/60/24/365);
455 $age_str .= " years ago";
456 } elsif ($age > 60*60*24*(365/12)*2) {
457 $age_str = int $age/60/60/24/(365/12);
458 $age_str .= " months ago";
459 } elsif ($age > 60*60*24*7*2) {
460 $age_str = int $age/60/60/24/7;
461 $age_str .= " weeks ago";
462 } elsif ($age > 60*60*24*2) {
463 $age_str = int $age/60/60/24;
464 $age_str .= " days ago";
465 } elsif ($age > 60*60*2) {
466 $age_str = int $age/60/60;
467 $age_str .= " hours ago";
468 } elsif ($age > 60*2) {
469 $age_str = int $age/60;
470 $age_str .= " min ago";
473 $age_str .= " sec ago";
475 $age_str .= " right now";
480 sub git_read_commit {
481 my $commit_id = shift;
482 my $commit_text = shift;
487 if (defined $commit_text) {
488 @commit_lines = @$commit_text;
491 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
492 @commit_lines = split '\n', <$fd>;
497 my $header = shift @commit_lines;
498 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
501 ($co{'id'}, my @parents) = split ' ', $header;
502 $co{'parents'} = \@parents;
503 $co{'parent'} = $parents[0];
504 while (my $line = shift @commit_lines) {
505 last if $line eq "\n";
506 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
508 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
510 $co{'author_epoch'} = $2;
511 $co{'author_tz'} = $3;
512 if ($co{'author'} =~ m/^([^<]+) </) {
513 $co{'author_name'} = $1;
515 $co{'author_name'} = $co{'author'};
517 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
518 $co{'committer'} = $1;
519 $co{'committer_epoch'} = $2;
520 $co{'committer_tz'} = $3;
521 $co{'committer_name'} = $co{'committer'};
522 $co{'committer_name'} =~ s/ <.*//;
525 if (!defined $co{'tree'}) {
529 foreach my $title (@commit_lines) {
531 $co{'title'} = chop_str($title, 80, 5);
532 # remove leading stuff of merges to make the interesting part visible
533 if (length($title) > 50) {
534 $title =~ s/^Automatic //;
535 $title =~ s/^merge (of|with) /Merge ... /i;
536 if (length($title) > 50) {
537 $title =~ s/(http|rsync):\/\///;
539 if (length($title) > 50) {
540 $title =~ s/(master|www|rsync)\.//;
542 if (length($title) > 50) {
543 $title =~ s/kernel.org:?//;
545 if (length($title) > 50) {
546 $title =~ s/\/pub\/scm//;
549 $co{'title_short'} = chop_str($title, 50, 5);
553 # remove added spaces
554 foreach my $line (@commit_lines) {
557 $co{'comment'} = \@commit_lines;
559 my $age = time - $co{'committer_epoch'};
561 $co{'age_string'} = age_string($age);
562 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
563 if ($age > 60*60*24*7*2) {
564 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
565 $co{'age_string_age'} = $co{'age_string'};
567 $co{'age_string_date'} = $co{'age_string'};
568 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
575 my $from_name = shift;
578 my $format = shift || "html";
580 my $from_tmp = "/dev/null";
581 my $to_tmp = "/dev/null";
584 # create tmp from-file
586 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
587 open my $fd2, "> $from_tmp";
588 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
597 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
598 open my $fd2, "> $to_tmp";
599 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
606 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
607 if ($format eq "plain") {
612 while (my $line = <$fd>) {
614 my $char = substr($line, 0, 1);
617 $color = " style=\"color:#008800;\"";
618 } elsif ($char eq "-") {
619 $color = " style=\"color:#cc0000;\"";
620 } elsif ($char eq "@") {
621 $color = " style=\"color:#990099;\"";
622 } elsif ($char eq "\\") {
626 while ((my $pos = index($line, "\t")) != -1) {
627 if (my $count = (8 - (($pos-1) % 8))) {
628 my $spaces = ' ' x $count;
629 $line =~ s/\t/$spaces/;
632 print "<div class=\"pre\"$color>" . esc_html($line) . "</div>\n";
646 my $mode = oct shift;
648 if (S_ISDIR($mode & S_IFMT)) {
650 } elsif (S_ISLNK($mode)) {
652 } elsif (S_ISREG($mode)) {
653 # git cares only about the executable bit
654 if ($mode & S_IXUSR) {
667 my $add_len = shift || 10;
669 # allow only $len chars, but don't cut a word if it would fit in $add_len
670 # if it doesn't fit, cut it if it's still longer than the dots we would add
671 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
674 if (length($tail) > 4) {
681 my $mode = oct shift;
683 if (S_ISDIR($mode & S_IFMT)) {
685 } elsif (S_ISLNK($mode)) {
687 } elsif (S_ISREG($mode)) {
694 sub format_log_line_html {
697 $line = esc_html($line);
698 $line =~ s/ / /g;
699 if ($line =~ m/([0-9a-fA-F]{40})/) {
701 if (git_get_type($hash_text) eq "commit") {
702 my $link = $cgi->a({-class => "text", -href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_text")}, $hash_text);
703 $line =~ s/$hash_text/$link/;
711 my $tz = shift || "-0000";
714 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
715 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
716 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
717 $date{'hour'} = $hour;
718 $date{'minute'} = $min;
719 $date{'mday'} = $mday;
720 $date{'day'} = $days[$wday];
721 $date{'month'} = $months[$mon];
722 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
723 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
725 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
726 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
727 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
728 $date{'hour_local'} = $hour;
729 $date{'minute_local'} = $min;
730 $date{'tz_local'} = $tz;
734 # git-logo (cached in browser for one day)
736 binmode STDOUT, ':raw';
737 print $cgi->header(-type => 'image/png', -expires => '+1d');
738 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
739 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
740 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
741 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
742 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
743 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
744 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
745 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
746 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
747 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
748 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
749 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
750 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
751 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
757 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
758 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
759 if (!defined $gcos) {
763 $owner =~ s/[,;].*$//;
767 sub git_read_projects {
770 if (-d $projects_list) {
771 # search in directory
772 my $dir = $projects_list;
773 opendir my $dh, $dir or return undef;
774 while (my $dir = readdir($dh)) {
775 if (-e "$projectroot/$dir/HEAD") {
783 } elsif (-f $projects_list) {
784 # read from file(url-encoded):
785 # 'git%2Fgit.git Linus+Torvalds'
786 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
787 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
788 open my $fd , $projects_list or return undef;
789 while (my $line = <$fd>) {
791 my ($path, $owner) = split ' ', $line;
792 $path = unescape($path);
793 $owner = unescape($owner);
794 if (!defined $path) {
797 if (-e "$projectroot/$path/HEAD") {
807 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
811 sub git_project_list {
812 my @list = git_read_projects();
815 die_error(undef, "No project found.");
817 foreach my $pr (@list) {
818 my $head = git_read_hash("$pr->{'path'}/HEAD");
819 if (!defined $head) {
822 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
823 my %co = git_read_commit($head);
827 $pr->{'commit'} = \%co;
828 if (!defined $pr->{'descr'}) {
829 my $descr = git_read_description($pr->{'path'}) || "";
830 $pr->{'descr'} = chop_str($descr, 25, 5);
832 if (!defined $pr->{'owner'}) {
833 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
839 print "<div class=\"index_include\">\n";
840 open (my $fd, $home_text);
845 print "<table cellspacing=\"0\">\n" .
847 if (!defined($order) || (defined($order) && ($order eq "project"))) {
848 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
849 print "<th>Project</th>\n";
851 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=project")}, "Project") . "</th>\n";
853 if (defined($order) && ($order eq "descr")) {
854 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
855 print "<th>Description</th>\n";
857 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=descr")}, "Description") . "</th>\n";
859 if (defined($order) && ($order eq "owner")) {
860 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
861 print "<th>Owner</th>\n";
863 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=owner")}, "Owner") . "</th>\n";
865 if (defined($order) && ($order eq "age")) {
866 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
867 print "<th>Last Change</th>\n";
869 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=age")}, "Last Change") . "</th>\n";
871 print "<th></th>\n" .
874 foreach my $pr (@projects) {
876 print "<tr class=\"dark\">\n";
878 print "<tr class=\"light\">\n";
881 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
882 "<td>$pr->{'descr'}</td>\n" .
883 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
885 if ($pr->{'commit'}{'age'} < 60*60*2) {
886 $colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>";
887 } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {
888 $colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>";
890 $colored_age = "<i>$pr->{'commit'}{'age_string'}</i>";
892 print "<td>$colored_age</td>\n" .
893 "<td class=\"link\">" .
894 $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") .
895 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") .
896 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") .
909 opendir my $dh, "$projectroot/$project/$ref_dir";
910 while (my $dir = readdir($dh)) {
911 if ($dir =~ m/^\./) {
914 if (-d "$projectroot/$project/$ref_dir/$dir") {
915 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
916 my @subdirs = grep !m/^\./, readdir $dh2;
918 foreach my $subdir (@subdirs) {
919 push @refs, "$dir/$subdir"
926 foreach my $ref_file (@refs) {
927 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
928 my $type = git_get_type($ref_id) || next;
931 $ref_item{'type'} = $type;
932 $ref_item{'id'} = $ref_id;
933 $ref_item{'epoch'} = 0;
934 $ref_item{'age'} = "unknown";
935 if ($type eq "tag") {
936 my %tag = git_read_tag($ref_id);
937 $ref_item{'comment'} = $tag{'comment'};
938 if ($tag{'type'} eq "commit") {
939 %co = git_read_commit($tag{'object'});
940 $ref_item{'epoch'} = $co{'committer_epoch'};
941 $ref_item{'age'} = $co{'age_string'};
942 } elsif (defined($tag{'epoch'})) {
943 my $age = time - $tag{'epoch'};
944 $ref_item{'epoch'} = $tag{'epoch'};
945 $ref_item{'age'} = age_string($age);
947 $ref_item{'reftype'} = $tag{'type'};
948 $ref_item{'name'} = $tag{'name'};
949 $ref_item{'refid'} = $tag{'object'};
950 } elsif ($type eq "commit"){
951 %co = git_read_commit($ref_id);
952 $ref_item{'reftype'} = "commit";
953 $ref_item{'name'} = $ref_file;
954 $ref_item{'title'} = $co{'title'};
955 $ref_item{'refid'} = $ref_id;
956 $ref_item{'epoch'} = $co{'committer_epoch'};
957 $ref_item{'age'} = $co{'age_string'};
960 push @reflist, \%ref_item;
963 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
968 my $descr = git_read_description($project) || "none";
969 my $head = git_read_hash("$project/HEAD");
970 my %co = git_read_commit($head);
971 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
974 if (-f $projects_list) {
975 open (my $fd , $projects_list);
976 while (my $line = <$fd>) {
978 my ($pr, $ow) = split ' ', $line;
981 if ($pr eq $project) {
988 if (!defined $owner) {
989 $owner = get_file_owner("$projectroot/$project");
993 print "<div class=\"page_nav\">\n" .
995 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
996 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
997 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
998 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
999 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree")}, "tree") .
1002 print "<div class=\"title\"> </div>\n";
1003 print "<table cellspacing=\"0\">\n" .
1004 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
1005 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1006 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1008 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
1009 my (@revlist) = map { chomp; $_ } <$fd>;
1012 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1015 print "<table cellspacing=\"0\">\n";
1017 foreach my $commit (@revlist) {
1018 my %co = git_read_commit($commit);
1019 my %ad = date_str($co{'author_epoch'});
1021 print "<tr class=\"dark\">\n";
1023 print "<tr class=\"light\">\n";
1027 print "<td><i>$co{'age_string'}</i></td>\n" .
1028 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1030 if (length($co{'title_short'}) < length($co{'title'})) {
1031 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
1032 "<b>" . esc_html($co{'title_short'}) . "</b>");
1034 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
1035 "<b>" . esc_html($co{'title'}) . "</b>");
1038 "<td class=\"link\">" .
1039 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1040 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1044 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "...") . "</td>\n" .
1051 my $taglist = git_read_refs("refs/tags");
1052 if (defined @$taglist) {
1054 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags"), -class => "title"}, "tags") .
1057 print "<table cellspacing=\"0\">\n";
1059 foreach my $entry (@$taglist) {
1061 my $comment_lines = $tag{'comment'};
1062 my $comment = shift @$comment_lines;
1063 if (defined($comment)) {
1064 $comment = chop_str($comment, 30, 5);
1067 print "<tr class=\"dark\">\n";
1069 print "<tr class=\"light\">\n";
1073 print "<td><i>$tag{'age'}</i></td>\n" .
1075 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1076 "<b>" . esc_html($tag{'name'}) . "</b>") .
1079 if (defined($comment)) {
1080 print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1083 "<td class=\"link\">";
1084 if ($tag{'type'} eq "tag") {
1085 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1087 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1088 if ($tag{'reftype'} eq "commit") {
1089 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1090 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
1095 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags")}, "...") . "</td>\n" .
1103 my $headlist = git_read_refs("refs/heads");
1104 if (defined @$headlist) {
1106 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads"), -class => "title"}, "heads") .
1109 print "<table cellspacing=\"0\">\n";
1111 foreach my $entry (@$headlist) {
1114 print "<tr class=\"dark\">\n";
1116 print "<tr class=\"light\">\n";
1120 print "<td><i>$tag{'age'}</i></td>\n" .
1122 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1123 "<b>" . esc_html($tag{'name'}) . "</b>") .
1125 "<td class=\"link\">" .
1126 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1127 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1131 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads")}, "...") . "</td>\n" .
1142 my $head = git_read_hash("$project/HEAD");
1144 print "<div class=\"page_nav\">\n" .
1145 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1146 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1147 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1148 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1149 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1150 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1153 my %tag = git_read_tag($hash);
1155 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($tag{'name'})) . "\n" .
1157 print "<div class=\"title_text\">\n" .
1158 "<table cellspacing=\"0\">\n" .
1160 "<td>object</td>\n" .
1161 "<td>" . $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1162 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1164 if (defined($tag{'author'})) {
1165 my %ad = date_str($tag{'epoch'}, $tag{'tz'});
1166 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
1167 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1169 print "</table>\n\n" .
1171 print "<div class=\"page_body\">";
1172 my $comment = $tag{'comment'};
1173 foreach my $line (@$comment) {
1174 print esc_html($line) . "<br/>\n";
1181 my $head = git_read_hash("$project/HEAD");
1183 print "<div class=\"page_nav\">\n" .
1184 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1185 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1186 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1187 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1188 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1189 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1192 my $taglist = git_read_refs("refs/tags");
1194 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1196 print "<table cellspacing=\"0\">\n";
1198 if (defined @$taglist) {
1199 foreach my $entry (@$taglist) {
1201 my $comment_lines = $tag{'comment'};
1202 my $comment = shift @$comment_lines;
1203 if (defined($comment)) {
1204 $comment = chop_str($comment, 30, 5);
1207 print "<tr class=\"dark\">\n";
1209 print "<tr class=\"light\">\n";
1212 print "<td><i>$tag{'age'}</i></td>\n" .
1214 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1215 "<b>" . esc_html($tag{'name'}) . "</b>") .
1218 if (defined($comment)) {
1219 print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1222 "<td class=\"link\">";
1223 if ($tag{'type'} eq "tag") {
1224 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1226 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1227 if ($tag{'reftype'} eq "commit") {
1228 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1229 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
1240 my $head = git_read_hash("$project/HEAD");
1242 print "<div class=\"page_nav\">\n" .
1243 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1244 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1245 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1246 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1247 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1248 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1251 my $taglist = git_read_refs("refs/heads");
1253 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1255 print "<table cellspacing=\"0\">\n";
1257 if (defined @$taglist) {
1258 foreach my $entry (@$taglist) {
1261 print "<tr class=\"dark\">\n";
1263 print "<tr class=\"light\">\n";
1266 print "<td><i>$tag{'age'}</i></td>\n" .
1268 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
1270 "<td class=\"link\">" .
1271 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1272 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1281 sub git_get_hash_by_path {
1283 my $path = shift || return undef;
1286 my @parts = split '/', $path;
1287 while (my $part = shift @parts) {
1288 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1289 my (@entries) = map { chomp; $_ } <$fd>;
1290 close $fd or return undef;
1291 foreach my $line (@entries) {
1292 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1293 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1298 if ($t_name eq $part) {
1302 if ($t_type eq "tree") {
1312 if (!defined $hash && defined $file_name) {
1313 my $base = $hash_base || git_read_hash("$project/HEAD");
1314 $hash = git_get_hash_by_path($base, $file_name, "blob");
1316 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1318 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1319 print "<div class=\"page_nav\">\n" .
1320 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1321 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1322 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1323 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1324 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1325 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1326 if (defined $file_name) {
1327 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1328 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1330 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1334 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
1337 print "<div class=\"page_nav\">\n" .
1338 "<br/><br/></div>\n" .
1339 "<div class=\"title\">$hash</div>\n";
1341 if (defined $file_name) {
1342 print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n";
1344 print "<div class=\"page_body\">\n";
1346 while (my $line = <$fd>) {
1349 while ((my $pos = index($line, "\t")) != -1) {
1350 if (my $count = (8 - ($pos % 8))) {
1351 my $spaces = ' ' x $count;
1352 $line =~ s/\t/$spaces/;
1355 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line);
1357 close $fd or print "Reading blob failed.\n";
1362 sub git_blob_plain {
1363 my $save_as = "$hash.txt";
1364 if (defined $file_name) {
1365 $save_as = $file_name;
1367 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"$save_as\"");
1368 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1376 if (!defined $hash) {
1377 $hash = git_read_hash("$project/HEAD");
1378 if (defined $file_name) {
1379 my $base = $hash_base || git_read_hash("$project/HEAD");
1380 $hash = git_get_hash_by_path($base, $file_name, "tree");
1382 if (!defined $hash_base) {
1383 $hash_base = git_read_hash("$project/HEAD");
1387 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error(undef, "Open git-ls-tree failed.");
1388 chomp (my (@entries) = <$fd>);
1389 close $fd or die_error(undef, "Reading tree failed.");
1395 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1396 $base_key = ";hb=$hash_base";
1397 print "<div class=\"page_nav\">\n" .
1398 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1399 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1400 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash_base")}, "log") .
1401 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1402 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1407 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1410 print "<div class=\"page_nav\">\n";
1411 print "<br/><br/></div>\n";
1412 print "<div class=\"title\">$hash</div>\n";
1414 if (defined $file_name) {
1415 $base = esc_html("$file_name/");
1416 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n";
1418 print "<div class=\"page_path\"><b>/</b></div>\n";
1420 print "<div class=\"page_body\">\n";
1421 print "<table cellspacing=\"0\">\n";
1423 foreach my $line (@entries) {
1424 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1425 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1429 my $t_name = validate_input($4);
1431 print "<tr class=\"dark\">\n";
1433 print "<tr class=\"light\">\n";
1436 print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n";
1437 if ($t_type eq "blob") {
1438 print "<td class=\"list\">" .
1439 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name"), -class => "list"}, esc_html($t_name)) .
1441 "<td class=\"link\">" .
1442 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1443 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1445 } elsif ($t_type eq "tree") {
1446 print "<td class=\"list\">" .
1447 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html($t_name)) .
1449 "<td class=\"link\">" .
1450 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1455 print "</table>\n" .
1461 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1462 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
1463 my (@revlist) = map { chomp; $_ } <$fd>;
1464 close $fd or die_error(undef, "Reading rev-list failed.");
1465 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1466 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1467 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1468 print "<channel>\n";
1469 print "<title>$project</title>\n".
1470 "<link>" . esc_html("$my_url?p=$project;a=summary") . "</link>\n".
1471 "<description>$project log</description>\n".
1472 "<language>en</language>\n";
1474 for (my $i = 0; $i <= $#revlist; $i++) {
1475 my $commit = $revlist[$i];
1476 my %co = git_read_commit($commit);
1477 # we read 150, we always show 30 and the ones more recent than 48 hours
1478 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1481 my %cd = date_str($co{'committer_epoch'});
1482 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1483 my @difftree = map { chomp; $_ } <$fd>;
1487 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
1489 "<author>" . esc_html($co{'author'}) . "</author>\n" .
1490 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1491 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1492 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1493 "<description>" . esc_html($co{'title'}) . "</description>\n" .
1494 "<content:encoded>" .
1496 my $comment = $co{'comment'};
1497 foreach my $line (@$comment) {
1498 $line = decode("utf8", $line, Encode::FB_DEFAULT);
1499 print "$line<br/>\n";
1502 foreach my $line (@difftree) {
1503 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1506 my $file = validate_input(unquote($7));
1507 $file = decode("utf8", $file, Encode::FB_DEFAULT);
1508 print "$file<br/>\n";
1511 "</content:encoded>\n" .
1514 print "</channel></rss>";
1518 my @list = git_read_projects();
1520 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1521 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1522 "<opml version=\"1.0\">\n".
1524 " <title>Git OPML Export</title>\n".
1527 "<outline text=\"git RSS feeds\">\n";
1529 foreach my $pr (@list) {
1531 my $head = git_read_hash("$proj{'path'}/HEAD");
1532 if (!defined $head) {
1535 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1536 my %co = git_read_commit($head);
1541 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
1542 my $rss = "$my_url?p=$proj{'path'};a=rss";
1543 my $html = "$my_url?p=$proj{'path'};a=summary";
1544 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1546 print "</outline>\n".
1552 my $head = git_read_hash("$project/HEAD");
1553 if (!defined $hash) {
1556 if (!defined $page) {
1560 print "<div class=\"page_nav\">\n";
1561 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1562 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1564 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
1565 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1566 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1568 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1569 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1570 my (@revlist) = map { chomp; $_ } <$fd>;
1573 if ($hash ne $head || $page) {
1574 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "HEAD");
1580 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
1582 print " ⋅ prev";
1584 if ($#revlist >= (100 * ($page+1)-1)) {
1586 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
1588 print " ⋅ next";
1594 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1596 my %co = git_read_commit($hash);
1597 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1599 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1600 my $commit = $revlist[$i];
1601 my %co = git_read_commit($commit);
1603 my %ad = date_str($co{'author_epoch'});
1605 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "title"},
1606 "<span class=\"age\">$co{'age_string'}</span>" . esc_html($co{'title'})) . "\n" .
1608 print "<div class=\"title_text\">\n" .
1609 "<div class=\"log_link\">\n" .
1610 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1611 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1614 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1616 "<div class=\"log_body\">\n";
1617 my $comment = $co{'comment'};
1619 foreach my $line (@$comment) {
1620 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1631 print format_log_line_html($line) . "<br/>\n";
1642 my %co = git_read_commit($hash);
1644 die_error(undef, "Unknown commit object.");
1646 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1647 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1651 my $parent = $co{'parent'};
1652 if (!defined $parent) {
1656 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed.");
1657 @difftree = map { chomp; $_ } <$fd>;
1658 close $fd or die_error(undef, "Reading diff-tree failed.");
1660 # non-textual hash id's can be cached
1662 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1665 git_header_html(undef, $expires);
1666 print "<div class=\"page_nav\">\n" .
1667 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1668 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1669 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
1671 if (defined $co{'parent'}) {
1672 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1674 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1675 "<br/><br/></div>\n";
1676 if (defined $co{'parent'}) {
1678 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1682 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1685 print "<div class=\"title_text\">\n" .
1686 "<table cellspacing=\"0\">\n";
1687 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
1689 "<td></td><td> $ad{'rfc2822'}";
1690 if ($ad{'hour_local'} < 6) {
1691 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1693 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1697 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
1698 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1699 print "<tr><td>commit</td><td style=\"font-family:monospace\">$co{'id'}</td></tr>\n";
1702 "<td style=\"font-family:monospace\">" .
1703 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1705 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1708 my $parents = $co{'parents'};
1709 foreach my $par (@$parents) {
1712 "<td style=\"font-family:monospace\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1713 "<td class=\"link\">" .
1714 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par")}, "commit") .
1715 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1721 print "<div class=\"page_body\">\n";
1722 my $comment = $co{'comment'};
1725 foreach my $line (@$comment) {
1726 # print only one empty line
1728 if ($empty || $signed) {
1735 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1737 print "<span style=\"color: #888888\">" . esc_html($line) . "</span><br/>\n";
1740 print format_log_line_html($line) . "<br/>\n";
1744 print "<div class=\"list_head\">\n";
1745 if ($#difftree > 10) {
1746 print(($#difftree + 1) . " files changed:\n");
1749 print "<table cellspacing=\"0\">\n";
1751 foreach my $line (@difftree) {
1752 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1753 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1754 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1762 my $similarity = $6;
1763 my $file = validate_input(unquote($7));
1765 print "<tr class=\"dark\">\n";
1767 print "<tr class=\"light\">\n";
1770 if ($status eq "A") {
1772 if (S_ISREG(oct $to_mode)) {
1773 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1776 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file)) . "</td>\n" .
1777 "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1778 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
1779 } elsif ($status eq "D") {
1781 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file)) . "</td>\n" .
1782 "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1783 "<td class=\"link\">" .
1784 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
1785 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") .
1787 } elsif ($status eq "M" || $status eq "T") {
1788 my $mode_chnge = "";
1789 if ($from_mode != $to_mode) {
1790 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1791 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1792 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1794 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1795 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1796 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1797 } elsif (S_ISREG($to_mode)) {
1798 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1801 $mode_chnge .= "]</span>\n";
1804 if ($to_id ne $from_id) {
1805 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
1807 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
1810 "<td>$mode_chnge</td>\n" .
1811 "<td class=\"link\">";
1812 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
1813 if ($to_id ne $from_id) {
1814 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
1816 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
1818 } elsif ($status eq "R") {
1819 my ($from_file, $to_file) = split "\t", $file;
1821 if ($from_mode != $to_mode) {
1822 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1825 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"), -class => "list"}, esc_html($to_file)) . "</td>\n" .
1826 "<td><span style=\"color: #777777;\">[moved from " .
1827 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file"), -class => "list"}, esc_html($from_file)) .
1828 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1829 "<td class=\"link\">" .
1830 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
1831 if ($to_id ne $from_id) {
1832 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
1843 mkdir($git_temp, 0700);
1845 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1846 print "<div class=\"page_nav\">\n" .
1847 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1848 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1849 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1850 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1851 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1852 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
1854 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
1857 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1860 print "<div class=\"page_nav\">\n" .
1861 "<br/><br/></div>\n" .
1862 "<div class=\"title\">$hash vs $hash_parent</div>\n";
1864 if (defined $file_name) {
1865 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n";
1867 print "<div class=\"page_body\">\n" .
1868 "<div class=\"diff_info\">blob:" .
1869 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
1871 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
1873 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
1878 sub git_blobdiff_plain {
1879 mkdir($git_temp, 0700);
1880 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1881 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
1884 sub git_commitdiff {
1885 mkdir($git_temp, 0700);
1886 my %co = git_read_commit($hash);
1888 die_error(undef, "Unknown commit object.");
1890 if (!defined $hash_parent) {
1891 $hash_parent = $co{'parent'};
1893 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1894 my (@difftree) = map { chomp; $_ } <$fd>;
1895 close $fd or die_error(undef, "Reading diff-tree failed.");
1897 # non-textual hash id's can be cached
1899 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1902 git_header_html(undef, $expires);
1903 print "<div class=\"page_nav\">\n" .
1904 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1905 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1906 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
1907 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
1909 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
1910 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
1913 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1915 print "<div class=\"page_body\">\n";
1916 my $comment = $co{'comment'};
1919 my @log = @$comment;
1920 # remove first and empty lines after that
1922 while (defined $log[0] && $log[0] eq "") {
1925 foreach my $line (@log) {
1926 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1937 print format_log_line_html($line) . "<br/>\n";
1940 foreach my $line (@difftree) {
1941 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1942 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1943 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1949 my $file = validate_input(unquote($6));
1950 if ($status eq "A") {
1951 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
1952 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
1954 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
1955 } elsif ($status eq "D") {
1956 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
1957 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
1959 git_diff_print($from_id, "a/$file", undef, "/dev/null");
1960 } elsif ($status eq "M") {
1961 if ($from_id ne $to_id) {
1962 print "<div class=\"diff_info\">" .
1963 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
1965 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
1967 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
1976 sub git_commitdiff_plain {
1977 mkdir($git_temp, 0700);
1978 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1979 my (@difftree) = map { chomp; $_ } <$fd>;
1980 close $fd or die_error(undef, "Reading diff-tree failed.");
1982 # try to figure out the next tag after this commit
1985 my $tags = git_read_refs("refs/tags");
1986 foreach my $entry (@$tags) {
1988 $taghash{$tag{'refid'}} = $tag{'name'};
1990 open $fd, "-|", "$gitbin/git-rev-list HEAD";
1991 while (my $commit = <$fd>) {
1993 if ($taghash{$commit}) {
1994 $tagname = $taghash{$commit};
1996 if ($commit eq $hash) {
2002 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2003 my %co = git_read_commit($hash);
2004 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
2005 my $comment = $co{'comment'};
2006 print "From: $co{'author'}\n" .
2007 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2008 "Subject: $co{'title'}\n";
2009 if (defined $tagname) {
2010 print "X-Git-Tag: $tagname\n";
2012 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2015 foreach my $line (@$comment) {;
2020 foreach my $line (@difftree) {
2021 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2026 if ($status eq "A") {
2027 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
2028 } elsif ($status eq "D") {
2029 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
2030 } elsif ($status eq "M") {
2031 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
2037 if (!defined $hash) {
2038 $hash = git_read_hash("$project/HEAD");
2040 my %co = git_read_commit($hash);
2042 die_error(undef, "Unknown commit object.");
2045 print "<div class=\"page_nav\">\n" .
2046 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2047 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2048 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
2049 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2050 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2051 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2055 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2057 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b><br/></div>\n";
2059 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin \'$file_name\'";
2061 print "<table cellspacing=\"0\">\n";
2063 while (my $line = <$fd>) {
2064 if ($line =~ m/^([0-9a-fA-F]{40})/){
2068 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2069 my %co = git_read_commit($commit);
2074 print "<tr class=\"dark\">\n";
2076 print "<tr class=\"light\">\n";
2079 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2080 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2081 "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2082 esc_html(chop_str($co{'title'}, 50)) . "</b>") . "</td>\n" .
2083 "<td class=\"link\">" .
2084 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2085 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2086 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2087 my $blob = git_get_hash_by_path($hash, $file_name);
2088 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2089 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2091 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2105 if (!defined $searchtext) {
2106 die_error("", "Text field empty.");
2108 if (!defined $hash) {
2109 $hash = git_read_hash("$project/HEAD");
2111 my %co = git_read_commit($hash);
2113 die_error(undef, "Unknown commit object.");
2115 # pickaxe may take all resources of your box and run for several minutes
2116 # with every query - so decide by yourself how public you make this feature :)
2117 my $commit_search = 1;
2118 my $author_search = 0;
2119 my $committer_search = 0;
2120 my $pickaxe_search = 0;
2121 if ($searchtext =~ s/^author\\://i) {
2123 } elsif ($searchtext =~ s/^committer\\://i) {
2124 $committer_search = 1;
2125 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2127 $pickaxe_search = 1;
2130 print "<div class=\"page_nav\">\n" .
2131 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary;h=$hash")}, "summary") .
2132 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2133 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2134 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2135 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2136 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2141 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2143 print "<table cellspacing=\"0\">\n";
2145 if ($commit_search) {
2147 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2148 while (my $commit_text = <$fd>) {
2149 if (!grep m/$searchtext/i, $commit_text) {
2152 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2155 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2158 my @commit_lines = split "\n", $commit_text;
2159 my %co = git_read_commit(undef, \@commit_lines);
2164 print "<tr class=\"dark\">\n";
2166 print "<tr class=\"light\">\n";
2169 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2170 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2172 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" . esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2173 my $comment = $co{'comment'};
2174 foreach my $line (@$comment) {
2175 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2176 my $lead = esc_html($1) || "";
2177 $lead = chop_str($lead, 30, 10);
2178 my $match = esc_html($2) || "";
2179 my $trail = esc_html($3) || "";
2180 $trail = chop_str($trail, 30, 10);
2181 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
2182 print chop_str($text, 80, 5) . "<br/>\n";
2186 "<td class=\"link\">" .
2187 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2188 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2195 if ($pickaxe_search) {
2197 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2200 while (my $line = <$fd>) {
2201 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2204 $set{'from_id'} = $3;
2206 $set{'id'} = $set{'to_id'};
2207 if ($set{'id'} =~ m/0{40}/) {
2208 $set{'id'} = $set{'from_id'};
2210 if ($set{'id'} =~ m/0{40}/) {
2214 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2217 print "<tr class=\"dark\">\n";
2219 print "<tr class=\"light\">\n";
2222 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2223 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2225 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2226 esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2227 while (my $setref = shift @files) {
2229 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2230 "<span style=\"color:#e00000\">" . esc_html($set{'file'}) . "</span>") .
2234 "<td class=\"link\">" .
2235 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2236 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2240 %co = git_read_commit($1);
2250 my $head = git_read_hash("$project/HEAD");
2251 if (!defined $hash) {
2254 if (!defined $page) {
2258 print "<div class=\"page_nav\">\n" .
2259 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2261 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2262 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2263 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2264 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2266 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2267 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
2268 my (@revlist) = map { chomp; $_ } <$fd>;
2271 if ($hash ne $head || $page) {
2272 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "HEAD");
2278 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
2280 print " ⋅ prev";
2282 if ($#revlist >= (100 * ($page+1)-1)) {
2284 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
2286 print " ⋅ next";
2291 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
2293 print "<table cellspacing=\"0\">\n";
2295 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2296 my $commit = $revlist[$i];
2297 my %co = git_read_commit($commit);
2298 my %ad = date_str($co{'author_epoch'});
2300 print "<tr class=\"dark\">\n";
2302 print "<tr class=\"light\">\n";
2305 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2306 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2308 if (length($co{'title_short'}) < length($co{'title'})) {
2309 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
2310 "<b>" . esc_html($co{'title_short'}) . "</b>");
2312 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
2313 "<b>" . esc_html($co{'title_short'}) . "</b>");
2316 "<td class=\"link\">" .
2317 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2318 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2322 if ($#revlist >= (100 * ($page+1)-1)) {
2325 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title => "Alt-n"}, "next") .