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 file is licensed under the GPL v2, or a later version
12 use CGI qw(:standard :escapeHTML);
13 use CGI::Carp qw(fatalsToBrowser);
18 my $projectroot = "/pub/scm";
19 $projectroot = "/home/kay/public_html/pub/scm";
20 my $home_link = "/git";
21 $home_link = "/~kay/git";
22 my $gitbin = "/usr/bin";
23 my $gittmp = "/tmp/gitweb";
24 my $logo_link = "/pub/software/scm/cogito";
25 $logo_link = "/~kay/pub/software/scm/cogito";
29 my $my_url = $cgi->url();
30 my $my_uri = $cgi->url(-absolute => 1);
33 my $project = $cgi->param('p');
34 if (defined($project)) {
35 if ($project =~ /(^|\/)(|\.|\.\.)($|\/)/) {
37 die_error("", "Invalid project parameter.");
39 if (!(-d "$projectroot/$project")) {
41 die_error("", "No such project.");
43 $rss_link = "<link rel=\"alternate\" title=\"$project log\" href=\"$my_uri?p=$project;a=rss\" type=\"application/rss+xml\"/>";
44 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
47 my $file_name = $cgi->param('f');
48 if (defined($file_name) && $file_name =~ /(^|\/)(|\.|\.\.)($|\/)/) {
50 die_error("", "Invalid file parameter.");
53 my $action = $cgi->param('a');
54 if (defined($action) && $action =~ m/[^0-9a-zA-Z\.\-]+$/) {
56 die_error("", "Invalid action parameter.");
59 my $hash = $cgi->param('h');
60 if (defined($hash) && !($hash =~ m/^[0-9a-fA-F]{40}$/)) {
62 die_error("", "Invalid hash parameter.");
65 my $hash_parent = $cgi->param('hp');
66 if (defined($hash_parent) && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
68 die_error("", "Invalid parent hash parameter.");
71 my $time_back = $cgi->param('t');
72 if (defined($time_back) && !($time_back =~ m/^[0-9]+$/)) {
74 die_error("", "Invalid time parameter.");
80 my $status = shift || "200 OK";
82 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status);
84 <?xml version="1.0" encoding="utf-8"?>
85 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
86 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
87 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
89 <title>git - $project</title>
91 <style type="text/css">
92 body { font-family: sans-serif; font-size: 12px; margin:0px; }
94 a:hover { color:#880000; }
95 a:visited { color:#880000; }
96 a:active { color:#880000; }
98 margin:15px 25px 0px; height:25px; padding:8px;
99 font-size:18px; font-weight:bold; background-color:#d9d8d1;
101 div.page_header a:visited { color:#0000cc; }
102 div.page_header a:hover { color:#880000; }
103 div.page_nav { margin:0px 25px; padding:8px; border:solid #d9d8d1; border-width:0px 1px; }
104 div.page_nav a:visited { color:#0000cc; }
105 div.page_footer { margin:0px 25px 15px; height:17px; padding:4px; padding-left:8px; background-color: #d9d8d1; }
106 div.page_footer_text { float:left; color:#555555; font-style:italic; }
107 div.page_body { margin:0px 25px; padding:8px; border:solid #d9d8d1; border-width:0px 1px; }
109 display:block; margin:0px 25px; padding:6px 8px;
110 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
112 a.title:hover { background-color: #d9d8d1; }
113 div.title_text { margin:0px 25px; padding:6px 8px; border: solid #d9d8d1; border-width:0px 1px 1px; }
114 div.log_body { margin:0px 25px; padding:8px; padding-left:150px; border:solid #d9d8d1; border-width:0px 1px; }
115 span.log_age { position:relative; float:left; width:142px; font-style:italic; }
116 div.log_link { font-size:10px; font-family:sans-serif; font-style:normal; position:relative; float:left; width:142px; }
118 display:block; margin:0px 25px; padding:4px 6px 2px; border:solid #d9d8d1; border-width:1px 1px 0px;
122 display:block; margin:0px 25px; padding:4px 6px 4px; border:solid #d9d8d1; border-width:1px 1px 0px;
125 div.list a { text-decoration:none; color:#000000; }
126 div.list a:hover { color:#880000; }
128 margin:0px 25px; padding:0px 6px 8px; border:solid #d9d8d1; border-width:0px 1px;
129 font-family:sans-serif; font-size:10px;
131 td.key { padding-right:10px; }
132 span.diff_info { color:#000099; background-color:#eeeeee; font-style:italic; }
133 a.rss_logo { float:right; border:1px solid;
135 border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e; width:35px;
136 color:#ffffff; background-color:#ff6600;
137 font-weight:bold; font-family:sans-serif; text-align:center;
138 font-size:10px; display:block; text-decoration:none;
140 a.rss_logo:hover { background-color:#ee5500; }
145 print "<div class=\"page_header\">\n" .
146 "<a href=\"$logo_link\">" .
147 "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
148 print $cgi->a({-href => "$my_uri"}, "projects") . " / ";
149 if ($project ne "") {
150 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, escapeHTML($project));
158 sub git_footer_html {
159 print "<div class=\"page_footer\">\n";
160 if ($project ne "") {
161 if (-e "$projectroot/$project/description") {
162 open(my $fd, "$projectroot/$project/description");
164 print "<div class=\"page_footer_text\">" . escapeHTML($descr) . "</div>\n";
167 print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
175 my $status = shift || "403 Forbidden";
176 my $error = shift || "Malformed query, file missing or permission denied";
178 git_header_html($status);
179 print "<div class=\"page_body\">\n" .
181 print "$status - $error\n";
182 print "<br/></div>\n";
189 open(my $fd, "$projectroot/$path/HEAD") || die_error("", "Invalid project directory.");
201 open my $fd, "-|", "$gitbin/git-cat-file commit $commit";
202 while (my $line = <$fd>) {
205 if ($line =~ m/^tree (.*)$/) {
207 } elsif ($line =~ m/^parent (.*)$/) {
209 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
211 $co{'author_epoch'} = $2;
212 $co{'author_tz'} = $3;
213 $co{'author_name'} = $co{'author'};
214 $co{'author_name'} =~ s/ <.*//;
215 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
216 $co{'committer'} = $1;
217 $co{'committer_epoch'} = $2;
218 $co{'committer_tz'} = $3;
219 $co{'committer_name'} = $co{'committer'};
220 $co{'committer_name'} =~ s/ <.*//;
223 if (!defined($co{'tree'})) {
226 $co{'parents'} = \@parents;
227 $co{'parent'} = $parents[0];
228 my (@comment) = map { chomp; $_ } <$fd>;
229 $co{'comment'} = \@comment;
230 $co{'title'} = $comment[0];
233 my $age = time - $co{'committer_epoch'};
235 if ($age > 60*60*24*365*2) {
236 $co{'age_string'} = (int $age/60/60/24/365);
237 $co{'age_string'} .= " years ago";
238 } elsif ($age > 60*60*24*365/12*2) {
239 $co{'age_string'} = int $age/60/60/24/365/12;
240 $co{'age_string'} .= " months ago";
241 } elsif ($age > 60*60*24*7*2) {
242 $co{'age_string'} = int $age/60/60/24/7;
243 $co{'age_string'} .= " weeks ago";
244 } elsif ($age > 60*60*24*2) {
245 $co{'age_string'} = int $age/60/60/24;
246 $co{'age_string'} .= " days ago";
247 } elsif ($age > 60*60*2) {
248 $co{'age_string'} = int $age/60/60;
249 $co{'age_string'} .= " hours ago";
250 } elsif ($age > 60*2) {
251 $co{'age_string'} = int $age/60;
252 $co{'age_string'} .= " minutes ago";
259 my $from_name = shift;
263 my $from_tmp = "/dev/null";
264 my $to_tmp = "/dev/null";
267 # create tmp from-file
269 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
270 open(my $fd2, "> $from_tmp");
271 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
280 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
281 open my $fd2, "> $to_tmp";
282 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
289 open my $fd, "-|", "/usr/bin/diff -u -p -L $from_name -L $to_name $from_tmp $to_tmp";
290 while (my $line = <$fd>) {
291 my $char = substr($line,0,1);
293 next if $char eq '\\';
295 print '<span style="color: #008800;">' if $char eq '+';
296 print '<span style="color: #CC0000;">' if $char eq '-';
297 print '<span style="color: #990099;">' if $char eq '@';
298 print escapeHTML($line);
299 print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
312 my $mode = oct shift;
315 if (($mode & 00170000) == 0040000 ) {
316 $modestr = 'drwxr-xr-x';
317 } elsif (($mode & 00170000) == 0120000 ) {
318 $modestr = 'lrwxrwxrwx';
319 } elsif (($mode & 00170000) == 0100000 ) {
320 # git cares only about the executable bit
322 $modestr = '-rwxr-xr-x';
324 $modestr = '-rw-r--r--';
331 my $mode = oct shift;
333 if (($mode & 0170000) == 0040000 ) {
335 } elsif (($mode & 0170000) == 0120000 ) {
337 } elsif (($mode & 0170000) == 0100000 ) {
339 return "executable file";
350 my $tz = shift || "-0000";
353 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
354 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
355 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
356 $date{'hour'} = $hour;
357 $date{'minute'} = $min;
358 $date{'mday'} = $mday;
359 $date{'day'} = $days[$wday];
360 $date{'month'} = $months[$mon];
361 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
362 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
364 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
365 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
366 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
367 $date{'hour_local'} = $hour;
368 $date{'minute_local'} = $min;
369 $date{'tz_local'} = $tz;
373 if (defined($action) && $action eq "git-logo.png") {
374 print $cgi->header(-type => 'image/png', -expires => '+1d');
375 print "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
376 "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
377 "\055\000\000\000\030\120\114\124\105\377\377\377\140\140\135\260".
378 "\257\252\000\200\000\316\315\307\300\000\000\350\350\346\367\367".
379 "\366\225\014\247\107\000\000\000\163\111\104\101\124\050\317\143".
380 "\110\147\040\004\112\134\030\012\010\052\142\123\141\040\002\010".
381 "\015\151\105\254\241\241\001\060\014\223\140\066\046\122\221\261".
382 "\001\021\326\341\125\144\154\154\314\154\154\014\242\014\160\052".
383 "\142\006\052\301\142\035\263\001\002\123\244\010\350\000\003\030".
384 "\046\126\021\324\341\040\227\033\340\264\016\065\044\161\051\202".
385 "\231\060\270\223\012\021\271\105\210\301\215\240\242\104\041\006".
386 "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305".
387 "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202";
391 if (!defined($project)) {
392 print $cgi->redirect($home_link);
396 if (!defined($action)) {
400 if (!defined($time_back)) {
404 if ($action eq "blob") {
406 print "<div class=\"page_nav\">\n";
407 print "<br/><br/></div>\n";
408 print "<div class=\"title\">$hash</div>\n";
409 print "<div class=\"page_body\"><pre>\n";
410 open(my $fd, "-|", "$gitbin/git-cat-file blob $hash");
412 while (my $line = <$fd>) {
414 printf "<span style =\"color: #999999;\">%4i\t</span>%s", $nr, escapeHTML($line);;
417 print "<br/></pre>\n";
420 } elsif ($action eq "tree") {
422 $hash = git_head($project);
424 open my $fd, "-|", "$gitbin/git-ls-tree $hash";
425 my (@entries) = map { chomp; $_ } <$fd>;
429 my %co = git_commit($hash);
431 print "<div class=\"page_nav\"> view\n" .
432 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | " .
433 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . " | " .
434 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash"}, "tree") .
438 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
441 print "<div class=\"page_nav\">\n";
442 print "<br/><br/></div>\n";
443 print "<div class=\"title\">$hash</div>\n";
445 print "<div class=\"page_body\">\n";
446 print "<br/><pre>\n";
447 foreach my $line (@entries) {
448 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
449 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
454 if ($t_type eq "blob") {
455 print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash"}, $t_name);
456 if (((oct $t_mode) & 0170000) == 0120000) {
457 open my $fd, "-|", "$gitbin/git-cat-file blob $t_hash";
460 print "\t -> $target";
463 } elsif ($t_type eq "tree") {
464 print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash"}, $t_name) . "\n";
470 } elsif ($action eq "rss") {
471 open my $fd, "-|", "$gitbin/git-rev-list --max-count=20 " . git_head($project);
472 my (@revlist) = map { chomp; $_ } <$fd>;
475 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
476 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
477 "<rss version=\"0.91\">\n";
479 print "<title>$project</title>\n".
480 "<link> " . $my_url . "/$project/log</link>\n".
481 "<description>$project log</description>\n".
482 "<language>en</language>\n";
484 foreach my $commit (@revlist) {
485 my %co = git_commit($commit);
486 my %ad = date_str($co{'author_epoch'});
488 "\t<title>" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'min'}) . " - " . escapeHTML($co{'title'}) . "</title>\n" .
489 "\t<link> " . $my_url . "?p=$project;a=commit;h=$commit</link>\n" .
491 my $comment = $co{'comment'};
492 foreach my $line (@$comment) {
493 print escapeHTML($line) . "<br/>\n";
495 print "\t</description>\n" .
498 print "</channel></rss>";
499 } elsif ($action eq "log") {
501 if ($time_back > 0) {
502 $date = time - $time_back*24*60*60;
504 my $head = git_head($project);
505 open my $fd, "-|", "$gitbin/git-rev-list --max-age=$date $head";
506 my (@revlist) = map { chomp; $_ } <$fd>;
510 print "<div class=\"page_nav\">\n";
512 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, "last day") . " | " .
513 $cgi->a({-href => "$my_uri?p=$project;a=log;t=7"}, "week") . " | " .
514 $cgi->a({-href => "$my_uri?p=$project;a=log;t=31"}, "month") . " | " .
515 $cgi->a({-href => "$my_uri?p=$project;a=log;t=365"}, "year") . " | " .
516 $cgi->a({-href => "$my_uri?p=$project;a=log;t=0"}, "all") . "<br/>\n";
517 print "<br/><br/>\n" .
521 my %co = git_commit($head);
522 print "<div class=\"page_body\"> Last change " . $co{'age_string'} . ".<br/><br/></div>\n";
525 foreach my $commit (@revlist) {
526 my %co = git_commit($commit);
527 my %ad = date_str($co{'author_epoch'});
529 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
530 "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
532 print "<div class=\"title_text\">\n" .
533 "<div class=\"log_link\">\n" .
534 "view " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") . " | " .
535 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "diff") . "<br/>\n" .
537 "<i>" . escapeHTML($co{'author_name'}) . " [" . $ad{'rfc2822'} . "]</i><br/>\n" .
539 "<div class=\"log_body\">\n";
540 my $comment = $co{'comment'};
541 foreach my $line (@$comment) {
542 last if ($line =~ m/^(signed-off|acked)-by:/i);
543 print escapeHTML($line) . "<br/>\n";
549 } elsif ($action eq "commit") {
550 my %co = git_commit($hash);
552 die_error("", "Unknown commit object.");
554 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
555 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
558 if (defined($co{'parent'})) {
559 open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash";
560 @difftree = map { chomp; $_ } <$fd>;
563 # fake git-diff-tree output for initial revision
564 open my $fd, "-|", "$gitbin/git-ls-tree -r $hash";
565 @difftree = map { chomp; "+" . $_ } <$fd>;
569 print "<div class=\"page_nav\"> view\n" .
570 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
571 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . " | \n" .
572 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash"}, "tree") . "\n" .
573 "<br/><br/></div>\n";
575 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
577 print "<div class=\"title_text\">\n" .
578 "<table cellspacing=\"0\">";
579 print "<tr><td class=\"key\">author</td><td>" . escapeHTML($co{'author'}) . "</td><tr><td></td><td>" .
580 " " . $ad{'rfc2822'};
581 if ($ad{'hour_local'} < 6) {
582 print "<span style=\"color: #cc0000;\">";
584 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
585 if ($ad{'hour_local'} < 6 ) {
590 print "<tr><td class=\"key\">committer</td><td>" . escapeHTML($co{'committer'}) . "</td><tr><td></td><td>" .
591 " " . $cd{'rfc2822'} . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</i>\n" .
593 print "<tr><td class=\"key\">commit</td><td style=\"font-family: monospace;\">$hash</td></tr>\n";
594 print "<tr><td class=\"key\">tree</td><td style=\"font-family: monospace;\">" . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash"}, $co{'tree'}) . "</td></tr>\n";
595 my $parents = $co{'parents'};
596 foreach my $par (@$parents) {
597 print "<tr><td class=\"key\">parent</td><td style=\"font-family: monospace;\">" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, $par) . "</td></tr>\n";
599 print "</table></div>\n";
600 print "<div class=\"page_body\">\n";
601 my $comment = $co{'comment'};
602 foreach my $line (@$comment) {
603 if ($line =~ m/(signed-off|acked)-by:/i) {
604 print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
606 print escapeHTML($line) . "<br/>\n";
610 if ($#difftree > 10) {
611 print "<div class=\"list_head\">" . ($#difftree + 1) . " files changed:<br/></div>\n";
613 foreach my $line (@difftree) {
614 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
615 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
616 # '*100664->100644 blob b1a8e3dd5556b61dd771d32307c6ee5d7150fa43->b1a8e3dd5556b61dd771d32307c6ee5d7150fa43 show-files.c'
617 # '*100664->100644 blob d08e895238bac36d8220586fdc28c27e1a7a76d3->d08e895238bac36d8220586fdc28c27e1a7a76d3 update-cache.c'
618 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
625 if ($type eq "blob") {
627 print "<div class=\"list\">\n" .
628 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"},
629 escapeHTML($file) . " <span style=\"color: #008000;\">[new " . file_type($mode) . "]</span>") . "\n" .
631 print "<div class=\"link\">\n" .
633 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, "file") . "<br/>\n" .
635 } elsif ($op eq "-") {
636 print "<div class=\"list\">\n" .
637 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"},
638 escapeHTML($file) . " <span style=\"color: #c00000;\">[deleted " . file_type($mode) . "]</span>") . "\n" .
640 print "<div class=\"link\">\n" .
642 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, "file") . " | " .
643 $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "<br/>\n" .
645 } elsif ($op eq "*") {
646 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
649 $mode =~ m/^([0-7]{6})->([0-7]{6})$/;
653 if (((oct $from_mode) & 0170100) != ((oct $to_mode) & 0170100)) {
654 $mode_chnge = " <span style=\"color: #888888;\">[changed from " . file_type($from_mode) . " to " . file_type($to_mode) . "]</span>\n";
656 print "<div class=\"list\">\n";
657 if ($to_id ne $from_id) {
658 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id"},
659 escapeHTML($file) . $mode_chnge) . "\n" .
662 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id"},
663 escapeHTML($file) . $mode_chnge) . "\n" .
666 print "<div class=\"link\">\n" .
668 if ($to_id ne $from_id) {
669 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id"}, "diff") . " | ";
671 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id"}, "file") . " | " .
672 $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "<br/>\n" .
678 } elsif ($action eq "blobdiff") {
680 print "<div class=\"page_nav\">\n";
681 print "<br/><br/></div>\n";
682 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
683 print "<div class=\"page_body\">\n" .
685 print "<span class=\"diff_info\">blob:" .
686 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash_parent"}, $hash_parent) .
688 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash"}, $hash) .
690 git_diff_html($hash_parent, $hash_parent, $hash, $hash);
694 } elsif ($action eq "commitdiff") {
695 my %co = git_commit($hash);
697 die_error("", "Unknown commit object.");
699 open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash";
700 my (@difftree) = map { chomp; $_ } <$fd>;
704 print "<div class=\"page_nav\"> view\n" .
705 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
706 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . " | \n" .
707 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash"}, "tree") . "\n" .
708 "<br/><br/></div>\n";
710 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
712 print "<div class=\"page_body\">\n" .
714 foreach my $line (@difftree) {
715 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
716 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
722 if ($type eq "blob") {
724 print "<span class=\"diff_info\">new " . file_type($mode) . ":" .
725 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, $id) .
727 git_diff_html("", "/dev/null", $id, "b/$file");
728 } elsif ($op eq "-") {
729 print "<span class=\"diff_info\">deleted " . file_type($mode) . ":" .
730 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, $id) .
732 git_diff_html($id, "a/$file", "", "/dev/null");
733 } elsif ($op eq "*") {
734 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
737 $mode =~ m/([0-7]+)->([0-7]+)/;
740 if ($from_id ne $to_id) {
741 print "<span class=\"diff_info\">" .
742 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id"}, $from_id) .
744 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id"}, $to_id);
746 git_diff_html($from_id, "a/$file", $to_id, "b/$file");
751 print "<br/></pre>\n";
754 } elsif ($action eq "history") {
755 if (!(defined($hash))) {
756 $hash = git_head($project);
758 open my $fd, "-|", "$gitbin/git-rev-list $hash";
759 my (@revlist) = map { chomp; $_ } <$fd>;
763 print "<div class=\"page_nav\">\n";
764 print "<br/><br/></div>\n";
766 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($file_name)) . "\n" .
768 foreach my $rev (@revlist) {
769 my %co = git_commit($rev);
770 my $parents = $co{'parents'};
772 foreach my $parent (@$parents) {
773 open $fd, "-|", "$gitbin/git-diff-tree -r $parent $rev $file_name";
774 my (@difftree) = map { chomp; $_ } <$fd>;
777 foreach my $line (@difftree) {
778 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
780 if ($file eq $file_name) {
787 print "<div class=\"list\">\n" .
788 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$rev"},
789 "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
791 print "<div class=\"link\">\n" .
793 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$rev"}, "commit") . " | " .
794 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$rev"}, "tree") . "<br/><br/>\n" .
801 die_error("", "Unknown action.");