3 # gitweb.pl - 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 GPL v2, or a later version
12 use CGI qw(:standard :escapeHTML);
13 use CGI::Carp qw(fatalsToBrowser);
18 my $my_url = $cgi->url();
19 my $my_uri = $cgi->url(-absolute => 1);
22 # absolute fs-path which will be prepended to the project path
23 my $projectroot = "/pub/scm";
25 # location of the git-core binaries
26 my $gitbin = "/usr/bin";
28 # location for temporary files needed for diffs
29 my $gittmp = "/tmp/gitweb";
31 # target of the home link on top of all pages
32 #my $home_link = $my_uri;
33 my $home_link = "/git";
35 # source of projects list
36 #my $projects_list = $projectroot;
37 my $projects_list = "index/index.txt";
39 # input validation and dispatch
40 my $action = $cgi->param('a');
41 if (defined $action) {
42 if ($action =~ m/[^0-9a-zA-Z\.\-]+/) {
44 die_error(undef, "Invalid action parameter.");
46 if ($action eq "git-logo.png") {
54 my $project = $cgi->param('p');
55 if (defined $project) {
56 if ($project =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
58 die_error(undef, "Non-canonical project parameter.");
60 if ($project =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~]/) {
62 die_error(undef, "Invalid character in project parameter.");
64 if (!(-d "$projectroot/$project")) {
66 die_error(undef, "No such directory.");
68 if (!(-e "$projectroot/$project/HEAD")) {
70 die_error(undef, "No such project.");
72 $rss_link = "<link rel=\"alternate\" title=\"$project log\" href=\"$my_uri?p=$project;a=rss\" type=\"application/rss+xml\"/>";
73 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
75 git_project_list($projects_list);
79 my $file_name = $cgi->param('f');
80 if (defined $file_name) {
81 if ($file_name =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
83 die_error(undef, "Non-canonical file parameter.");
85 if ($file_name =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~\:\!]/) {
87 die_error(undef, "Invalid character in file parameter.");
91 my $hash = $cgi->param('h');
92 if (defined $hash && !($hash =~ m/^[0-9a-fA-F]{40}$/)) {
94 die_error(undef, "Invalid hash parameter.");
97 my $hash_parent = $cgi->param('hp');
98 if (defined $hash_parent && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
100 die_error(undef, "Invalid hash_parent parameter.");
103 my $hash_base = $cgi->param('hb');
104 if (defined $hash_base && !($hash_base =~ m/^[0-9a-fA-F]{40}$/)) {
106 die_error(undef, "Invalid parent hash parameter.");
109 my $time_back = $cgi->param('t');
110 if (defined $time_back) {
111 if ($time_back =~ m/^[^0-9]+$/) {
113 die_error(undef, "Invalid time parameter.");
117 if ($action eq "blob") {
120 } elsif ($action eq "tree") {
123 } elsif ($action eq "rss") {
126 } elsif ($action eq "commit") {
129 } elsif ($action eq "log") {
132 } elsif ($action eq "blobdiff") {
135 } elsif ($action eq "commitdiff") {
138 } elsif ($action eq "history") {
143 die_error(undef, "Unknown action.");
147 sub git_header_html {
148 my $status = shift || "200 OK";
151 if (defined $project) {
152 $title .= " - $project";
153 if (defined $action) {
154 $title .= "/$action";
157 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status);
159 <?xml version="1.0" encoding="utf-8"?>
160 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
161 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
162 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
164 <title>$title</title>
166 <style type="text/css">
167 body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
169 a:hover, a:visited, a:active { color:#880000; }
170 div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; }
171 div.page_header a:visited { color:#0000cc; }
172 div.page_header a:hover { color:#880000; }
173 div.page_nav { padding:8px; }
174 div.page_nav a:visited { color:#0000cc; }
175 div.page_path { font-weight:bold; padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
176 div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
177 div.page_footer_text { float:left; color:#555555; font-style:italic; }
178 div.page_body { padding:8px; }
180 display:block; padding:6px 8px;
181 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
183 a.title:hover { background-color: #d9d8d1; }
184 div.title_text { padding:6px 8px; border: solid #d9d8d1; border-width:0px 0px 1px; }
185 div.log_body { padding:8px 8px 8px 150px; }
186 span.log_age { position:relative; float:left; width:142px; font-style:italic; }
188 font-size:10px; font-family:sans-serif; font-style:normal;
189 position:relative; float:left; width:142px;
191 div.list { display:block; padding:4px 8px 2px; font-weight:bold; }
193 display:block; padding:6px 6px 4px; border:solid #d9d8d1;
194 border-width:0px 0px 1px; font-style:italic;
196 div.list a { text-decoration:none; color:#000000; }
197 div.list a:hover { color:#880000; }
199 padding:4px 8px 6px; border:solid #d9d8d1; border-width:0px 0px 1px;
200 font-family:sans-serif; font-size:10px;
202 td { padding:5px 15px 0px 0px; font-size:12px; }
203 th { padding-right:10px; font-size:12px; text-align:left; }
204 td.link { font-family:sans-serif; font-size:10px; }
205 td.pre { font-family:monospace; font-size:12px; white-space:pre; padding:2px 15px 0px 0px; }
206 div.pre { font-family:monospace; font-size:12px; white-space:pre; }
207 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
208 a.rss_logo { float:right; padding:3px 0px; width:35px; line-height:10px;
209 border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
210 color:#ffffff; background-color:#ff6600;
211 font-weight:bold; font-family:sans-serif; font-size:10px;
212 text-align:center; text-decoration:none;
214 a.rss_logo:hover { background-color:#ee5500; }
219 print "<div class=\"page_header\">\n" .
220 "<a href=\"http://kernel.org/pub/software/scm/cogito\">" .
221 "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
222 print $cgi->a({-href => $home_link}, "projects") . " / ";
223 if (defined $project) {
224 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, escapeHTML($project));
225 if (defined $action) {
232 sub git_footer_html {
233 print "<div class=\"page_footer\">\n";
234 if (defined $project) {
235 my $descr = git_read_description($project);
236 if (defined $descr) {
237 print "<div class=\"page_footer_text\">" . escapeHTML($descr) . "</div>\n";
239 print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
247 my $status = shift || "403 Forbidden";
248 my $error = shift || "Malformed query, file missing or permission denied";
250 git_header_html($status);
251 print "<div class=\"page_body\">\n" .
253 print "$status - $error\n";
254 print "<br/></div>\n";
262 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" || return;
272 open my $fd, "$projectroot/$path/HEAD" || return undef;
276 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
283 sub git_read_description {
286 open my $fd, "$projectroot/$path/description" || return undef;
293 sub git_read_commit {
298 open my $fd, "-|", "$gitbin/git-cat-file commit $commit" || return;
299 while (my $line = <$fd>) {
300 last if $line eq "\n";
302 if ($line =~ m/^tree (.*)$/) {
304 } elsif ($line =~ m/^parent (.*)$/) {
306 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
308 $co{'author_epoch'} = $2;
309 $co{'author_tz'} = $3;
310 $co{'author_name'} = $co{'author'};
311 $co{'author_name'} =~ s/ <.*//;
312 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
313 $co{'committer'} = $1;
314 $co{'committer_epoch'} = $2;
315 $co{'committer_tz'} = $3;
316 $co{'committer_name'} = $co{'committer'};
317 $co{'committer_name'} =~ s/ <.*//;
320 $co{'parents'} = \@parents;
321 $co{'parent'} = $parents[0];
322 my (@comment) = map { chomp; $_ } <$fd>;
323 $co{'comment'} = \@comment;
324 $comment[0] =~ m/^(.{0,60}[^ ]*)/;
326 if ($comment[0] ne $co{'title'}) {
327 $co{'title'} .= " [...]";
330 if (!defined $co{'tree'}) {
334 my $age = time - $co{'committer_epoch'};
336 if ($age > 60*60*24*365*2) {
337 $co{'age_string'} = (int $age/60/60/24/365);
338 $co{'age_string'} .= " years ago";
339 } elsif ($age > 60*60*24*365/12*2) {
340 $co{'age_string'} = int $age/60/60/24/365/12;
341 $co{'age_string'} .= " months ago";
342 } elsif ($age > 60*60*24*7*2) {
343 $co{'age_string'} = int $age/60/60/24/7;
344 $co{'age_string'} .= " weeks ago";
345 } elsif ($age > 60*60*24*2) {
346 $co{'age_string'} = int $age/60/60/24;
347 $co{'age_string'} .= " days ago";
348 } elsif ($age > 60*60*2) {
349 $co{'age_string'} = int $age/60/60;
350 $co{'age_string'} .= " hours ago";
351 } elsif ($age > 60*2) {
352 $co{'age_string'} = int $age/60;
353 $co{'age_string'} .= " minutes ago";
355 $co{'age_string'} = int $age;
356 $co{'age_string'} .= " seconds ago";
358 $co{'age_string'} .= " right now";
365 my $from_name = shift;
369 my $from_tmp = "/dev/null";
370 my $to_tmp = "/dev/null";
373 # create tmp from-file
375 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
376 open my $fd2, "> $from_tmp";
377 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
386 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
387 open my $fd2, "> $to_tmp";
388 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
395 open my $fd, "-|", "/usr/bin/diff -u -p -L $from_name -L $to_name $from_tmp $to_tmp";
396 while (my $line = <$fd>) {
398 my $char = substr($line, 0, 1);
401 $color = " style=\"color:#008800;\"";
402 } elsif ($char eq '-') {
403 $color = " style=\"color:#cc0000;\"";
404 } elsif ($char eq '@') {
405 $color = " style=\"color:#990099;\"";
406 } elsif ($char eq '\\') {
410 print "<div class=\"pre\"$color>" . escapeHTML($line) . "</div>\n";
423 my $mode = oct shift;
425 if (S_ISDIR($mode & S_IFMT)) {
427 } elsif (S_ISLNK($mode)) {
429 } elsif (S_ISREG($mode)) {
430 # git cares only about the executable bit
431 if ($mode & S_IXUSR) {
442 my $mode = oct shift;
444 if (S_ISDIR($mode & S_IFMT)) {
446 } elsif (S_ISLNK($mode)) {
448 } elsif (S_ISREG($mode)) {
457 my $tz = shift || "-0000";
460 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
461 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
462 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
463 $date{'hour'} = $hour;
464 $date{'minute'} = $min;
465 $date{'mday'} = $mday;
466 $date{'day'} = $days[$wday];
467 $date{'month'} = $months[$mon];
468 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
469 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
471 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
472 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
473 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
474 $date{'hour_local'} = $hour;
475 $date{'minute_local'} = $min;
476 $date{'tz_local'} = $tz;
480 # git-logo (cached in browser for one day)
482 print $cgi->header(-type => 'image/png', -expires => '+1d');
483 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
484 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
485 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
486 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
487 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
488 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
489 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
490 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
491 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
492 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
493 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
494 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
495 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
496 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
502 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
503 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
504 if (!defined $gcos) {
508 $owner =~ s/[,;].*$//;
512 sub git_project_list {
513 my $project_list = shift;
516 if (-d $project_list) {
517 # search in directory
518 my $dir = $project_list;
519 opendir my $dh, $dir || return undef;
520 while (my $dir = readdir($dh)) {
521 if (-e "$projectroot/$dir/HEAD") {
529 } elsif (-e $project_list) {
531 # 'git/git.git:Linus Torvalds'
532 # 'linux/hotplug/udev.git'
533 open my $fd , $project_list || return undef;
534 while (my $line = <$fd>) {
536 my ($path, $owner) = split ':', $line;
537 if (!defined $path) {
540 if (-e "$projectroot/$path/HEAD") {
552 die_error(undef, "No project found.");
554 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
557 print "<div class=\"page_body\"><br/>\n";
558 print "<table cellspacing=\"0\">\n";
560 "<th>Project</th>\n" .
561 "<th>Description</th>\n" .
563 "<th>last change</th>\n" .
565 foreach my $pr (@list) {
567 my $head = git_read_head($proj{'path'});
568 if (!defined $head) {
571 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$proj{'path'}/objects";
572 my %co = git_read_commit($head);
576 my $descr = git_read_description($proj{'path'}) || "";
577 # get directory owner if not already specified
578 if (!defined $proj{'owner'}) {
579 $proj{'owner'} = get_file_owner("$projectroot/$proj{'path'}") || "";
582 "<td>" . $cgi->a({-href => "$my_uri?p=" . $proj{'path'} . ";a=log"}, escapeHTML($proj{'path'})) . "</td>\n" .
583 "<td>$descr</td>\n" .
584 "<td><i>$proj{'owner'}</i></td>\n";
585 if ($co{'age'} < 60*60*2) {
586 print "<td><span style =\"color: #009900;\"><b><i>$co{'age_string'}</i></b></span></td>\n";
587 } elsif ($co{'age'} < 60*60*24*2) {
588 print "<td><span style =\"color: #009900;\"><i>$co{'age_string'}</i></span></td>\n";
590 print "<td><i>$co{'age_string'}</i></td>\n";
600 sub git_get_hash_by_path {
605 my @parts = split '/', $path;
606 while (my $part = shift @parts) {
607 open my $fd, "-|", "$gitbin/git-ls-tree $tree" || die_error(undef, "Open git-ls-tree failed.");
608 my (@entries) = map { chomp; $_ } <$fd>;
609 close $fd || return undef;
610 foreach my $line (@entries) {
611 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
612 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
617 if ($t_name eq $part) {
621 if ($t_type eq "tree") {
631 if (!defined $hash && defined $file_name) {
632 my $base = $hash_base || git_read_head($project);
633 $hash = git_get_hash_by_path($base, $file_name, "blob");
635 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" || die_error(undef, "Open failed.");
636 my $base = $file_name || "";
638 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
639 print "<div class=\"page_nav\">\n" .
640 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
641 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
642 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash_base"}, "tree");
643 if (defined $file_name) {
644 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base;f=$file_name"}, "history");
646 print "<br/><br/>\n" .
649 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) .
652 print "<div class=\"page_nav\">\n" .
653 "<br/><br/></div>\n" .
654 "<div class=\"title\">$hash</div>\n";
656 if (defined $file_name) {
657 print "<div class=\"page_path\">/$file_name</div>\n";
659 print "<div class=\"page_body\">\n";
661 while (my $line = <$fd>) {
664 print "<div class=\"pre\">";
665 printf "<span style=\"color:#999999;\">%4i</span>", $nr;
666 print " " .escapeHTML($line) . "</div>\n";
668 close $fd || print "Reading blob failed.\n";
674 if (!defined $hash) {
675 $hash = git_read_head($project);
676 if (defined $file_name) {
677 my $base = $hash_base || git_read_head($project);
678 $hash = git_get_hash_by_path($base, $file_name, "tree");
681 open my $fd, "-|", "$gitbin/git-ls-tree $hash" || die_error(undef, "Open git-ls-tree failed.");
682 my (@entries) = map { chomp; $_ } <$fd>;
683 close $fd || die_error(undef, "Reading tree failed.");
689 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
690 $base_key = ";hb=$hash_base";
691 print "<div class=\"page_nav\">\n" .
692 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") . " | " .
693 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") . " | " .
694 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash_base"}, "tree") .
698 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
701 print "<div class=\"page_nav\">\n";
702 print "<br/><br/></div>\n";
703 print "<div class=\"title\">$hash</div>\n";
705 if (defined $file_name) {
706 $base = "$file_name/";
707 print "<div class=\"page_path\">/$file_name</div>\n";
709 print "<div class=\"page_path\">/</div>\n";
711 print "<div class=\"page_body\">\n";
712 print "<table cellspacing=\"0\">\n";
713 foreach my $line (@entries) {
714 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
715 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
720 $file_key = ";f=$base$t_name";
722 "<td class=\"pre\">" . mode_str($t_mode) . "</td>\n";
723 if ($t_type eq "blob") {
724 print "<td class=\"pre\">$t_name</td>\n";
725 print "<td class=\"link\">" .
726 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key}, "blob") .
727 " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base" . $file_key}, "history") .
729 } elsif ($t_type eq "tree") {
730 print "<td class=\"pre\">" .
731 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key}, $t_name) .
742 open my $fd, "-|", "$gitbin/git-rev-list --max-count=20 " . git_read_head($project) || die_error(undef, "Open failed.");
743 my (@revlist) = map { chomp; $_ } <$fd>;
744 close $fd || die_error(undef, "Reading rev-list failed.");
746 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
747 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
748 "<rss version=\"0.91\">\n";
750 print "<title>$project</title>\n".
751 "<link> " . $my_url . "/$project/log</link>\n".
752 "<description>$project log</description>\n".
753 "<language>en</language>\n";
755 foreach my $commit (@revlist) {
756 my %co = git_read_commit($commit);
757 my %ad = date_str($co{'author_epoch'});
759 "\t<title>" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'minute'}) . " - " . escapeHTML($co{'title'}) . "</title>\n" .
760 "\t<link> " . $my_url . "?p=$project;a=commit;h=$commit</link>\n" .
762 my $comment = $co{'comment'};
763 foreach my $line (@$comment) {
764 print escapeHTML($line) . "<br/>\n";
766 print "\t</description>\n" .
769 print "</channel></rss>";
773 my $head = git_read_head($project);
774 my $limit_option = "";
775 if (!defined $time_back) {
776 $limit_option = "--max-count=10";
777 } elsif ($time_back > 0) {
778 my $date = time - $time_back*24*60*60;
779 $limit_option = "--max-age=$date";
781 open my $fd, "-|", "$gitbin/git-rev-list $limit_option $head" || die_error(undef, "Open failed.");
782 my (@revlist) = map { chomp; $_ } <$fd>;
783 close $fd || die_error(undef, "Reading rev-list failed.");
786 print "<div class=\"page_nav\">\n";
787 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, "last 10") . " | " .
788 $cgi->a({-href => "$my_uri?p=$project;a=log;t=1"}, "day") . " | " .
789 $cgi->a({-href => "$my_uri?p=$project;a=log;t=7"}, "week") . " | " .
790 $cgi->a({-href => "$my_uri?p=$project;a=log;t=31"}, "month") . " | " .
791 $cgi->a({-href => "$my_uri?p=$project;a=log;t=365"}, "year") . " | " .
792 $cgi->a({-href => "$my_uri?p=$project;a=log;t=0"}, "all") . "<br/>\n";
793 print "<br/><br/>\n" .
797 my %co = git_read_commit($head);
798 print "<div class=\"page_body\"> Last change " . $co{'age_string'} . ".<br/><br/></div>\n";
801 foreach my $commit (@revlist) {
802 my %co = git_read_commit($commit);
804 my %ad = date_str($co{'author_epoch'});
806 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
807 "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
809 print "<div class=\"title_text\">\n" .
810 "<div class=\"log_link\">\n" .
811 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
812 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
815 "<i>" . escapeHTML($co{'author_name'}) . " [" . $ad{'rfc2822'} . "]</i><br/>\n" .
817 "<div class=\"log_body\">\n";
818 my $comment = $co{'comment'};
820 foreach my $line (@$comment) {
821 if ($line =~ m/^(signed[ \-]off[\-]by[ :]|acked[\-]by[ \:]|cc[ :])/i) {
832 print escapeHTML($line) . "<br/>\n";
843 my %co = git_read_commit($hash);
845 die_error(undef, "Unknown commit object.");
847 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
848 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
851 if (defined $co{'parent'}) {
852 open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash" || die_error(undef, "Open failed.");
853 @difftree = map { chomp; $_ } <$fd>;
854 close $fd || die_error(undef, "Reading diff-tree failed.");
856 # fake git-diff-tree output for initial revision
857 open my $fd, "-|", "$gitbin/git-ls-tree -r $hash" || die_error(undef, "Open failed.");
858 @difftree = map { chomp; "+" . $_ } <$fd>;
859 close $fd || die_error(undef, "Reading ls-tree failed.");
862 print "<div class=\"page_nav\">\n" .
863 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit");
864 if (defined $co{'parent'}) {
865 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff");
867 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash"}, "tree") . "\n" .
868 "<br/><br/></div>\n";
869 if (defined $co{'parent'}) {
871 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
875 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
878 print "<div class=\"title_text\">\n" .
879 "<table cellspacing=\"0\">\n";
880 print "<tr><td>author</td><td>" . escapeHTML($co{'author'}) . "</td></tr>\n".
881 "<tr><td></td><td> " . $ad{'rfc2822'};
882 if ($ad{'hour_local'} < 6) {
883 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
885 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
887 print "</td></tr>\n";
888 print "<tr><td>committer</td><td>" . escapeHTML($co{'committer'}) . "</td></tr>\n";
889 print "<tr><td></td><td> " . $cd{'rfc2822'} . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
890 print "<tr><td>commit</td><td style=\"font-family: monospace;\">$hash</td></tr>\n";
891 print "<tr><td>tree</td><td style=\"font-family: monospace;\">" .
892 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=" . $hash}, $co{'tree'}) . "</td></tr>\n";
893 my $parents = $co{'parents'};
894 foreach my $par (@$parents) {
895 print "<tr><td>parent</td><td style=\"font-family: monospace;\">" .
896 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, $par) . "</td></tr>\n";
900 print "<div class=\"page_body\">\n";
901 my $comment = $co{'comment'};
904 foreach my $line (@$comment) {
905 # print only one empty line
907 if ($empty || $signed) {
914 if ($line =~ m/^(signed[ \-]off[\-]by[ :]|acked[\-]by[ \:]|cc[ :])/i) {
916 print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
919 print escapeHTML($line) . "<br/>\n";
923 print "<div class=\"list_head\">\n";
924 if ($#difftree > 10) {
925 print(($#difftree + 1) . " files changed:\n");
928 foreach my $line (@difftree) {
929 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
930 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
931 # '*100664->100644 blob b1a8e3dd5556b61dd771d32307c6ee5d7150fa43->b1a8e3dd5556b61dd771d32307c6ee5d7150fa43 show-files.c'
932 # '*100664->100644 blob d08e895238bac36d8220586fdc28c27e1a7a76d3->d08e895238bac36d8220586fdc28c27e1a7a76d3 update-cache.c'
933 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
939 if ($type eq "blob") {
942 if (S_ISREG(oct $mode)) {
943 $mode_chng = sprintf(" with mode: %04o", (oct $mode) & 0777);
945 print "<div class=\"list\">\n" .
946 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"},
947 escapeHTML($file) . " <span style=\"color: #008000;\">[new " . file_type($mode) . $mode_chng . "]</span>") . "\n" .
949 print "<div class=\"link\">\n" .
950 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, "blob") . "\n" .
952 } elsif ($op eq "-") {
953 print "<div class=\"list\">\n" .
954 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"},
955 escapeHTML($file) . " <span style=\"color: #c00000;\">[deleted " . file_type($mode) . "]</span>") . "\n" .
957 print "<div class=\"link\">\n" .
958 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, "blob") . " | " .
959 $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "\n" .
961 } elsif ($op eq "*") {
962 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
965 $mode =~ m/^([0-7]{6})->([0-7]{6})$/;
969 if ($from_mode != $to_mode) {
970 $mode_chnge = " <span style=\"color: #888888;\">[changed";
971 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
972 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
974 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
975 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
976 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
977 } elsif (S_ISREG($to_mode)) {
978 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
981 $mode_chnge .= "]</span>\n";
983 print "<div class=\"list\">\n";
984 if ($to_id ne $from_id) {
985 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"},
986 escapeHTML($file) . $mode_chnge) . "\n" .
989 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"},
990 escapeHTML($file) . $mode_chnge) . "\n" .
993 print "<div class=\"link\">\n";
994 if ($to_id ne $from_id) {
995 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"}, "diff") . " | ";
997 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob") . " | " .
998 $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "\n" .
1007 mkdir($gittmp, 0700);
1009 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1010 print "<div class=\"page_nav\">\n" .
1011 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1012 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1013 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash_base"}, "tree");
1014 if (defined $file_name) {
1015 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base;f=$file_name"}, "history");
1017 print "<br/><br/>\n" .
1020 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1023 print "<div class=\"page_nav\">\n" .
1024 "<br/><br/></div>\n" .
1025 "<div class=\"title\">$hash vs $hash_parent</div>\n";
1027 if (defined $file_name) {
1028 print "<div class=\"page_path\">\n" .
1032 print "<div class=\"page_body\">\n" .
1033 "<div class=\"diff_info\">blob:" .
1034 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name"}, $hash_parent) .
1036 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name"}, $hash) .
1038 git_diff_html($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
1043 sub git_commitdiff {
1044 mkdir($gittmp, 0700);
1045 my %co = git_read_commit($hash);
1047 die_error(undef, "Unknown commit object.");
1049 open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash" || die_error(undef, "Open failed.");
1050 my (@difftree) = map { chomp; $_ } <$fd>;
1051 close $fd || die_error(undef, "Reading diff-tree failed.");
1054 print "<div class=\"page_nav\">\n" .
1055 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
1056 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") . " | \n" .
1057 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash"}, "tree") . "\n" .
1058 "<br/><br/></div>\n";
1060 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1062 print "<div class=\"page_body\">\n";
1063 foreach my $line (@difftree) {
1064 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
1065 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
1071 if ($type eq "blob") {
1073 print "<div class=\"diff_info\">" . file_type($mode) . ":" .
1074 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, $id) . "(new)" .
1076 git_diff_html(undef, "/dev/null", $id, "b/$file");
1077 } elsif ($op eq "-") {
1078 print "<div class=\"diff_info\">" . file_type($mode) . ":" .
1079 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, $id) . "(deleted)" .
1081 git_diff_html($id, "a/$file", undef, "/dev/null");
1082 } elsif ($op eq "*") {
1083 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
1086 $mode =~ m/([0-7]+)->([0-7]+)/;
1089 if ($from_id ne $to_id) {
1090 print "<div class=\"diff_info\">" .
1091 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) .
1093 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id);
1095 git_diff_html($from_id, "a/$file", $to_id, "b/$file");
1106 if (!defined $hash) {
1107 $hash = git_read_head($project);
1109 my %co = git_read_commit($hash);
1111 die_error(undef, "Unknown commit object.");
1114 print "<div class=\"page_nav\">\n" .
1115 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | " .
1116 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") . " | " .
1117 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash"}, "tree") .
1121 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1123 print "<div class=\"page_path\">\n" .
1124 "/$file_name<br/>\n";
1126 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin $file_name";
1128 while (my $line = <$fd>) {
1129 if ($line =~ m/^([0-9a-fA-F]{40}) /){
1133 if ($line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/ && (defined $commit)) {
1136 if ($file ne $file_name || $type ne "blob") {
1139 my %co = git_read_commit($commit);
1143 print "<div class=\"list\">\n" .
1144 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"},
1145 "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
1147 print "<div class=\"link\">\n" .
1148 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1149 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$commit"}, "tree") .
1150 " | " . $cgi->a({-href => "$my_uri?p=$project;a=blob;hb=$commit;f=" . $file}, "blob");
1151 my $blob = git_get_hash_by_path($hash, $file_name);
1152 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1153 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
1154 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=" . $file}, "diff");