v077
[git.git] / gitweb.cgi
blobf96013fd8024cb5d69629a76168b3310d39f8917
1 #!/usr/bin/perl
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
10 use strict;
11 use warnings;
12 use CGI qw(:standard :escapeHTML);
13 use CGI::Carp qw(fatalsToBrowser);
15 my $cgi = new CGI;
17 my $version = "078";
18 my $projectroot = "/pub/scm";
19 my $home_link = "/git";
20 my $gitbin = "/usr/bin";
21 my $gittmp = "/tmp/gitweb";
22 my $logo_link = "/pub/software/scm/cogito";
23 my $my_url = $cgi->url();
24 my $my_uri = $cgi->url(-absolute => 1);
26 # remove #
27 my $projectroot = "/home/kay/public_html/pub/scm";
28 my $home_link = "/~kay/git";
29 my $logo_link = "/~kay/pub/software/scm/cogito";
30 # remove #
32 mkdir($gittmp, 0700);
33 my $project = $cgi->param('p');
34 my $action = $cgi->param('a');
35 my $hash = $cgi->param('h');
36 my $hash_parent = $cgi->param('hp');
37 my $file_name = $cgi->param('f');
38 my $time_back = $cgi->param('t');
39 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
41 # validate input
42 if (defined($project)) {
43 if ($project =~ /(^|\/)(|\.|\.\.)($|\/)/) {
44 die_error("", "Invalid project parameter.");
46 if (!(-d "$projectroot/$project")) {
47 die_error("", "No such project.");
50 if (defined($file_name) && $file_name =~ /(^|\/)(|\.|\.\.)($|\/)/) {
51 die_error("", "Invalid file parameter.");
53 if (defined($action) && !$action =~ m/^[0-9a-zA-Z\.\-]+$/) {
54 die_error("", "Invalid action parameter.");
56 if (defined($hash) && !($hash =~ m/^[0-9a-fA-F]{40}$/)) {
57 die_error("", "Invalid hash parameter.");
59 if (defined($hash_parent) && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
60 die_error("", "Invalid parent hash parameter.");
62 if (defined($time_back) && !($time_back =~ m/^[0-9]+$/)) {
63 die_error("", "Invalid time parameter.");
66 sub git_header_html {
67 my $status = shift || "200 OK";
69 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status);
70 print <<EOF;
71 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
72 <html>
73 <head>
74 <title>git - $project $action</title>
75 <link rel="alternate" title="$project log" href="$my_uri?p=$project;a=rss" type="application/rss+xml"/>
76 <style type="text/css">
77 body { font-family: sans-serif; font-size: 12px; margin:0px; }
78 a { color:#0000cc; }
79 a:hover { color:#880000; }
80 a:visited { color:#880000; }
81 a:active { color:#880000; }
82 div.page_header {
83 margin:15px 25px 0px; height:25px; padding:8px;
84 font-size:18px; font-weight:bold; background-color:#d9d8d1;
86 div.page_header a:visited { color:#0000cc; }
87 div.page_header a:hover { color:#880000; }
88 div.page_nav { margin:0px 25px; padding:8px; border:solid #d9d8d1; border-width:0px 1px; }
89 div.page_nav a:visited { color:#0000cc; }
90 div.page_footer {
91 margin:0px 25px 15px; height:17px; padding:4px; padding-left:8px;
92 background-color: #d9d8d1;
94 div.page_footer_text { float:left; color:#888888; font-size:10px;}
95 div.page_body { margin:0px 25px; padding:8px; border:solid #d9d8d1; border-width:0px 1px; }
96 div.title {
97 display:block; margin:0px 25px; padding:8px;
98 font-weight:bold; background-color:#d9d8d1; color:#000000;
100 a.log_title {
101 display:block; margin:0px 25px; padding:6px;
102 font-weight:bold; background-color:#d9d8d1; text-decoration:none; color:#000000;
104 a.log_title:hover { background-color: #c9c8c1; }
105 div.log_head {
106 margin:0px 25px; padding:8px;
107 border: solid #d9d8d1; border-width:0px 1px; font-family:monospace;
108 background-color: #edece6;
110 div.log_body {
111 margin:0px 25px; padding:8px; padding-left:150px;
112 border:solid #d9d8d1; border-width:0px 1px;
114 span.log_age { position:relative; float:left; width:142px; }
115 div.log_link { font-size:10px; font-family:sans-serif; position:relative; float:left; width:142px; }
116 div.list {
117 display:block; margin:0px 25px; padding:2px 8px 0px; border:solid #d9d8d1; border-width:1px 1px 0px 1px;
118 font-weight:bold; text-decoration:none; color:#000000;
120 div.list a { color:#000000; text-decoration:none; }
121 div.link { font-weight:normal; font-family:sans-serif; font-size:10px; border:solid #d9d8d1; border-width:1px 1px 0px 1px; }
122 a.view { display:inline; font-size:24px; }
123 a.xml_logo { float:right; border:1px solid;
124 line-height:15px;
125 border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e; width:35px;
126 color:#ffffff; background-color:#ff6600;
127 font-weight:bold; font-family:sans-serif; text-align:center;
128 font-size:10px; display:block; text-decoration:none;
130 a.xml_logo:hover { background-color:#ee5500; }
131 </style>
132 </head>
133 <body>
135 print "<div class=\"page_header\">\n" .
136 "<a href=\"$logo_link\">" .
137 "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
138 print $cgi->a({-href => "$my_uri"}, "projects") . " / ";
139 if ($project ne "") {
140 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, escapeHTML($project));
142 if ($action ne "") {
143 print " / $action";
145 print "</div>\n";
148 sub git_footer_html {
149 print "<div class=\"page_footer\">";
150 print "<div class=\"page_footer_text\">version $version</div>";
151 if ($project ne '') {
152 print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "xml_logo"}, "XML") . "\n";
154 print "</div>" .
155 "</body>" .
156 "</html>";
159 sub die_error {
160 my $status = shift || "403 Forbidden";
161 my $error = shift || "Malformed query, file missing or permission denied";
163 $project = "";
164 $action = "";
165 git_header_html($status);
166 print "<div class=\"page_body\">\n" .
167 "<br/><br/>\n";
168 print "$error\n";
169 print "<br/></div>\n";
170 git_footer_html();
171 exit 0;
174 sub git_head {
175 my $path = shift;
176 open(my $fd, "$projectroot/$path/HEAD") || die_error("", "Invalid project directory.");;
177 my $head = <$fd>;
178 close $fd;
179 chomp $head;
180 return $head;
183 sub git_commit {
184 my $commit = shift;
185 my %co;
186 my @parents;
188 open my $fd, "-|", "$gitbin/git-cat-file commit $commit";
189 while (my $line = <$fd>) {
190 chomp($line);
191 last if $line eq "";
192 if ($line =~ m/^tree (.*)$/) {
193 $co{'tree'} = $1;
194 } elsif ($line =~ m/^parent (.*)$/) {
195 push @parents, $1;
196 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
197 $co{'author'} = $1;
198 $co{'author_epoch'} = $2;
199 $co{'author_tz'} = $3;
200 $co{'author_name'} = $co{'author'};
201 $co{'author_name'} =~ s/ <.*//;
202 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
203 $co{'committer'} = $1;
204 $co{'committer_epoch'} = $2;
205 $co{'committer_tz'} = $3;
206 $co{'committer_name'} = $co{'committer'};
207 $co{'committer_name'} =~ s/ <.*//;
210 if (!defined($co{'tree'})) {
211 return;
213 $co{'parents'} = \@parents;
214 $co{'parent'} = $parents[0];
215 my (@comment) = map { chomp; $_ } <$fd>;
216 $co{'comment'} = \@comment;
217 $co{'title'} = $comment[0];
218 close $fd;
220 my $age = time - $co{'committer_epoch'};
221 $co{'age'} = $age;
222 if ($age > 60*60*24*365*2) {
223 $co{'age_string'} = (int $age/60/60/24/365);
224 $co{'age_string'} .= " years ago";
225 } elsif ($age > 60*60*24*365/12*2) {
226 $co{'age_string'} = int $age/60/60/24/365/12;
227 $co{'age_string'} .= " months ago";
228 } elsif ($age > 60*60*24*7*2) {
229 $co{'age_string'} = int $age/60/60/24/7;
230 $co{'age_string'} .= " weeks ago";
231 } elsif ($age > 60*60*24*2) {
232 $co{'age_string'} = int $age/60/60/24;
233 $co{'age_string'} .= " days ago";
234 } elsif ($age > 60*60*2) {
235 $co{'age_string'} = int $age/60/60;
236 $co{'age_string'} .= " hours ago";
237 } elsif ($age > 60*2) {
238 $co{'age_string'} = int $age/60;
239 $co{'age_string'} .= " minutes ago";
241 return %co;
244 sub git_diff_html {
245 my $from_name = shift || "/dev/null";
246 my $to_name = shift || "/dev/null";
247 my $from = shift;
248 my $to = shift;
250 my $from_tmp = "/dev/null";
251 my $to_tmp = "/dev/null";
252 my $from_label = "/dev/null";
253 my $to_label = "/dev/null";
254 my $pid = $$;
256 # create tmp from-file
257 if ($from ne "") {
258 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
259 open(my $fd2, "> $from_tmp");
260 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
261 my @file = <$fd>;
262 print $fd2 @file;
263 close $fd2;
264 close $fd;
265 $from_label = "a/$from_name";
268 # create tmp to-file
269 if ($to ne "") {
270 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
271 open my $fd2, "> $to_tmp";
272 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
273 my @file = <$fd>;
274 print $fd2 @file;
275 close $fd2;
276 close $fd;
277 $to_label = "b/$to_name";
280 open my $fd, "-|", "/usr/bin/diff -u -p -L $from_label -L $to_label $from_tmp $to_tmp";
281 print "<span style=\"color: #000099;\">===== ";
282 if ($from ne "") {
283 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from"}, $from);
284 } else {
285 print $from_name;
287 print " vs ";
288 if ($to ne "") {
289 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to"}, $to);
290 } else {
291 print $to_name;
293 print " =====</span>\n";
294 while (my $line = <$fd>) {
295 my $char = substr($line,0,1);
296 print '<span style="color: #008800;">' if $char eq '+';
297 print '<span style="color: #CC0000;">' if $char eq '-';
298 print '<span style="color: #990099;">' if $char eq '@';
299 print escapeHTML($line);
300 print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
302 close $fd;
304 if ($from ne "") {
305 unlink("$from_tmp");
307 if ($to ne "") {
308 unlink("$to_tmp");
312 sub mode_str {
313 my $perms = oct shift;
314 my $modestr;
315 if ($perms & 040000) {
316 $modestr .= 'drwxr-xr-x';
317 } else {
318 # git cares only about the executable bit
319 if ($perms & 0100) {
320 $modestr .= '-rwxr-xr-x';
321 } else {
322 $modestr .= '-rw-r--r--';
325 return $modestr;
328 sub date_str {
329 my $epoch = shift;
330 my $tz = shift || "-0000";
332 my %date;
333 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
334 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
335 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
336 $date{'hour'} = $hour;
337 $date{'minute'} = $min;
338 $date{'mday'} = $mday;
339 $date{'day'} = $days[$wday];
340 $date{'month'} = $months[$mon];
341 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
342 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
344 $tz =~ m/((-|\+)[0-9][0-9])([0-9][0-9])/;
345 my $local = $epoch + (($1 + ($2/60)) * 3600);
346 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
347 $date{'hour_local'} = $hour;
348 $date{'minute_local'} = $min;
349 $date{'tz_local'} = $tz;
350 return %date;
353 if ($action eq "git-logo.png") {
354 print $cgi->header(-type => 'image/png', -expires => '+1d');
355 print "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
356 "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
357 "\055\000\000\000\030\120\114\124\105\377\377\377\140\140\135\260".
358 "\257\252\000\200\000\316\315\307\300\000\000\350\350\346\367\367".
359 "\366\225\014\247\107\000\000\000\163\111\104\101\124\050\317\143".
360 "\110\147\040\004\112\134\030\012\010\052\142\123\141\040\002\010".
361 "\015\151\105\254\241\241\001\060\014\223\140\066\046\122\221\261".
362 "\001\021\326\341\125\144\154\154\314\154\154\014\242\014\160\052".
363 "\142\006\052\301\142\035\263\001\002\123\244\010\350\000\003\030".
364 "\046\126\021\324\341\040\227\033\340\264\016\065\044\161\051\202".
365 "\231\060\270\223\012\021\271\105\210\301\215\240\242\104\041\006".
366 "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305".
367 "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202";
368 exit;
371 if (!defined($project)) {
372 print $cgi->redirect($home_link);
373 exit;
376 if (!defined($action)) {
377 $action = "log";
380 if (!defined($time_back)) {
381 $time_back = 1;
384 if ($action eq "blob") {
385 git_header_html();
386 print "<div class=\"page_nav\">\n";
387 print "<br/><br/></div>\n";
388 print "<div class=\"title\">$hash</div>\n";
389 print "<div class=\"page_body\"><pre>\n";
390 open(my $fd, "-|", "$gitbin/git-cat-file blob $hash");
391 my $nr;
392 while (my $line = <$fd>) {
393 $nr++;
394 printf "<span style =\"color: #999999;\">%4i\t</span>%s", $nr, escapeHTML($line);;
396 close $fd;
397 print "<br/></pre>\n";
398 print "</div>";
399 git_footer_html();
400 } elsif ($action eq "tree") {
401 if ($hash eq "") {
402 $hash = git_head($project);
404 open my $fd, "-|", "$gitbin/git-ls-tree $hash";
405 my (@entries) = map { chomp; $_ } <$fd>;
406 close $fd;
408 git_header_html();
409 my %co = git_commit($hash);
410 if (defined(%co)) {
411 print "<div class=\"page_nav\"> view\n" .
412 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
413 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . " | \n" .
414 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash"}, "tree") . "\n" .
415 "<br/><br/></div>\n";
416 print "<div>\n" .
417 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "log_title"}, escapeHTML($co{'title'})) . "\n" .
418 "</div>\n";
419 } else {
420 print "<div class=\"page_nav\">\n";
421 print "<br/><br/></div>\n";
422 print "<div class=\"title\">$hash</div>\n";
424 print "<div class=\"page_body\">\n";
425 print "<br/><pre>\n";
426 foreach my $line (@entries) {
427 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
428 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
429 my $t_mode = $1;
430 my $t_type = $2;
431 my $t_hash = $3;
432 my $t_name = $4;
433 if ($t_type eq "blob") {
434 print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash"}, $t_name) . "\n";
435 } elsif ($t_type eq "tree") {
436 print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash"}, $t_name) . "\n";
439 print "</pre>\n";
440 print "<br/></div>";
441 git_footer_html();
442 } elsif ($action eq "log" || $action eq "rss") {
443 open my $fd, "-|", "$gitbin/git-rev-list " . git_head($project);
444 my (@revlist) = map { chomp; $_ } <$fd>;
445 close $fd;
447 if ($action eq "log") {
448 git_header_html();
449 print "<div class=\"page_nav\">\n";
450 print "view ";
451 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, "last day") . " | \n" .
452 $cgi->a({-href => "$my_uri?p=$project;a=log;t=7"}, "week") . " | \n" .
453 $cgi->a({-href => "$my_uri?p=$project;a=log;t=31"}, "month") . " | \n" .
454 $cgi->a({-href => "$my_uri?p=$project;a=log;t=365"}, "year") . " | \n" .
455 $cgi->a({-href => "$my_uri?p=$project;a=log;t=0"}, "all") . "<br/>\n";
456 print "<br/><br/>\n" .
457 "</div>\n";
458 } elsif ($action eq "rss") {
459 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
460 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
461 "<rss version=\"0.91\">\n";
462 print "<channel>\n";
463 print "<title>$project</title>\n".
464 "<link> " . $my_url . "/$project/log</link>\n".
465 "<description>$project log</description>\n".
466 "<language>en</language>\n";
469 for (my $i = 0; $i <= $#revlist; $i++) {
470 my $commit = $revlist[$i];
471 my %co = git_commit($commit);
472 my %ad = date_str($co{'author_epoch'});
473 if ($action eq "log") {
474 if ($time_back > 0 && $co{'age'} > $time_back*60*60*24) {
475 if ($i == 0) {
476 print "<div class=\"page_body\"> Last change " . $co{'age_string'} . ".<br/><br/></div>\n";
478 last;
480 print "<div>\n" .
481 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "log_title"},
482 "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
483 "</div>\n";
484 print "<div class=\"log_head\">\n" .
485 "<div class=\"log_link\">\n" .
486 "view " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") . " | " .
487 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "diff") . "<br/>\n" .
488 "</div>\n" .
489 escapeHTML($co{'author_name'}) . " [" . $ad{'rfc2822'} . "]<br/>\n" .
490 "</div>\n" .
491 "<div class=\"log_body\">\n";
492 my $comment = $co{'comment'};
493 foreach my $line (@$comment) {
494 last if ($line =~ m/^(signed-off|acked)-by:/i);
495 print escapeHTML($line) . "<br/>\n";
497 print "<br/>\n" .
498 "</div>\n";
499 } elsif ($action eq "rss") {
500 last if ($i >= 20);
501 print "<item>\n" .
502 "\t<title>" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'min'}) . " - " . escapeHTML($co{'title'}) . "</title>\n" .
503 "\t<link> " . $my_url . "?p=$project;a=commit;h=$commit</link>\n" .
504 "\t<description>";
505 my $comment = $co{'comment'};
506 foreach my $line (@$comment) {
507 print escapeHTML($line) . "\n";
509 print "\t</description>\n" .
510 "</item>\n";
513 if ($action eq "log") {
514 git_footer_html();
515 } elsif ($action eq "rss") {
516 print "</channel></rss>";
518 } elsif ($action eq "commit") {
519 my %co = git_commit($hash);
520 if (!defined(%co)) {
521 die_error("", "Unknown commit object.");
523 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
524 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
525 open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash";
526 my (@difftree) = map { chomp; $_ } <$fd>;
527 close $fd;
529 git_header_html();
530 print "<div class=\"page_nav\"> view\n" .
531 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
532 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . " | \n" .
533 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash"}, "tree") . "\n" .
534 "<br/><br/></div>\n";
535 print "<div>\n" .
536 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "log_title"}, escapeHTML($co{'title'})) . "\n" .
537 "</div>\n";
538 print "<div class=\"log_head\">\n";
539 print "author &nbsp; &nbsp; &nbsp;" . escapeHTML($co{'author'}) . "<br/>\n";
540 print "author-time " . $ad{'rfc2822'};
541 if ($ad{'hour_local'} < 6) { print "<span style=\"color: #cc0000;\">"; }
542 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
543 if ($ad{'hour_local'} < 6 ) { print "</span>"; }
544 print "<br/>\n";
545 print "committer &nbsp; " . escapeHTML($co{'committer'}) . "<br/>\n";
546 print "commit-time " . $cd{'rfc2822'};
547 printf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'});
548 print "<br/>\n";
549 print "commit &nbsp &nbsp; &nbsp;$hash<br/>\n";
550 print "tree &nbsp; &nbsp; &nbsp; &nbsp" . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash"}, $co{'tree'}) . "<br/>\n";
551 my $parents = $co{'parents'};
552 foreach my $par (@$parents) {
553 print "parent &nbsp; &nbsp &nbsp" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, $par) . "<br/>\n";
555 print "</div>\n";
556 print "<div class=\"page_body\">\n";
557 my $comment = $co{'comment'};
558 foreach my $line (@$comment) {
559 if ($line =~ m/(signed-off|acked)-by:/i) {
560 print "<span style=\"color: #a9a8a1\">" . escapeHTML($line) . "</span><br/>\n";
561 } else {
562 print escapeHTML($line) . "<br/>\n";
565 print "<br/><br/>\n" .
566 "</div>\n";
567 foreach my $line (@difftree) {
568 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
569 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
570 # '*100664->100644 blob b1a8e3dd5556b61dd771d32307c6ee5d7150fa43->b1a8e3dd5556b61dd771d32307c6ee5d7150fa43 show-files.c'
571 # '*100664->100644 blob d08e895238bac36d8220586fdc28c27e1a7a76d3->d08e895238bac36d8220586fdc28c27e1a7a76d3 update-cache.c'
572 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
573 my $op = $1;
574 my $mode = $2;
575 my $type = $3;
576 my $id = $4;
577 my $file = $5;
578 my $mode_chng = "";
579 if ($type eq "blob") {
580 if ($op eq "+") {
581 print "<div>\n" .
582 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id", -class => "list"},
583 escapeHTML($file) . " <span style=\"color: #008000;\">[new]</span>") . "\n" .
584 "</div>";
585 print "<div class=\"link\">\n" .
586 "view " .
587 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, "file") . "<br/><br/>\n" .
588 "</div>\n";
589 } elsif ($op eq "-") {
590 print "<div>\n" .
591 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id", -class => "list"},
592 escapeHTML($file) . " <span style=\"color: #c00000;\">[removed]</span>") . "\n" .
593 "</div>";
594 print "<div class=\"link\">\n" .
595 "view " .
596 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, "file") . " | " .
597 $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "<br/><br/>\n" .
598 "</div>\n";
599 } elsif ($op eq "*") {
600 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
601 my $from_id = $1;
602 my $to_id = $2;
603 $mode =~ m/^([0-7]{6})->([0-7]{6})$/;
604 my $from_mode = $1;
605 my $to_mode = $2;
606 my $mode_chnge = "";
607 if ($from_mode != $to_mode) {
608 $mode_chnge = " <span style=\"color: #555555;\"> [chmod $mode]</span>\n";
610 print "<div>\n" .
611 $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id", -class => "list"},
612 escapeHTML($file) . $mode_chnge) . "\n" .
613 "</div>\n";
614 print "<div class=\"link\">\n" .
615 "view ";
616 if ($to_id ne $from_id) {
617 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id"}, "diff") . " | ";
619 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id"}, "file") . " | " .
620 $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "<br/><br/>\n" .
621 "</div>\n";
625 git_footer_html();
626 } elsif ($action eq "blobdiff") {
627 git_header_html();
628 print "<div class=\"page_nav\">\n";
629 print "<br/><br/></div>\n";
630 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
631 print "<div class=\"page_body\">\n" .
632 "<pre>\n";
633 git_diff_html($hash_parent, $hash, $hash_parent, $hash);
634 print "</pre>\n" .
635 "<br/></div>";
636 git_footer_html();
637 } elsif ($action eq "commitdiff") {
638 my %co = git_commit($hash);
639 if (!defined(%co)) {
640 die_error("", "Unknown commit object.");
642 open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash";
643 my (@difftree) = map { chomp; $_ } <$fd>;
644 close $fd;
646 git_header_html();
647 print "<div class=\"page_nav\"> view\n" .
648 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
649 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . " | \n" .
650 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash"}, "tree") . "\n" .
651 "<br/><br/></div>\n";
652 print "<div>\n" .
653 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "log_title"}, escapeHTML($co{'title'})) . "\n" .
654 "</div>\n";
655 print "<div class=\"page_body\">\n" .
656 "<pre>\n";
657 foreach my $line (@difftree) {
658 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
659 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
660 my $op = $1;
661 my $mode = $2;
662 my $type = $3;
663 my $id = $4;
664 my $file = $5;
665 if ($type eq "blob") {
666 if ($op eq "+") {
667 git_diff_html("", $file, "", $id);
668 } elsif ($op eq "-") {
669 git_diff_html($file, "", $id, "");
670 } elsif ($op eq "*") {
671 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
672 if ($1 ne $2) {
673 git_diff_html($file, $file, $1, $2);
678 print "<br/></pre>\n";
679 print "</div>";
680 git_footer_html();
681 } elsif ($action eq "history") {
682 if (!(defined($hash))) {
683 $hash = git_head($project);
685 open my $fd, "-|", "$gitbin/git-rev-list $hash";
686 my (@revlist) = map { chomp; $_ } <$fd>;
687 close $fd;
689 git_header_html();
690 print "<div class=\"page_nav\">\n";
691 print "<br/><br/></div>\n";
692 print "<div>\n" .
693 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "log_title"}, escapeHTML($file_name)) . "\n" .
694 "</div>\n";
695 print "<div class=\"page_body\">\n" .
696 "<br/>\n" .
697 "</div>\n";
698 foreach my $rev (@revlist) {
699 my %co = git_commit($rev);
700 my $parents = $co{'parents'};
701 my $found = 0;
702 foreach my $parent (@$parents) {
703 open $fd, "-|", "$gitbin/git-diff-tree -r $parent $rev $file_name";
704 my (@difftree) = map { chomp; $_ } <$fd>;
705 close $fd;
707 foreach my $line (@difftree) {
708 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
709 my $file = $5;
710 if ($file eq $file_name) {
711 $found = 1;
712 last;
716 if ($found) {
717 print "<div class=\"list\">\n" .
718 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$rev"},
719 "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
720 "<div class=\"link\">\n" .
721 "view " .
722 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$rev"}, "commit") . " | " .
723 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$rev"}, "tree") . "<br/><br/>\n" .
724 "</div>\n" .
725 "</div>\n";
728 git_footer_html();
729 } else {
730 die_error("", "unknown action");