3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
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\ \t\.\/\-\+\#\~\%]/) {
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") {
206 } elsif ($action eq "blame") {
211 die_error(undef, "Unknown action.");
215 # quote unsafe chars, but keep the slash, even when it's not
216 # correct, but quoted slashes look too horrible in bookmarks
219 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
225 # replace invalid utf8 character with SUBSTITUTION sequence
228 $str = decode("utf8", $str, Encode::FB_DEFAULT);
229 $str = escapeHTML($str);
233 # git may return quoted and escaped filenames
236 if ($str =~ m/^"(.*)"$/) {
238 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
243 sub git_header_html {
244 my $status = shift || "200 OK";
248 if (defined $project) {
249 $title .= " - $project";
250 if (defined $action) {
251 $title .= "/$action";
254 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires);
256 <?xml version="1.0" encoding="utf-8"?>
257 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
258 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
259 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
261 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
262 <meta name="robots" content="index, nofollow"/>
263 <title>$title</title>
265 <style type="text/css">
267 font-family: sans-serif; font-size: 12px; border:solid #d9d8d1; border-width:1px;
268 margin:10px; background-color:#ffffff; color:#000000;
271 a:hover, a:visited, a:active { color:#880000; }
272 div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; }
273 div.page_header a:visited, a.header { color:#0000cc; }
274 div.page_header a:hover { color:#880000; }
275 div.page_nav { padding:8px; }
276 div.page_nav a:visited { color:#0000cc; }
277 div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
278 div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
279 div.page_footer_text { float:left; color:#555555; font-style:italic; }
280 div.page_body { padding:8px; }
282 display:block; padding:6px 8px;
283 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
285 a.title:hover { background-color: #d9d8d1; }
286 div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; }
287 div.log_body { padding:8px 8px 8px 150px; }
288 span.age { position:relative; float:left; width:142px; font-style:italic; }
291 font-size:10px; font-family:sans-serif; font-style:normal;
292 position:relative; float:left; width:136px;
294 div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; }
295 a.list { text-decoration:none; color:#000000; }
296 a.list:hover { text-decoration:underline; color:#880000; }
297 a.text { text-decoration:none; color:#0000cc; }
298 a.text:visited { text-decoration:none; color:#880000; }
299 a.text:hover { text-decoration:underline; color:#880000; }
300 table { padding:8px 4px; }
301 th { padding:2px 5px; font-size:12px; text-align:left; }
302 tr.light:hover { background-color:#edece6; }
303 tr.dark { background-color:#f6f6f0; }
304 tr.dark:hover { background-color:#edece6; }
305 td { padding:2px 5px; font-size:12px; vertical-align:top; }
306 td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; }
307 div.pre { font-family:monospace; font-size:12px; white-space:pre; }
308 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
309 div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
310 div.search { margin:4px 8px; position:absolute; top:56px; right:12px }
311 a.linenr { color:#999999; text-decoration:none }
313 float:right; padding:3px 0px; width:35px; line-height:10px;
314 border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
315 color:#ffffff; background-color:#ff6600;
316 font-weight:bold; font-family:sans-serif; font-size:10px;
317 text-align:center; text-decoration:none;
319 a.rss_logo:hover { background-color:#ee5500; }
321 padding:0px 4px; font-size:10px; font-weight:normal;
322 background-color:#ffffaa; border:1px solid; border-color:#ffffcc #ffee00 #ffee00 #ffffcc;
328 print "<div class=\"page_header\">\n" .
329 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
330 "<img src=\"$my_uri?" . esc_param("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
332 print $cgi->a({-href => esc_param($home_link)}, "projects") . " / ";
333 if (defined $project) {
334 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, esc_html($project));
335 if (defined $action) {
339 if (!defined $searchtext) {
344 $search_hash = $hash;
346 $search_hash = "HEAD";
348 $cgi->param("a", "search");
349 $cgi->param("h", $search_hash);
350 print $cgi->startform(-method => "get", -action => $my_uri) .
351 "<div class=\"search\">\n" .
352 $cgi->hidden(-name => "p") . "\n" .
353 $cgi->hidden(-name => "a") . "\n" .
354 $cgi->hidden(-name => "h") . "\n" .
355 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
357 $cgi->end_form() . "\n";
362 sub git_footer_html {
363 print "<div class=\"page_footer\">\n";
364 if (defined $project) {
365 my $descr = git_read_description($project);
366 if (defined $descr) {
367 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
369 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
371 print $cgi->a({-href => "$my_uri?" . esc_param("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
379 my $status = shift || "403 Forbidden";
380 my $error = shift || "Malformed query, file missing or permission denied";
382 git_header_html($status);
383 print "<div class=\"page_body\">\n" .
385 "$status - $error\n" .
395 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
404 my $oENV = $ENV{'GIT_DIR'};
406 $ENV{'GIT_DIR'} = "$projectroot/$project";
407 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
410 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
415 $ENV{'GIT_DIR'} = $oENV;
423 open my $fd, "$projectroot/$path" or return undef;
427 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
432 sub git_read_description {
435 open my $fd, "$projectroot/$path/description" or return undef;
447 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
448 $tag{'id'} = $tag_id;
449 while (my $line = <$fd>) {
451 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
453 } elsif ($line =~ m/^type (.+)$/) {
455 } elsif ($line =~ m/^tag (.+)$/) {
457 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
461 } elsif ($line =~ m/--BEGIN/) {
462 push @comment, $line;
464 } elsif ($line eq "") {
468 push @comment, <$fd>;
469 $tag{'comment'} = \@comment;
471 if (!defined $tag{'name'}) {
481 if ($age > 60*60*24*365*2) {
482 $age_str = (int $age/60/60/24/365);
483 $age_str .= " years ago";
484 } elsif ($age > 60*60*24*(365/12)*2) {
485 $age_str = int $age/60/60/24/(365/12);
486 $age_str .= " months ago";
487 } elsif ($age > 60*60*24*7*2) {
488 $age_str = int $age/60/60/24/7;
489 $age_str .= " weeks ago";
490 } elsif ($age > 60*60*24*2) {
491 $age_str = int $age/60/60/24;
492 $age_str .= " days ago";
493 } elsif ($age > 60*60*2) {
494 $age_str = int $age/60/60;
495 $age_str .= " hours ago";
496 } elsif ($age > 60*2) {
497 $age_str = int $age/60;
498 $age_str .= " min ago";
501 $age_str .= " sec ago";
503 $age_str .= " right now";
508 sub git_read_commit {
509 my $commit_id = shift;
510 my $commit_text = shift;
515 if (defined $commit_text) {
516 @commit_lines = @$commit_text;
519 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
520 @commit_lines = split '\n', <$fd>;
525 my $header = shift @commit_lines;
526 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
529 ($co{'id'}, my @parents) = split ' ', $header;
530 $co{'parents'} = \@parents;
531 $co{'parent'} = $parents[0];
532 while (my $line = shift @commit_lines) {
533 last if $line eq "\n";
534 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
536 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
538 $co{'author_epoch'} = $2;
539 $co{'author_tz'} = $3;
540 if ($co{'author'} =~ m/^([^<]+) </) {
541 $co{'author_name'} = $1;
543 $co{'author_name'} = $co{'author'};
545 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
546 $co{'committer'} = $1;
547 $co{'committer_epoch'} = $2;
548 $co{'committer_tz'} = $3;
549 $co{'committer_name'} = $co{'committer'};
550 $co{'committer_name'} =~ s/ <.*//;
553 if (!defined $co{'tree'}) {
557 foreach my $title (@commit_lines) {
560 $co{'title'} = chop_str($title, 80, 5);
561 # remove leading stuff of merges to make the interesting part visible
562 if (length($title) > 50) {
563 $title =~ s/^Automatic //;
564 $title =~ s/^merge (of|with) /Merge ... /i;
565 if (length($title) > 50) {
566 $title =~ s/(http|rsync):\/\///;
568 if (length($title) > 50) {
569 $title =~ s/(master|www|rsync)\.//;
571 if (length($title) > 50) {
572 $title =~ s/kernel.org:?//;
574 if (length($title) > 50) {
575 $title =~ s/\/pub\/scm//;
578 $co{'title_short'} = chop_str($title, 50, 5);
582 # remove added spaces
583 foreach my $line (@commit_lines) {
586 $co{'comment'} = \@commit_lines;
588 my $age = time - $co{'committer_epoch'};
590 $co{'age_string'} = age_string($age);
591 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
592 if ($age > 60*60*24*7*2) {
593 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
594 $co{'age_string_age'} = $co{'age_string'};
596 $co{'age_string_date'} = $co{'age_string'};
597 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
604 my $from_name = shift;
607 my $format = shift || "html";
609 my $from_tmp = "/dev/null";
610 my $to_tmp = "/dev/null";
613 # create tmp from-file
615 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
616 open my $fd2, "> $from_tmp";
617 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
626 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
627 open my $fd2, "> $to_tmp";
628 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
635 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
636 if ($format eq "plain") {
641 while (my $line = <$fd>) {
643 my $char = substr($line, 0, 1);
646 $color = " style=\"color:#008800;\"";
647 } elsif ($char eq "-") {
648 $color = " style=\"color:#cc0000;\"";
649 } elsif ($char eq "@") {
650 $color = " style=\"color:#990099;\"";
651 } elsif ($char eq "\\") {
655 while ((my $pos = index($line, "\t")) != -1) {
656 if (my $count = (8 - (($pos-1) % 8))) {
657 my $spaces = ' ' x $count;
658 $line =~ s/\t/$spaces/;
661 print "<div class=\"pre\"$color>" . esc_html($line) . "</div>\n";
675 my $mode = oct shift;
677 if (S_ISDIR($mode & S_IFMT)) {
679 } elsif (S_ISLNK($mode)) {
681 } elsif (S_ISREG($mode)) {
682 # git cares only about the executable bit
683 if ($mode & S_IXUSR) {
696 my $add_len = shift || 10;
698 # allow only $len chars, but don't cut a word if it would fit in $add_len
699 # if it doesn't fit, cut it if it's still longer than the dots we would add
700 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
703 if (length($tail) > 4) {
710 my $mode = oct shift;
712 if (S_ISDIR($mode & S_IFMT)) {
714 } elsif (S_ISLNK($mode)) {
716 } elsif (S_ISREG($mode)) {
723 sub format_log_line_html {
726 $line = esc_html($line);
727 $line =~ s/ / /g;
728 if ($line =~ m/([0-9a-fA-F]{40})/) {
730 if (git_get_type($hash_text) eq "commit") {
731 my $link = $cgi->a({-class => "text", -href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_text")}, $hash_text);
732 $line =~ s/$hash_text/$link/;
740 my $tz = shift || "-0000";
743 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
744 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
745 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
746 $date{'hour'} = $hour;
747 $date{'minute'} = $min;
748 $date{'mday'} = $mday;
749 $date{'day'} = $days[$wday];
750 $date{'month'} = $months[$mon];
751 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
752 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
754 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
755 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
756 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
757 $date{'hour_local'} = $hour;
758 $date{'minute_local'} = $min;
759 $date{'tz_local'} = $tz;
763 # git-logo (cached in browser for one day)
765 binmode STDOUT, ':raw';
766 print $cgi->header(-type => 'image/png', -expires => '+1d');
767 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
768 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
769 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
770 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
771 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
772 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
773 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
774 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
775 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
776 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
777 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
778 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
779 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
780 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
786 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
787 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
788 if (!defined $gcos) {
792 $owner =~ s/[,;].*$//;
793 return decode("utf8", $owner, Encode::FB_DEFAULT);
796 sub git_read_projects {
799 if (-d $projects_list) {
800 # search in directory
801 my $dir = $projects_list;
802 opendir my $dh, $dir or return undef;
803 while (my $dir = readdir($dh)) {
804 if (-e "$projectroot/$dir/HEAD") {
812 } elsif (-f $projects_list) {
813 # read from file(url-encoded):
814 # 'git%2Fgit.git Linus+Torvalds'
815 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
816 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
817 open my $fd , $projects_list or return undef;
818 while (my $line = <$fd>) {
820 my ($path, $owner) = split ' ', $line;
821 $path = unescape($path);
822 $owner = unescape($owner);
823 if (!defined $path) {
826 if (-e "$projectroot/$path/HEAD") {
829 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
836 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
840 sub git_project_list {
841 my @list = git_read_projects();
844 die_error(undef, "No project found.");
846 foreach my $pr (@list) {
847 my $head = git_read_head($pr->{'path'});
848 if (!defined $head) {
851 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
852 my %co = git_read_commit($head);
856 $pr->{'commit'} = \%co;
857 if (!defined $pr->{'descr'}) {
858 my $descr = git_read_description($pr->{'path'}) || "";
859 $pr->{'descr'} = chop_str($descr, 25, 5);
861 if (!defined $pr->{'owner'}) {
862 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
868 print "<div class=\"index_include\">\n";
869 open (my $fd, $home_text);
874 print "<table cellspacing=\"0\">\n" .
876 if (!defined($order) || (defined($order) && ($order eq "project"))) {
877 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
878 print "<th>Project</th>\n";
880 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=project")}, "Project") . "</th>\n";
882 if (defined($order) && ($order eq "descr")) {
883 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
884 print "<th>Description</th>\n";
886 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=descr")}, "Description") . "</th>\n";
888 if (defined($order) && ($order eq "owner")) {
889 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
890 print "<th>Owner</th>\n";
892 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=owner")}, "Owner") . "</th>\n";
894 if (defined($order) && ($order eq "age")) {
895 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
896 print "<th>Last Change</th>\n";
898 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=age")}, "Last Change") . "</th>\n";
900 print "<th></th>\n" .
903 foreach my $pr (@projects) {
905 print "<tr class=\"dark\">\n";
907 print "<tr class=\"light\">\n";
910 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
911 "<td>$pr->{'descr'}</td>\n" .
912 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
914 if ($pr->{'commit'}{'age'} < 60*60*2) {
915 $colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>";
916 } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {
917 $colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>";
919 $colored_age = "<i>$pr->{'commit'}{'age_string'}</i>";
921 print "<td>$colored_age</td>\n" .
922 "<td class=\"link\">" .
923 $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") .
924 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") .
925 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") .
934 my $type = shift || "";
936 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
937 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
938 open my $fd, "$projectroot/$project/info/refs" or return;
939 while (my $line = <$fd>) {
941 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\^]+)/) {
942 if (defined $refs{$1}) {
943 $refs{$1} .= " / $2";
958 opendir my $dh, "$projectroot/$project/$ref_dir";
959 while (my $dir = readdir($dh)) {
960 if ($dir =~ m/^\./) {
963 if (-d "$projectroot/$project/$ref_dir/$dir") {
964 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
965 my @subdirs = grep !m/^\./, readdir $dh2;
967 foreach my $subdir (@subdirs) {
968 push @refs, "$dir/$subdir"
975 foreach my $ref_file (@refs) {
976 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
977 my $type = git_get_type($ref_id) || next;
980 $ref_item{'type'} = $type;
981 $ref_item{'id'} = $ref_id;
982 $ref_item{'epoch'} = 0;
983 $ref_item{'age'} = "unknown";
984 if ($type eq "tag") {
985 my %tag = git_read_tag($ref_id);
986 $ref_item{'comment'} = $tag{'comment'};
987 if ($tag{'type'} eq "commit") {
988 %co = git_read_commit($tag{'object'});
989 $ref_item{'epoch'} = $co{'committer_epoch'};
990 $ref_item{'age'} = $co{'age_string'};
991 } elsif (defined($tag{'epoch'})) {
992 my $age = time - $tag{'epoch'};
993 $ref_item{'epoch'} = $tag{'epoch'};
994 $ref_item{'age'} = age_string($age);
996 $ref_item{'reftype'} = $tag{'type'};
997 $ref_item{'name'} = $tag{'name'};
998 $ref_item{'refid'} = $tag{'object'};
999 } elsif ($type eq "commit"){
1000 %co = git_read_commit($ref_id);
1001 $ref_item{'reftype'} = "commit";
1002 $ref_item{'name'} = $ref_file;
1003 $ref_item{'title'} = $co{'title'};
1004 $ref_item{'refid'} = $ref_id;
1005 $ref_item{'epoch'} = $co{'committer_epoch'};
1006 $ref_item{'age'} = $co{'age_string'};
1009 push @reflist, \%ref_item;
1012 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1017 my $descr = git_read_description($project) || "none";
1018 my $head = git_read_head($project);
1019 my %co = git_read_commit($head);
1020 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1023 if (-f $projects_list) {
1024 open (my $fd , $projects_list);
1025 while (my $line = <$fd>) {
1027 my ($pr, $ow) = split ' ', $line;
1028 $pr = unescape($pr);
1029 $ow = unescape($ow);
1030 if ($pr eq $project) {
1031 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
1037 if (!defined $owner) {
1038 $owner = get_file_owner("$projectroot/$project");
1041 my $refs = read_info_ref();
1043 print "<div class=\"page_nav\">\n" .
1045 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1046 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1047 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1048 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1049 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree")}, "tree") .
1052 print "<div class=\"title\"> </div>\n";
1053 print "<table cellspacing=\"0\">\n" .
1054 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
1055 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1056 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1058 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head($project) or die_error(undef, "Open failed.");
1059 my (@revlist) = map { chomp; $_ } <$fd>;
1062 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1065 print "<table cellspacing=\"0\">\n";
1067 foreach my $commit (@revlist) {
1068 my %co = git_read_commit($commit);
1069 my %ad = date_str($co{'author_epoch'});
1071 print "<tr class=\"dark\">\n";
1073 print "<tr class=\"light\">\n";
1078 if (defined $refs->{$commit}) {
1079 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
1081 print "<td><i>$co{'age_string'}</i></td>\n" .
1082 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1084 if (length($co{'title_short'}) < length($co{'title'})) {
1085 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
1086 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
1088 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
1089 "<b>" . esc_html($co{'title'}) . "$ref</b>");
1092 "<td class=\"link\">" .
1093 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1094 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1098 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "...") . "</td>\n" .
1105 my $taglist = git_read_refs("refs/tags");
1106 if (defined @$taglist) {
1108 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags"), -class => "title"}, "tags") .
1111 print "<table cellspacing=\"0\">\n";
1113 foreach my $entry (@$taglist) {
1115 my $comment_lines = $tag{'comment'};
1116 my $comment = shift @$comment_lines;
1117 if (defined($comment)) {
1118 $comment = chop_str($comment, 30, 5);
1121 print "<tr class=\"dark\">\n";
1123 print "<tr class=\"light\">\n";
1127 print "<td><i>$tag{'age'}</i></td>\n" .
1129 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1130 "<b>" . esc_html($tag{'name'}) . "</b>") .
1133 if (defined($comment)) {
1134 print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1137 "<td class=\"link\">";
1138 if ($tag{'type'} eq "tag") {
1139 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1141 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1142 if ($tag{'reftype'} eq "commit") {
1143 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1144 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
1149 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags")}, "...") . "</td>\n" .
1157 my $headlist = git_read_refs("refs/heads");
1158 if (defined @$headlist) {
1160 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads"), -class => "title"}, "heads") .
1163 print "<table cellspacing=\"0\">\n";
1165 foreach my $entry (@$headlist) {
1168 print "<tr class=\"dark\">\n";
1170 print "<tr class=\"light\">\n";
1174 print "<td><i>$tag{'age'}</i></td>\n" .
1176 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1177 "<b>" . esc_html($tag{'name'}) . "</b>") .
1179 "<td class=\"link\">" .
1180 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1181 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1185 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads")}, "...") . "</td>\n" .
1196 my $head = git_read_head($project);
1198 print "<div class=\"page_nav\">\n" .
1199 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1200 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1201 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1202 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1203 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1204 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1207 my %tag = git_read_tag($hash);
1209 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($tag{'name'})) . "\n" .
1211 print "<div class=\"title_text\">\n" .
1212 "<table cellspacing=\"0\">\n" .
1214 "<td>object</td>\n" .
1215 "<td>" . $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1216 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1218 if (defined($tag{'author'})) {
1219 my %ad = date_str($tag{'epoch'}, $tag{'tz'});
1220 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
1221 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1223 print "</table>\n\n" .
1225 print "<div class=\"page_body\">";
1226 my $comment = $tag{'comment'};
1227 foreach my $line (@$comment) {
1228 print esc_html($line) . "<br/>\n";
1236 die_error('404 Not Found', "What file will it be, master?") if (!$file_name);
1237 $hash_base ||= git_read_head($project);
1238 die_error(undef, "Reading commit failed.") unless ($hash_base);
1239 my %co = git_read_commit($hash_base)
1240 or die_error(undef, "Reading commit failed.");
1241 if (!defined $hash) {
1242 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
1243 or die_error(undef, "Error lookup file.");
1245 open ($fd, "-|", "$gitbin/git-annotate", '-l', '-t', '-r', $file_name, $hash_base)
1246 or die_error(undef, "Open failed.");
1248 print "<div class=\"page_nav\">\n" .
1249 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1250 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1251 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1252 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1253 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1254 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1255 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1256 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head") . "<br/>\n";
1259 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
1261 print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n";
1262 print "<div class=\"page_body\">\n";
1264 <table style="border-collapse: collapse;">
1273 my @line_class = (qw(light dark));
1274 my $line_class_len = scalar (@line_class);
1275 my $line_class_num = $#line_class;
1276 while (my $line = <$fd>) {
1288 $line_class_num = ($line_class_num + 1) % $line_class_len;
1290 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1297 print qq( <tr><td colspan="5" style="color: red; background-color: yellow;">Unable to parse: $line</td></tr>\n);
1300 $short_rev = substr ($long_rev, 0, 8);
1301 $age = time () - $time;
1302 $age_str = age_string ($age);
1303 $age_str =~ s/ / /g;
1304 $age_style = 'font-style: italic;';
1305 $age_style .= ' color: #009900; background: transparent;' if ($age < 60*60*24*2);
1306 $age_style .= ' font-weight: bold;' if ($age < 60*60*2);
1307 $author = esc_html ($author);
1308 $author =~ s/ / /g;
1310 while ((my $pos = index($data, "\t")) != -1) {
1311 if (my $count = (8 - ($pos % 8))) {
1312 my $spaces = ' ' x $count;
1313 $data =~ s/\t/$spaces/;
1316 $data = esc_html ($data);
1317 $data =~ s/ / /g;
1320 <tr class="$line_class[$line_class_num]">
1321 <td style="font-family: monospace;"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1322 <td style="$age_style">$age_str</td>
1324 <td style="text-align: right;"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1325 <td style="font-family: monospace;">$data</td>
1328 } # while (my $line = <$fd>)
1329 print "</table>\n\n";
1330 close $fd or print "Reading blob failed.\n";
1336 my $head = git_read_head($project);
1338 print "<div class=\"page_nav\">\n" .
1339 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1340 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1341 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1342 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1343 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1344 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1347 my $taglist = git_read_refs("refs/tags");
1349 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1351 print "<table cellspacing=\"0\">\n";
1353 if (defined @$taglist) {
1354 foreach my $entry (@$taglist) {
1356 my $comment_lines = $tag{'comment'};
1357 my $comment = shift @$comment_lines;
1358 if (defined($comment)) {
1359 $comment = chop_str($comment, 30, 5);
1362 print "<tr class=\"dark\">\n";
1364 print "<tr class=\"light\">\n";
1367 print "<td><i>$tag{'age'}</i></td>\n" .
1369 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1370 "<b>" . esc_html($tag{'name'}) . "</b>") .
1373 if (defined($comment)) {
1374 print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1377 "<td class=\"link\">";
1378 if ($tag{'type'} eq "tag") {
1379 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1381 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1382 if ($tag{'reftype'} eq "commit") {
1383 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1384 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
1395 my $head = git_read_head($project);
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")}, "shortlog") .
1400 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1401 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1402 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1403 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1406 my $taglist = git_read_refs("refs/heads");
1408 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1410 print "<table cellspacing=\"0\">\n";
1412 if (defined @$taglist) {
1413 foreach my $entry (@$taglist) {
1416 print "<tr class=\"dark\">\n";
1418 print "<tr class=\"light\">\n";
1421 print "<td><i>$tag{'age'}</i></td>\n" .
1423 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
1425 "<td class=\"link\">" .
1426 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1427 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1436 sub git_get_hash_by_path {
1438 my $path = shift || return undef;
1441 my @parts = split '/', $path;
1442 while (my $part = shift @parts) {
1443 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1444 my (@entries) = map { chomp; $_ } <$fd>;
1445 close $fd or return undef;
1446 foreach my $line (@entries) {
1447 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1448 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1452 my $t_name = validate_input(unquote($4));
1453 if ($t_name eq $part) {
1457 if ($t_type eq "tree") {
1467 if (!defined $hash && defined $file_name) {
1468 my $base = $hash_base || git_read_head($project);
1469 $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
1471 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1473 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1474 print "<div class=\"page_nav\">\n" .
1475 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1476 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1477 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1478 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1479 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1480 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1481 if (defined $file_name) {
1482 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") .
1483 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1484 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1486 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1490 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
1493 print "<div class=\"page_nav\">\n" .
1494 "<br/><br/></div>\n" .
1495 "<div class=\"title\">$hash</div>\n";
1497 if (defined $file_name) {
1498 print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n";
1500 print "<div class=\"page_body\">\n";
1502 while (my $line = <$fd>) {
1505 while ((my $pos = index($line, "\t")) != -1) {
1506 if (my $count = (8 - ($pos % 8))) {
1507 my $spaces = ' ' x $count;
1508 $line =~ s/\t/$spaces/;
1511 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line);
1513 close $fd or print "Reading blob failed.\n";
1518 sub git_blob_plain {
1519 my $save_as = "$hash.txt";
1520 if (defined $file_name) {
1521 $save_as = $file_name;
1523 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"$save_as\"");
1524 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1532 if (!defined $hash) {
1533 $hash = git_read_head($project);
1534 if (defined $file_name) {
1535 my $base = $hash_base || $hash;
1536 $hash = git_get_hash_by_path($base, $file_name, "tree");
1538 if (!defined $hash_base) {
1543 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error(undef, "Open git-ls-tree failed.");
1544 chomp (my (@entries) = <$fd>);
1545 close $fd or die_error(undef, "Reading tree failed.");
1548 my $refs = read_info_ref();
1550 if (defined $refs->{$hash_base}) {
1551 $ref = " <span class=\"tag\">" . esc_html($refs->{$hash_base}) . "</span>";
1556 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1557 $base_key = ";hb=$hash_base";
1558 print "<div class=\"page_nav\">\n" .
1559 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1560 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1561 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash_base")}, "log") .
1562 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1563 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1568 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
1571 print "<div class=\"page_nav\">\n";
1572 print "<br/><br/></div>\n";
1573 print "<div class=\"title\">$hash</div>\n";
1575 if (defined $file_name) {
1576 $base = esc_html("$file_name/");
1577 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n";
1579 print "<div class=\"page_path\"><b>/</b></div>\n";
1581 print "<div class=\"page_body\">\n";
1582 print "<table cellspacing=\"0\">\n";
1584 foreach my $line (@entries) {
1585 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1586 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1590 my $t_name = validate_input($4);
1592 print "<tr class=\"dark\">\n";
1594 print "<tr class=\"light\">\n";
1597 print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n";
1598 if ($t_type eq "blob") {
1599 print "<td class=\"list\">" .
1600 $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)) .
1602 "<td class=\"link\">" .
1603 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1604 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1605 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1607 } elsif ($t_type eq "tree") {
1608 print "<td class=\"list\">" .
1609 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html($t_name)) .
1611 "<td class=\"link\">" .
1612 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1617 print "</table>\n" .
1623 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1624 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed.");
1625 my (@revlist) = map { chomp; $_ } <$fd>;
1626 close $fd or die_error(undef, "Reading rev-list failed.");
1627 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1628 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1629 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1630 print "<channel>\n";
1631 print "<title>$project</title>\n".
1632 "<link>" . esc_html("$my_url?p=$project;a=summary") . "</link>\n".
1633 "<description>$project log</description>\n".
1634 "<language>en</language>\n";
1636 for (my $i = 0; $i <= $#revlist; $i++) {
1637 my $commit = $revlist[$i];
1638 my %co = git_read_commit($commit);
1639 # we read 150, we always show 30 and the ones more recent than 48 hours
1640 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1643 my %cd = date_str($co{'committer_epoch'});
1644 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1645 my @difftree = map { chomp; $_ } <$fd>;
1649 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
1651 "<author>" . esc_html($co{'author'}) . "</author>\n" .
1652 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1653 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1654 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1655 "<description>" . esc_html($co{'title'}) . "</description>\n" .
1656 "<content:encoded>" .
1658 my $comment = $co{'comment'};
1659 foreach my $line (@$comment) {
1660 $line = decode("utf8", $line, Encode::FB_DEFAULT);
1661 print "$line<br/>\n";
1664 foreach my $line (@difftree) {
1665 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1668 my $file = validate_input(unquote($7));
1669 $file = decode("utf8", $file, Encode::FB_DEFAULT);
1670 print "$file<br/>\n";
1673 "</content:encoded>\n" .
1676 print "</channel></rss>";
1680 my @list = git_read_projects();
1682 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1683 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1684 "<opml version=\"1.0\">\n".
1686 " <title>Git OPML Export</title>\n".
1689 "<outline text=\"git RSS feeds\">\n";
1691 foreach my $pr (@list) {
1693 my $head = git_read_head($proj{'path'});
1694 if (!defined $head) {
1697 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1698 my %co = git_read_commit($head);
1703 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
1704 my $rss = "$my_url?p=$proj{'path'};a=rss";
1705 my $html = "$my_url?p=$proj{'path'};a=summary";
1706 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1708 print "</outline>\n".
1714 my $head = git_read_head($project);
1715 if (!defined $hash) {
1718 if (!defined $page) {
1721 my $refs = read_info_ref();
1723 print "<div class=\"page_nav\">\n";
1724 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1725 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1727 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
1728 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1729 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1731 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1732 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1733 my (@revlist) = map { chomp; $_ } <$fd>;
1736 if ($hash ne $head || $page) {
1737 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "HEAD");
1743 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
1745 print " ⋅ prev";
1747 if ($#revlist >= (100 * ($page+1)-1)) {
1749 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
1751 print " ⋅ next";
1757 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1759 my %co = git_read_commit($hash);
1760 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1762 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1763 my $commit = $revlist[$i];
1765 if (defined $refs->{$commit}) {
1766 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
1768 my %co = git_read_commit($commit);
1770 my %ad = date_str($co{'author_epoch'});
1772 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "title"},
1773 "<span class=\"age\">$co{'age_string'}</span>" . esc_html($co{'title'}) . $ref) . "\n";
1775 print "<div class=\"title_text\">\n" .
1776 "<div class=\"log_link\">\n" .
1777 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1778 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1781 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1783 "<div class=\"log_body\">\n";
1784 my $comment = $co{'comment'};
1786 foreach my $line (@$comment) {
1787 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1798 print format_log_line_html($line) . "<br/>\n";
1809 my %co = git_read_commit($hash);
1811 die_error(undef, "Unknown commit object.");
1813 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1814 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1818 my $parent = $co{'parent'};
1819 if (!defined $parent) {
1823 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed.");
1824 @difftree = map { chomp; $_ } <$fd>;
1825 close $fd or die_error(undef, "Reading diff-tree failed.");
1827 # non-textual hash id's can be cached
1829 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1832 my $refs = read_info_ref();
1834 if (defined $refs->{$co{'id'}}) {
1835 $ref = " <span class=\"tag\">" . esc_html($refs->{$co{'id'}}) . "</span>";
1837 git_header_html(undef, $expires);
1838 print "<div class=\"page_nav\">\n" .
1839 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1840 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1841 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
1843 if (defined $co{'parent'}) {
1844 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1846 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1847 "<br/><br/></div>\n";
1848 if (defined $co{'parent'}) {
1850 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
1854 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1857 print "<div class=\"title_text\">\n" .
1858 "<table cellspacing=\"0\">\n";
1859 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
1861 "<td></td><td> $ad{'rfc2822'}";
1862 if ($ad{'hour_local'} < 6) {
1863 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1865 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1869 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
1870 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1871 print "<tr><td>commit</td><td style=\"font-family:monospace\">$co{'id'}</td></tr>\n";
1874 "<td style=\"font-family:monospace\">" .
1875 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1877 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1880 my $parents = $co{'parents'};
1881 foreach my $par (@$parents) {
1884 "<td style=\"font-family:monospace\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1885 "<td class=\"link\">" .
1886 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par")}, "commit") .
1887 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1893 print "<div class=\"page_body\">\n";
1894 my $comment = $co{'comment'};
1897 foreach my $line (@$comment) {
1898 # print only one empty line
1900 if ($empty || $signed) {
1907 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1909 print "<span style=\"color: #888888\">" . esc_html($line) . "</span><br/>\n";
1912 print format_log_line_html($line) . "<br/>\n";
1916 print "<div class=\"list_head\">\n";
1917 if ($#difftree > 10) {
1918 print(($#difftree + 1) . " files changed:\n");
1921 print "<table cellspacing=\"0\">\n";
1923 foreach my $line (@difftree) {
1924 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1925 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1926 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1934 my $similarity = $6;
1935 my $file = validate_input(unquote($7));
1937 print "<tr class=\"dark\">\n";
1939 print "<tr class=\"light\">\n";
1942 if ($status eq "A") {
1944 if (S_ISREG(oct $to_mode)) {
1945 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1948 $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" .
1949 "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1950 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
1951 } elsif ($status eq "D") {
1953 $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" .
1954 "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1955 "<td class=\"link\">" .
1956 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
1957 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") .
1959 } elsif ($status eq "M" || $status eq "T") {
1960 my $mode_chnge = "";
1961 if ($from_mode != $to_mode) {
1962 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1963 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1964 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1966 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1967 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1968 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1969 } elsif (S_ISREG($to_mode)) {
1970 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1973 $mode_chnge .= "]</span>\n";
1976 if ($to_id ne $from_id) {
1977 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));
1979 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
1982 "<td>$mode_chnge</td>\n" .
1983 "<td class=\"link\">";
1984 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
1985 if ($to_id ne $from_id) {
1986 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
1988 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
1990 } elsif ($status eq "R") {
1991 my ($from_file, $to_file) = split "\t", $file;
1993 if ($from_mode != $to_mode) {
1994 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1997 $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" .
1998 "<td><span style=\"color: #777777;\">[moved from " .
1999 $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)) .
2000 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2001 "<td class=\"link\">" .
2002 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2003 if ($to_id ne $from_id) {
2004 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2015 mkdir($git_temp, 0700);
2017 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
2018 print "<div class=\"page_nav\">\n" .
2019 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2020 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2021 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
2022 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
2023 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
2024 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
2026 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
2029 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2032 print "<div class=\"page_nav\">\n" .
2033 "<br/><br/></div>\n" .
2034 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2036 if (defined $file_name) {
2037 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n";
2039 print "<div class=\"page_body\">\n" .
2040 "<div class=\"diff_info\">blob:" .
2041 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2043 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2045 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2050 sub git_blobdiff_plain {
2051 mkdir($git_temp, 0700);
2052 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
2053 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2056 sub git_commitdiff {
2057 mkdir($git_temp, 0700);
2058 my %co = git_read_commit($hash);
2060 die_error(undef, "Unknown commit object.");
2062 if (!defined $hash_parent) {
2063 $hash_parent = $co{'parent'};
2065 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
2066 my (@difftree) = map { chomp; $_ } <$fd>;
2067 close $fd or die_error(undef, "Reading diff-tree failed.");
2069 # non-textual hash id's can be cached
2071 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2074 my $refs = read_info_ref();
2076 if (defined $refs->{$co{'id'}}) {
2077 $ref = " <span class=\"tag\">" . esc_html($refs->{$co{'id'}}) . "</span>";
2079 git_header_html(undef, $expires);
2080 print "<div class=\"page_nav\">\n" .
2081 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2082 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
2083 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2084 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2086 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
2087 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
2090 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
2092 print "<div class=\"page_body\">\n";
2093 my $comment = $co{'comment'};
2096 my @log = @$comment;
2097 # remove first and empty lines after that
2099 while (defined $log[0] && $log[0] eq "") {
2102 foreach my $line (@log) {
2103 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2114 print format_log_line_html($line) . "<br/>\n";
2117 foreach my $line (@difftree) {
2118 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2119 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2120 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2126 my $file = validate_input(unquote($6));
2127 if ($status eq "A") {
2128 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
2129 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2131 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
2132 } elsif ($status eq "D") {
2133 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
2134 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2136 git_diff_print($from_id, "a/$file", undef, "/dev/null");
2137 } elsif ($status eq "M") {
2138 if ($from_id ne $to_id) {
2139 print "<div class=\"diff_info\">" .
2140 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2142 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2144 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
2153 sub git_commitdiff_plain {
2154 mkdir($git_temp, 0700);
2155 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
2156 my (@difftree) = map { chomp; $_ } <$fd>;
2157 close $fd or die_error(undef, "Reading diff-tree failed.");
2159 # try to figure out the next tag after this commit
2161 my $refs = read_info_ref("tags");
2162 open $fd, "-|", "$gitbin/git-rev-list HEAD";
2163 chomp (my (@commits) = <$fd>);
2165 foreach my $commit (@commits) {
2166 if (defined $refs->{$commit}) {
2167 $tagname = $refs->{$commit}
2169 if ($commit eq $hash) {
2174 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2175 my %co = git_read_commit($hash);
2176 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
2177 my $comment = $co{'comment'};
2178 print "From: $co{'author'}\n" .
2179 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2180 "Subject: $co{'title'}\n";
2181 if (defined $tagname) {
2182 print "X-Git-Tag: $tagname\n";
2184 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2187 foreach my $line (@$comment) {;
2192 foreach my $line (@difftree) {
2193 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2198 if ($status eq "A") {
2199 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
2200 } elsif ($status eq "D") {
2201 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
2202 } elsif ($status eq "M") {
2203 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
2209 if (!defined $hash) {
2210 $hash = git_read_head($project);
2212 my %co = git_read_commit($hash);
2214 die_error(undef, "Unknown commit object.");
2216 my $refs = read_info_ref();
2218 print "<div class=\"page_nav\">\n" .
2219 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2220 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2221 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
2222 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2223 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2224 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2228 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2230 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b><br/></div>\n";
2232 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -- \'$file_name\'";
2234 print "<table cellspacing=\"0\">\n";
2236 while (my $line = <$fd>) {
2237 if ($line =~ m/^([0-9a-fA-F]{40})/){
2241 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2242 my %co = git_read_commit($commit);
2247 if (defined $refs->{$commit}) {
2248 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
2251 print "<tr class=\"dark\">\n";
2253 print "<tr class=\"light\">\n";
2256 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2257 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2258 "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2259 esc_html(chop_str($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2260 "<td class=\"link\">" .
2261 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2262 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2263 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2264 my $blob = git_get_hash_by_path($hash, $file_name);
2265 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2266 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2268 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2282 if (!defined $searchtext) {
2283 die_error("", "Text field empty.");
2285 if (!defined $hash) {
2286 $hash = git_read_head($project);
2288 my %co = git_read_commit($hash);
2290 die_error(undef, "Unknown commit object.");
2292 # pickaxe may take all resources of your box and run for several minutes
2293 # with every query - so decide by yourself how public you make this feature :)
2294 my $commit_search = 1;
2295 my $author_search = 0;
2296 my $committer_search = 0;
2297 my $pickaxe_search = 0;
2298 if ($searchtext =~ s/^author\\://i) {
2300 } elsif ($searchtext =~ s/^committer\\://i) {
2301 $committer_search = 1;
2302 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2304 $pickaxe_search = 1;
2307 print "<div class=\"page_nav\">\n" .
2308 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary;h=$hash")}, "summary") .
2309 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2310 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2311 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2312 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2313 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2318 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2320 print "<table cellspacing=\"0\">\n";
2322 if ($commit_search) {
2324 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2325 while (my $commit_text = <$fd>) {
2326 if (!grep m/$searchtext/i, $commit_text) {
2329 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2332 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2335 my @commit_lines = split "\n", $commit_text;
2336 my %co = git_read_commit(undef, \@commit_lines);
2341 print "<tr class=\"dark\">\n";
2343 print "<tr class=\"light\">\n";
2346 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2347 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2349 $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/>");
2350 my $comment = $co{'comment'};
2351 foreach my $line (@$comment) {
2352 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2353 my $lead = esc_html($1) || "";
2354 $lead = chop_str($lead, 30, 10);
2355 my $match = esc_html($2) || "";
2356 my $trail = esc_html($3) || "";
2357 $trail = chop_str($trail, 30, 10);
2358 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
2359 print chop_str($text, 80, 5) . "<br/>\n";
2363 "<td class=\"link\">" .
2364 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2365 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2372 if ($pickaxe_search) {
2374 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2377 while (my $line = <$fd>) {
2378 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2381 $set{'from_id'} = $3;
2383 $set{'id'} = $set{'to_id'};
2384 if ($set{'id'} =~ m/0{40}/) {
2385 $set{'id'} = $set{'from_id'};
2387 if ($set{'id'} =~ m/0{40}/) {
2391 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2394 print "<tr class=\"dark\">\n";
2396 print "<tr class=\"light\">\n";
2399 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2400 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2402 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2403 esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2404 while (my $setref = shift @files) {
2406 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2407 "<span style=\"color:#e00000\">" . esc_html($set{'file'}) . "</span>") .
2411 "<td class=\"link\">" .
2412 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2413 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2417 %co = git_read_commit($1);
2427 my $head = git_read_head($project);
2428 if (!defined $hash) {
2431 if (!defined $page) {
2434 my $refs = read_info_ref();
2436 print "<div class=\"page_nav\">\n" .
2437 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2439 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2440 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2441 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2442 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2444 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2445 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
2446 my (@revlist) = map { chomp; $_ } <$fd>;
2449 if ($hash ne $head || $page) {
2450 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "HEAD");
2456 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
2458 print " ⋅ prev";
2460 if ($#revlist >= (100 * ($page+1)-1)) {
2462 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
2464 print " ⋅ next";
2469 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
2471 print "<table cellspacing=\"0\">\n";
2473 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2474 my $commit = $revlist[$i];
2476 if (defined $refs->{$commit}) {
2477 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
2479 my %co = git_read_commit($commit);
2480 my %ad = date_str($co{'author_epoch'});
2482 print "<tr class=\"dark\">\n";
2484 print "<tr class=\"light\">\n";
2487 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2488 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2490 if (length($co{'title_short'}) < length($co{'title'})) {
2491 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
2492 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
2494 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
2495 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
2498 "<td class=\"link\">" .
2499 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2500 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2504 if ($#revlist >= (100 * ($page+1)-1)) {
2507 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title => "Alt-n"}, "next") .