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 # html text to include at home page
36 my $home_text = "indextext.html";
38 # source of projects list
39 #my $projects_list = $projectroot;
40 my $projects_list = "index/index.txt";
42 # input validation and dispatch
43 my $action = $cgi->param('a');
44 if (defined $action) {
45 if ($action =~ m/[^0-9a-zA-Z\.\-]+/) {
47 die_error(undef, "Invalid action parameter.");
49 if ($action eq "git-logo.png") {
57 my $project = $cgi->param('p');
58 if (defined $project) {
59 if ($project =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
61 die_error(undef, "Non-canonical project parameter.");
63 if ($project =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~]/) {
65 die_error(undef, "Invalid character in project parameter.");
67 if (!(-d "$projectroot/$project")) {
69 die_error(undef, "No such directory.");
71 if (!(-e "$projectroot/$project/HEAD")) {
73 die_error(undef, "No such project.");
75 $rss_link = "<link rel=\"alternate\" title=\"$project log\" href=\"$my_uri?p=$project;a=rss\" type=\"application/rss+xml\"/>";
76 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
78 git_project_list($projects_list);
82 my $file_name = $cgi->param('f');
83 if (defined $file_name) {
84 if ($file_name =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
86 die_error(undef, "Non-canonical file parameter.");
88 if ($file_name =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~\:\!]/) {
90 die_error(undef, "Invalid character in file parameter.");
94 my $hash = $cgi->param('h');
95 if (defined $hash && !($hash =~ m/^[0-9a-fA-F]{40}$/)) {
97 die_error(undef, "Invalid hash parameter.");
100 my $hash_parent = $cgi->param('hp');
101 if (defined $hash_parent && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
103 die_error(undef, "Invalid hash_parent parameter.");
106 my $hash_base = $cgi->param('hb');
107 if (defined $hash_base && !($hash_base =~ m/^[0-9a-fA-F]{40}$/)) {
109 die_error(undef, "Invalid parent hash parameter.");
112 my $time_back = $cgi->param('t');
113 if (defined $time_back) {
114 if ($time_back =~ m/^[^0-9]+$/) {
116 die_error(undef, "Invalid time parameter.");
120 if ($action eq "blob") {
123 } elsif ($action eq "tree") {
126 } elsif ($action eq "rss") {
129 } elsif ($action eq "commit") {
132 } elsif ($action eq "log") {
135 } elsif ($action eq "blobdiff") {
138 } elsif ($action eq "commitdiff") {
141 } elsif ($action eq "history") {
146 die_error(undef, "Unknown action.");
150 sub git_header_html {
151 my $status = shift || "200 OK";
154 if (defined $project) {
155 $title .= " - $project";
156 if (defined $action) {
157 $title .= "/$action";
160 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status);
162 <?xml version="1.0" encoding="utf-8"?>
163 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
164 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
165 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
167 <title>$title</title>
169 <style type="text/css">
170 body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
172 a:hover, a:visited, a:active { color:#880000; }
173 div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; }
174 div.page_header a:visited { color:#0000cc; }
175 div.page_header a:hover { color:#880000; }
176 div.page_nav { padding:8px; }
177 div.page_nav a:visited { color:#0000cc; }
178 div.page_path { font-weight:bold; padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
179 div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
180 div.page_footer_text { float:left; color:#555555; font-style:italic; }
181 div.page_body { padding:8px; }
183 display:block; padding:6px 8px;
184 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
186 a.title:hover { background-color: #d9d8d1; }
187 div.title_text { padding:6px 8px; border: solid #d9d8d1; border-width:0px 0px 1px; }
188 div.log_body { padding:8px 8px 8px 150px; }
189 span.log_age { position:relative; float:left; width:142px; font-style:italic; }
191 font-size:10px; font-family:sans-serif; font-style:normal;
192 position:relative; float:left; width:142px;
194 div.list { display:block; padding:4px 8px 2px; font-weight:bold; }
196 display:block; padding:6px 6px 4px; border:solid #d9d8d1;
197 border-width:0px 0px 1px; font-style:italic;
199 div.list a { text-decoration:none; color:#000000; }
200 div.list a:hover { color:#880000; }
202 padding:4px 8px 6px; border:solid #d9d8d1; border-width:0px 0px 1px;
203 font-family:sans-serif; font-size:10px;
205 td { padding:5px 15px 0px 0px; font-size:12px; }
206 th { padding-right:10px; font-size:12px; text-align:left; }
207 td.link { font-family:sans-serif; font-size:10px; }
208 td.pre { font-family:monospace; font-size:12px; white-space:pre; padding:2px 15px 0px 0px; }
209 div.pre { font-family:monospace; font-size:12px; white-space:pre; }
210 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
211 div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
212 a.rss_logo { float:right; padding:3px 0px; width:35px; line-height:10px;
213 border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
214 color:#ffffff; background-color:#ff6600;
215 font-weight:bold; font-family:sans-serif; font-size:10px;
216 text-align:center; text-decoration:none;
218 a.rss_logo:hover { background-color:#ee5500; }
223 print "<div class=\"page_header\">\n" .
224 "<a href=\"http://kernel.org/pub/software/scm/git/docs/\">" .
225 "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
226 print $cgi->a({-href => $home_link}, "projects") . " / ";
227 if (defined $project) {
228 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, escapeHTML($project));
229 if (defined $action) {
236 sub git_footer_html {
237 print "<div class=\"page_footer\">\n";
238 if (defined $project) {
239 my $descr = git_read_description($project);
240 if (defined $descr) {
241 print "<div class=\"page_footer_text\">" . escapeHTML($descr) . "</div>\n";
243 print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
251 my $status = shift || "403 Forbidden";
252 my $error = shift || "Malformed query, file missing or permission denied";
254 git_header_html($status);
255 print "<div class=\"page_body\">\n" .
257 print "$status - $error\n";
258 print "<br/></div>\n";
266 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" || return;
276 open my $fd, "$projectroot/$path/HEAD" || return undef;
280 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
287 sub git_read_description {
290 open my $fd, "$projectroot/$path/description" || return undef;
297 sub git_read_commit {
302 open my $fd, "-|", "$gitbin/git-cat-file commit $commit" || return;
303 while (my $line = <$fd>) {
304 last if $line eq "\n";
306 if ($line =~ m/^tree (.*)$/) {
308 } elsif ($line =~ m/^parent (.*)$/) {
310 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
312 $co{'author_epoch'} = $2;
313 $co{'author_tz'} = $3;
314 $co{'author_name'} = $co{'author'};
315 $co{'author_name'} =~ s/ <.*//;
316 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
317 $co{'committer'} = $1;
318 $co{'committer_epoch'} = $2;
319 $co{'committer_tz'} = $3;
320 $co{'committer_name'} = $co{'committer'};
321 $co{'committer_name'} =~ s/ <.*//;
324 $co{'parents'} = \@parents;
325 $co{'parent'} = $parents[0];
326 my (@comment) = map { chomp; $_ } <$fd>;
327 $co{'comment'} = \@comment;
328 $comment[0] =~ m/^(.{0,60}[^ ]*)/;
330 if ($comment[0] ne $co{'title'}) {
331 $co{'title'} .= " [...]";
334 if (!defined $co{'tree'}) {
338 my $age = time - $co{'committer_epoch'};
340 if ($age > 60*60*24*365*2) {
341 $co{'age_string'} = (int $age/60/60/24/365);
342 $co{'age_string'} .= " years ago";
343 } elsif ($age > 60*60*24*365/12*2) {
344 $co{'age_string'} = int $age/60/60/24/365/12;
345 $co{'age_string'} .= " months ago";
346 } elsif ($age > 60*60*24*7*2) {
347 $co{'age_string'} = int $age/60/60/24/7;
348 $co{'age_string'} .= " weeks ago";
349 } elsif ($age > 60*60*24*2) {
350 $co{'age_string'} = int $age/60/60/24;
351 $co{'age_string'} .= " days ago";
352 } elsif ($age > 60*60*2) {
353 $co{'age_string'} = int $age/60/60;
354 $co{'age_string'} .= " hours ago";
355 } elsif ($age > 60*2) {
356 $co{'age_string'} = int $age/60;
357 $co{'age_string'} .= " minutes ago";
359 $co{'age_string'} = int $age;
360 $co{'age_string'} .= " seconds ago";
362 $co{'age_string'} .= " right now";
369 my $from_name = shift;
373 my $from_tmp = "/dev/null";
374 my $to_tmp = "/dev/null";
377 # create tmp from-file
379 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
380 open my $fd2, "> $from_tmp";
381 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
390 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
391 open my $fd2, "> $to_tmp";
392 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
399 open my $fd, "-|", "/usr/bin/diff -u -p -L $from_name -L $to_name $from_tmp $to_tmp";
400 while (my $line = <$fd>) {
402 my $char = substr($line, 0, 1);
405 $color = " style=\"color:#008800;\"";
406 } elsif ($char eq '-') {
407 $color = " style=\"color:#cc0000;\"";
408 } elsif ($char eq '@') {
409 $color = " style=\"color:#990099;\"";
410 } elsif ($char eq '\\') {
414 print "<div class=\"pre\"$color>" . escapeHTML($line) . "</div>\n";
427 my $mode = oct shift;
429 if (S_ISDIR($mode & S_IFMT)) {
431 } elsif (S_ISLNK($mode)) {
433 } elsif (S_ISREG($mode)) {
434 # git cares only about the executable bit
435 if ($mode & S_IXUSR) {
446 my $mode = oct shift;
448 if (S_ISDIR($mode & S_IFMT)) {
450 } elsif (S_ISLNK($mode)) {
452 } elsif (S_ISREG($mode)) {
461 my $tz = shift || "-0000";
464 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
465 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
466 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
467 $date{'hour'} = $hour;
468 $date{'minute'} = $min;
469 $date{'mday'} = $mday;
470 $date{'day'} = $days[$wday];
471 $date{'month'} = $months[$mon];
472 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
473 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
475 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
476 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
477 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
478 $date{'hour_local'} = $hour;
479 $date{'minute_local'} = $min;
480 $date{'tz_local'} = $tz;
484 # git-logo (cached in browser for one day)
486 print $cgi->header(-type => 'image/png', -expires => '+1d');
487 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
488 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
489 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
490 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
491 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
492 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
493 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
494 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
495 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
496 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
497 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
498 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
499 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
500 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
506 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
507 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
508 if (!defined $gcos) {
512 $owner =~ s/[,;].*$//;
516 sub git_project_list {
517 my $project_list = shift;
520 if (-d $project_list) {
521 # search in directory
522 my $dir = $project_list;
523 opendir my $dh, $dir || return undef;
524 while (my $dir = readdir($dh)) {
525 if (-e "$projectroot/$dir/HEAD") {
533 } elsif (-e $project_list) {
535 # 'git/git.git:Linus Torvalds'
536 # 'linux/hotplug/udev.git'
537 open my $fd , $project_list || return undef;
538 while (my $line = <$fd>) {
540 my ($path, $owner) = split ':', $line;
541 if (!defined $path) {
544 if (-e "$projectroot/$path/HEAD") {
556 die_error(undef, "No project found.");
558 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
562 print "<div class=\"index_include\">\n";
563 open my $fd, $home_text;
568 print "<div class=\"page_body\"><br/>\n" .
569 "<table cellspacing=\"0\">\n" .
571 "<th>Project</th>\n" .
572 "<th>Description</th>\n" .
574 "<th>last change</th>\n" .
576 foreach my $pr (@list) {
578 my $head = git_read_head($proj{'path'});
579 if (!defined $head) {
582 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$proj{'path'}/objects";
583 my %co = git_read_commit($head);
587 my $descr = git_read_description($proj{'path'}) || "";
588 # get directory owner if not already specified
589 if (!defined $proj{'owner'}) {
590 $proj{'owner'} = get_file_owner("$projectroot/$proj{'path'}") || "";
593 "<td>" . $cgi->a({-href => "$my_uri?p=" . $proj{'path'} . ";a=log"}, escapeHTML($proj{'path'})) . "</td>\n" .
594 "<td>$descr</td>\n" .
595 "<td><i>$proj{'owner'}</i></td>\n";
596 if ($co{'age'} < 60*60*2) {
597 print "<td><span style =\"color: #009900;\"><b><i>$co{'age_string'}</i></b></span></td>\n";
598 } elsif ($co{'age'} < 60*60*24*2) {
599 print "<td><span style =\"color: #009900;\"><i>$co{'age_string'}</i></span></td>\n";
601 print "<td><i>$co{'age_string'}</i></td>\n";
611 sub git_get_hash_by_path {
616 my @parts = split '/', $path;
617 while (my $part = shift @parts) {
618 open my $fd, "-|", "$gitbin/git-ls-tree $tree" || die_error(undef, "Open git-ls-tree failed.");
619 my (@entries) = map { chomp; $_ } <$fd>;
620 close $fd || return undef;
621 foreach my $line (@entries) {
622 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
623 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
628 if ($t_name eq $part) {
632 if ($t_type eq "tree") {
642 if (!defined $hash && defined $file_name) {
643 my $base = $hash_base || git_read_head($project);
644 $hash = git_get_hash_by_path($base, $file_name, "blob");
646 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" || die_error(undef, "Open failed.");
647 my $base = $file_name || "";
649 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
650 print "<div class=\"page_nav\">\n" .
651 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
652 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
653 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash_base"}, "tree");
654 if (defined $file_name) {
655 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base;f=$file_name"}, "history");
657 print "<br/><br/>\n" .
660 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) .
663 print "<div class=\"page_nav\">\n" .
664 "<br/><br/></div>\n" .
665 "<div class=\"title\">$hash</div>\n";
667 if (defined $file_name) {
668 print "<div class=\"page_path\">/$file_name</div>\n";
670 print "<div class=\"page_body\">\n";
672 while (my $line = <$fd>) {
675 print "<div class=\"pre\">";
676 printf "<span style=\"color:#999999;\">%4i</span>", $nr;
677 print " " .escapeHTML($line) . "</div>\n";
679 close $fd || print "Reading blob failed.\n";
685 if (!defined $hash) {
686 $hash = git_read_head($project);
687 if (defined $file_name) {
688 my $base = $hash_base || git_read_head($project);
689 $hash = git_get_hash_by_path($base, $file_name, "tree");
692 open my $fd, "-|", "$gitbin/git-ls-tree $hash" || die_error(undef, "Open git-ls-tree failed.");
693 my (@entries) = map { chomp; $_ } <$fd>;
694 close $fd || die_error(undef, "Reading tree failed.");
700 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
701 $base_key = ";hb=$hash_base";
702 print "<div class=\"page_nav\">\n" .
703 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") . " | " .
704 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") . " | " .
705 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash_base"}, "tree") .
709 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
712 print "<div class=\"page_nav\">\n";
713 print "<br/><br/></div>\n";
714 print "<div class=\"title\">$hash</div>\n";
716 if (defined $file_name) {
717 $base = "$file_name/";
718 print "<div class=\"page_path\">/$file_name</div>\n";
720 print "<div class=\"page_path\">/</div>\n";
722 print "<div class=\"page_body\">\n";
723 print "<table cellspacing=\"0\">\n";
724 foreach my $line (@entries) {
725 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
726 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
731 $file_key = ";f=$base$t_name";
733 "<td class=\"pre\">" . mode_str($t_mode) . "</td>\n";
734 if ($t_type eq "blob") {
735 print "<td class=\"pre\">$t_name</td>\n";
736 print "<td class=\"link\">" .
737 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key}, "blob") .
738 " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base" . $file_key}, "history") .
740 } elsif ($t_type eq "tree") {
741 print "<td class=\"pre\">" .
742 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key}, $t_name) .
753 open my $fd, "-|", "$gitbin/git-rev-list --max-count=20 " . git_read_head($project) || die_error(undef, "Open failed.");
754 my (@revlist) = map { chomp; $_ } <$fd>;
755 close $fd || die_error(undef, "Reading rev-list failed.");
757 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
758 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
759 "<rss version=\"0.91\">\n";
761 print "<title>$project</title>\n".
762 "<link> " . $my_url . "/$project/log</link>\n".
763 "<description>$project log</description>\n".
764 "<language>en</language>\n";
766 foreach my $commit (@revlist) {
767 my %co = git_read_commit($commit);
768 my %ad = date_str($co{'author_epoch'});
770 "\t<title>" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'minute'}) . " - " . escapeHTML($co{'title'}) . "</title>\n" .
771 "\t<link> " . $my_url . "?p=$project;a=commit;h=$commit</link>\n" .
773 my $comment = $co{'comment'};
774 foreach my $line (@$comment) {
775 print escapeHTML($line) . "<br/>\n";
777 print "\t</description>\n" .
780 print "</channel></rss>";
784 my $head = git_read_head($project);
785 my $limit_option = "";
786 if (!defined $time_back) {
787 $limit_option = "--max-count=10";
788 } elsif ($time_back > 0) {
789 my $date = time - $time_back*24*60*60;
790 $limit_option = "--max-age=$date";
792 open my $fd, "-|", "$gitbin/git-rev-list $limit_option $head" || die_error(undef, "Open failed.");
793 my (@revlist) = map { chomp; $_ } <$fd>;
794 close $fd || die_error(undef, "Reading rev-list failed.");
797 print "<div class=\"page_nav\">\n";
798 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, "last 10") . " | " .
799 $cgi->a({-href => "$my_uri?p=$project;a=log;t=1"}, "day") . " | " .
800 $cgi->a({-href => "$my_uri?p=$project;a=log;t=7"}, "week") . " | " .
801 $cgi->a({-href => "$my_uri?p=$project;a=log;t=31"}, "month") . " | " .
802 $cgi->a({-href => "$my_uri?p=$project;a=log;t=365"}, "year") . " | " .
803 $cgi->a({-href => "$my_uri?p=$project;a=log;t=0"}, "all") . "<br/>\n";
804 print "<br/><br/>\n" .
808 my %co = git_read_commit($head);
809 print "<div class=\"page_body\"> Last change " . $co{'age_string'} . ".<br/><br/></div>\n";
812 foreach my $commit (@revlist) {
813 my %co = git_read_commit($commit);
815 my %ad = date_str($co{'author_epoch'});
817 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
818 "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
820 print "<div class=\"title_text\">\n" .
821 "<div class=\"log_link\">\n" .
822 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
823 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
826 "<i>" . escapeHTML($co{'author_name'}) . " [" . $ad{'rfc2822'} . "]</i><br/>\n" .
828 "<div class=\"log_body\">\n";
829 my $comment = $co{'comment'};
831 foreach my $line (@$comment) {
832 if ($line =~ m/^(signed[ \-]off[\-]by[ :]|acked[\-]by[ \:]|cc[ :])/i) {
843 print escapeHTML($line) . "<br/>\n";
854 my %co = git_read_commit($hash);
856 die_error(undef, "Unknown commit object.");
858 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
859 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
862 if (defined $co{'parent'}) {
863 open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash" || die_error(undef, "Open failed.");
864 @difftree = map { chomp; $_ } <$fd>;
865 close $fd || die_error(undef, "Reading diff-tree failed.");
867 # fake git-diff-tree output for initial revision
868 open my $fd, "-|", "$gitbin/git-ls-tree -r $hash" || die_error(undef, "Open failed.");
869 @difftree = map { chomp; "+" . $_ } <$fd>;
870 close $fd || die_error(undef, "Reading ls-tree failed.");
873 print "<div class=\"page_nav\">\n" .
874 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit");
875 if (defined $co{'parent'}) {
876 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff");
878 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash"}, "tree") . "\n" .
879 "<br/><br/></div>\n";
880 if (defined $co{'parent'}) {
882 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
886 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
889 print "<div class=\"title_text\">\n" .
890 "<table cellspacing=\"0\">\n";
891 print "<tr><td>author</td><td>" . escapeHTML($co{'author'}) . "</td></tr>\n".
892 "<tr><td></td><td> " . $ad{'rfc2822'};
893 if ($ad{'hour_local'} < 6) {
894 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
896 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
898 print "</td></tr>\n";
899 print "<tr><td>committer</td><td>" . escapeHTML($co{'committer'}) . "</td></tr>\n";
900 print "<tr><td></td><td> " . $cd{'rfc2822'} . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
901 print "<tr><td>commit</td><td style=\"font-family: monospace;\">$hash</td></tr>\n";
902 print "<tr><td>tree</td><td style=\"font-family: monospace;\">" .
903 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=" . $hash}, $co{'tree'}) . "</td></tr>\n";
904 my $parents = $co{'parents'};
905 foreach my $par (@$parents) {
906 print "<tr><td>parent</td><td style=\"font-family: monospace;\">" .
907 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, $par) . "</td></tr>\n";
911 print "<div class=\"page_body\">\n";
912 my $comment = $co{'comment'};
915 foreach my $line (@$comment) {
916 # print only one empty line
918 if ($empty || $signed) {
925 if ($line =~ m/^(signed[ \-]off[\-]by[ :]|acked[\-]by[ \:]|cc[ :])/i) {
927 print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
930 print escapeHTML($line) . "<br/>\n";
934 print "<div class=\"list_head\">\n";
935 if ($#difftree > 10) {
936 print(($#difftree + 1) . " files changed:\n");
939 foreach my $line (@difftree) {
940 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
941 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
942 # '*100664->100644 blob b1a8e3dd5556b61dd771d32307c6ee5d7150fa43->b1a8e3dd5556b61dd771d32307c6ee5d7150fa43 show-files.c'
943 # '*100664->100644 blob d08e895238bac36d8220586fdc28c27e1a7a76d3->d08e895238bac36d8220586fdc28c27e1a7a76d3 update-cache.c'
944 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
950 if ($type eq "blob") {
953 if (S_ISREG(oct $mode)) {
954 $mode_chng = sprintf(" with mode: %04o", (oct $mode) & 0777);
956 print "<div class=\"list\">\n" .
957 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"},
958 escapeHTML($file) . " <span style=\"color: #008000;\">[new " . file_type($mode) . $mode_chng . "]</span>") . "\n" .
960 print "<div class=\"link\">\n" .
961 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, "blob") . "\n" .
963 } elsif ($op eq "-") {
964 print "<div class=\"list\">\n" .
965 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"},
966 escapeHTML($file) . " <span style=\"color: #c00000;\">[deleted " . file_type($mode) . "]</span>") . "\n" .
968 print "<div class=\"link\">\n" .
969 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, "blob") . " | " .
970 $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "\n" .
972 } elsif ($op eq "*") {
973 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
976 $mode =~ m/^([0-7]{6})->([0-7]{6})$/;
980 if ($from_mode != $to_mode) {
981 $mode_chnge = " <span style=\"color: #888888;\">[changed";
982 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
983 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
985 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
986 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
987 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
988 } elsif (S_ISREG($to_mode)) {
989 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
992 $mode_chnge .= "]</span>\n";
994 print "<div class=\"list\">\n";
995 if ($to_id ne $from_id) {
996 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"},
997 escapeHTML($file) . $mode_chnge) . "\n" .
1000 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"},
1001 escapeHTML($file) . $mode_chnge) . "\n" .
1004 print "<div class=\"link\">\n";
1005 if ($to_id ne $from_id) {
1006 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"}, "diff") . " | ";
1008 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob") . " | " .
1009 $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "\n" .
1018 mkdir($gittmp, 0700);
1020 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1021 print "<div class=\"page_nav\">\n" .
1022 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1023 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1024 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash_base"}, "tree");
1025 if (defined $file_name) {
1026 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base;f=$file_name"}, "history");
1028 print "<br/><br/>\n" .
1031 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1034 print "<div class=\"page_nav\">\n" .
1035 "<br/><br/></div>\n" .
1036 "<div class=\"title\">$hash vs $hash_parent</div>\n";
1038 if (defined $file_name) {
1039 print "<div class=\"page_path\">\n" .
1043 print "<div class=\"page_body\">\n" .
1044 "<div class=\"diff_info\">blob:" .
1045 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name"}, $hash_parent) .
1047 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name"}, $hash) .
1049 git_diff_html($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
1054 sub git_commitdiff {
1055 mkdir($gittmp, 0700);
1056 my %co = git_read_commit($hash);
1058 die_error(undef, "Unknown commit object.");
1060 open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash" || die_error(undef, "Open failed.");
1061 my (@difftree) = map { chomp; $_ } <$fd>;
1062 close $fd || die_error(undef, "Reading diff-tree failed.");
1065 print "<div class=\"page_nav\">\n" .
1066 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
1067 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") . " | \n" .
1068 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash"}, "tree") . "\n" .
1069 "<br/><br/></div>\n";
1071 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1073 print "<div class=\"page_body\">\n";
1074 foreach my $line (@difftree) {
1075 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
1076 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
1082 if ($type eq "blob") {
1084 print "<div class=\"diff_info\">" . file_type($mode) . ":" .
1085 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, $id) . "(new)" .
1087 git_diff_html(undef, "/dev/null", $id, "b/$file");
1088 } elsif ($op eq "-") {
1089 print "<div class=\"diff_info\">" . file_type($mode) . ":" .
1090 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, $id) . "(deleted)" .
1092 git_diff_html($id, "a/$file", undef, "/dev/null");
1093 } elsif ($op eq "*") {
1094 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
1097 $mode =~ m/([0-7]+)->([0-7]+)/;
1100 if ($from_id ne $to_id) {
1101 print "<div class=\"diff_info\">" .
1102 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) .
1104 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id);
1106 git_diff_html($from_id, "a/$file", $to_id, "b/$file");
1117 if (!defined $hash) {
1118 $hash = git_read_head($project);
1120 my %co = git_read_commit($hash);
1122 die_error(undef, "Unknown commit object.");
1125 print "<div class=\"page_nav\">\n" .
1126 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | " .
1127 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") . " | " .
1128 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash"}, "tree") .
1132 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1134 print "<div class=\"page_path\">\n" .
1135 "/$file_name<br/>\n";
1137 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin $file_name";
1139 while (my $line = <$fd>) {
1140 if ($line =~ m/^([0-9a-fA-F]{40}) /){
1144 if ($line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/ && (defined $commit)) {
1147 if ($file ne $file_name || $type ne "blob") {
1150 my %co = git_read_commit($commit);
1154 print "<div class=\"list\">\n" .
1155 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"},
1156 "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
1158 print "<div class=\"link\">\n" .
1159 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1160 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$commit"}, "tree") .
1161 " | " . $cgi->a({-href => "$my_uri?p=$project;a=blob;hb=$commit;f=" . $file}, "blob");
1162 my $blob = git_get_hash_by_path($hash, $file_name);
1163 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1164 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
1165 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=" . $file}, "diff");