1#!/usr/bin/perl
2
3# gitweb.pl - simple web interface to track changes in git repositories
4#
5# (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
6# (C) 2005, Christian Gierke <ch@gierke.de>
7#
8# This file is licensed under the GPL v2, or a later version
9
10use strict;
11use warnings;
12use CGI qw(:standard :escapeHTML);
13use CGI::Carp qw(fatalsToBrowser);
14
15my $cgi = new CGI;
16
17my $version = "055";
18my $projectroot = "/home/kay/public_html/pub/scm";
19my $defaultprojects = "linux/kernel/git";
20my $gitbin = "/home/kay/bin/git";
21my $gittmp = "/tmp";
22my $my_url = $cgi->url();
23my $my_uri = $cgi->url(-absolute => 1);
24
25my $project = $cgi->param('p');
26my $action = $cgi->param('a');
27my $hash = $cgi->param('h');
28my $hash_parent = $cgi->param('hp');
29my $time_back = $cgi->param('t');
30$ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
31
32# validate input
33if (defined($project) && $project =~ /(^|\/)(|\.|\.\.)($|\/)/) {
34 error_page("403 Permission denied", "Invalid project parameter.");
35}
36if (defined($action) && !$action =~ m/^[0-9a-zA-Z\.\-]+$/) {
37 error_page("403 Permission denied", "Invalid action parameter.");
38}
39if (defined($hash) && !($hash =~ m/^[0-9a-fA-F]{40}$/)) {
40 error_page("403 Permission denied", "Invalid hash parameter.");
41}
42if (defined($hash_parent) && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
43 error_page("403 Permission denied", "Invalid parent hash parameter.");
44}
45if (defined($time_back) && !($time_back =~ m/^[0-9]+$/)) {
46 error_page("403 Permission denied", "Invalid time parameter.");
47} else {
48 $time_back = 1;
49}
50
51sub git_header_html {
52 my $status = shift || "200 OK";
53
54 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status);
55 print <<EOF;
56<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
57<html>
58<head>
59 <title>git - $project $action</title>
60 <link rel="alternate" title="$project log" href="$my_uri?p=$project;a=rss" type="application/rss+xml"/>
61 <style type="text/css">
62 body { font-family: sans-serif; font-size: 12px; margin:0px; }
63 a { color:#0000cc; }
64 a:hover { color:#880000; }
65 a:visited { color:#880000; }
66 a:active { color:#880000; }
67 div.page_header {
68 margin:15px 25px 0px; height:25px; padding:8px;
69 font-size:18px; clear:both; font-weight:bold; background-color: #d9d8d1;
70 }
71 div.page_header a:visited { color:#0000cc; }
72 div.page_nav { margin:0px 25px; padding:8px; clear:both; border:solid #d9d8d1; border-width:0px 1px; }
73 div.page_nav a:visited { color:#0000cc; }
74 div.page_footer {
75 margin:0px 25px 15px; height:17px; padding:4px; padding-left:8px;
76 clear:both; background-color: #d9d8d1;
77 }
78 div.page_footer_text { float:left; color:#888888; font-size:10px;}
79 div.page_body { margin:0px 25px; padding:8px; clear:both; border: solid #d9d8d1; border-width:0px 1px; }
80 a.log_title {
81 display:block; margin:0px 25px; padding:8px; clear:both;
82 font-weight:bold; background-color: #d9d8d1; text-decoration:none; color:#000000;
83 }
84 a.log_title:hover { background-color: #c9c8c1; }
85 a.xml_logo { float:right; border:1px solid;
86 line-height:15px;
87 border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e; width:35px;
88 color:#ffffff; background-color:#ff6600;
89 font-weight:bold; font-family:sans-serif; text-align:center;
90 font-size:11px; display:block; text-decoration:none;
91 }
92 a.xml_logo:hover { background-color:#ee5500; }
93 div.log_head {
94 margin:0px 25px; min-height: 30px; padding:8px; clear:both;
95 border: solid #d9d8d1; border-width:0px 1px; font-family:monospace;
96 background-color: #edece6;
97 }
98 div.log_body {
99 margin:0px 25px; padding:8px; padding-left:150px; clear:both;
100 border:solid #d9d8d1; border-width:0px 1px;
101 }
102 span.log_age { position:relative; float:left; width:142px; }
103 div.log_functions { font-size:10px; font-family:sans-serif; position:relative; float:left; width:142px; }
104 div.signed_off { color: #a9a8a1; }
105 </style>
106</head>
107<body>
108EOF
109 print "<div class=\"page_header\">\n" .
110 "<a href=\"http://kernel.org/pub/software/scm/git/\">" .
111 "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
112 if ($defaultprojects ne "") {
113 print $cgi->a({-href => "$my_uri"}, "projects") . " / ";
114 }
115 if ($project ne "") {
116 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, $project);
117 }
118 if ($action ne "") {
119 print " / $action";
120 }
121 print "</div>\n";
122}
123
124sub git_footer_html {
125 print "<div class=\"page_footer\">";
126 print "<div class=\"page_footer_text\">version $version</div>";
127 if ($project ne '') {
128 print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "xml_logo"}, "XML") . "\n";
129 }
130 print "</div>";
131 print "</body>\n</html>";
132}
133
134sub error_page {
135 my $status = shift || "403 Permission denied";
136 my $error = shift || "Malformed query, file missing or permission denied";
137 git_header_html($status);
138 print "<div class=\"page_body\">\n" .
139 "<br/><br/>\n";
140 print "$error\n";
141 print "<br/></div>\n";
142 git_footer_html();
143 exit 0;
144}
145
146sub git_head {
147 my $path = shift;
148 open my $fd, "$projectroot/$path/HEAD";
149 my $head = <$fd>;
150 close $fd;
151 chomp $head;
152 return $head;
153}
154
155sub git_commit {
156 my $commit = shift;
157 my %co;
158 my @parents;
159
160 open my $fd, "-|", "$gitbin/cat-file commit $commit";
161 while (my $line = <$fd>) {
162 chomp($line);
163 last if $line eq "";
164 if ($line =~ m/^tree (.*)$/) {
165 $co{'tree'} = $1;
166 } elsif ($line =~ m/^parent (.*)$/) {
167 push @parents, $1;
168 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
169 $co{'author'} = $1;
170 $co{'author_epoch'} = $2;
171 $co{'author_tz'} = $3;
172 $co{'author_name'} = $co{'author'};
173 $co{'author_name'} =~ s/ <.*//;
174 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
175 $co{'committer'} = $1;
176 $co{'committer_epoch'} = $2;
177 $co{'committer_tz'} = $3;
178 $co{'committer_name'} = $co{'committer'};
179 $co{'committer_name'} =~ s/ <.*//;
180 }
181 }
182 $co{'parents'} = \@parents;
183 $co{'parent'} = $parents[0];
184 my (@comment) = map { chomp; $_ } <$fd>;
185 $co{'comment'} = \@comment;
186 $co{'title'} = $comment[0];
187 close $fd;
188 return %co;
189}
190
191sub git_diff_html {
192 my $from_name = shift || "/dev/null";
193 my $to_name = shift || "/dev/null";
194 my $from = shift;
195 my $to = shift;
196
197 my $from_tmp = "/dev/null";
198 my $to_tmp = "/dev/null";
199 my $from_label = "/dev/null";
200 my $to_label = "/dev/null";
201 my $pid = $$;
202
203 # create tmp from-file
204 if ($from ne "") {
205 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
206 open my $fd2, "> $from_tmp";
207 open my $fd, "-|", "$gitbin/cat-file blob $from";
208 my @file = <$fd>;
209 print $fd2 @file;
210 close $fd2;
211 close $fd;
212 $from_label = "a/$from_name";
213 }
214
215 # create tmp to-file
216 if ($to ne "") {
217 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
218 open my $fd2, "> $to_tmp";
219 open my $fd, "-|", "$gitbin/cat-file blob $to";
220 my @file = <$fd>;
221 print $fd2 @file;
222 close $fd2;
223 close $fd;
224 $to_label = "b/$to_name";
225 }
226
227 open my $fd, "-|", "/usr/bin/diff -u -p -L $from_label -L $to_label $from_tmp $to_tmp";
228 print "<span style=\"color: #000099;\">===== ";
229 if ($from ne "") {
230 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from"}, $from);
231 } else {
232 print $from_name;
233 }
234 print " vs ";
235 if ($to ne "") {
236 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to"}, $to);
237 } else {
238 print $to_name;
239 }
240 print " =====</span>\n";
241 while (my $line = <$fd>) {
242 my $char = substr($line,0,1);
243 print '<span style="color: #008800;">' if $char eq '+';
244 print '<span style="color: #CC0000;">' if $char eq '-';
245 print '<span style="color: #990099;">' if $char eq '@';
246 print escapeHTML($line);
247 print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
248 }
249 close $fd;
250
251 if ($from ne "") {
252 unlink("$from_tmp");
253 }
254 if ($to ne "") {
255 unlink("$to_tmp");
256 }
257}
258
259sub mode_str {
260 my $perms = oct shift;
261 my $modestr;
262 if ($perms & 040000) {
263 $modestr .= 'drwxrwxr-x';
264 } else {
265 # git cares only about the executable bit
266 if ($perms & 0100) {
267 $modestr .= '-rwxrwxr-x';
268 } else {
269 $modestr .= '-rw-rw-r--';
270 };
271 }
272 return $modestr;
273}
274
275sub date_str {
276 my $epoch = shift;
277 my $tz = shift || "-0000";
278
279 my %date;
280 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
281 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
282 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
283 $date{'hour'} = $hour;
284 $date{'minute'} = $min;
285 $date{'mday'} = $mday;
286 $date{'day'} = $days[$wday];
287 $date{'month'} = $months[$mon];
288 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
289 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
290
291 $tz =~ m/((-|\+)[0-9][0-9])([0-9][0-9])/;
292 my $local = $epoch + (($1 + ($2/60)) * 3600);
293 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
294 $date{'hour_local'} = $hour;
295 $date{'minute_local'} = $min;
296 $date{'tz_local'} = $tz;
297 return %date;
298}
299
300if ($action eq "git-logo.png") {
301 print $cgi->header(-type => 'image/png', -expires => '+1d');
302 print "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
303 "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
304 "\055\000\000\000\030\120\114\124\105\377\377\377\140\140\135\260".
305 "\257\252\000\200\000\316\315\307\300\000\000\350\350\346\367\367".
306 "\366\225\014\247\107\000\000\000\163\111\104\101\124\050\317\143".
307 "\110\147\040\004\112\134\030\012\010\052\142\123\141\040\002\010".
308 "\015\151\105\254\241\241\001\060\014\223\140\066\046\122\221\261".
309 "\001\021\326\341\125\144\154\154\314\154\154\014\242\014\160\052".
310 "\142\006\052\301\142\035\263\001\002\123\244\010\350\000\003\030".
311 "\046\126\021\324\341\040\227\033\340\264\016\065\044\161\051\202".
312 "\231\060\270\223\012\021\271\105\210\301\215\240\242\104\041\006".
313 "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305".
314 "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202";
315 exit;
316}
317
318# show list of default projects
319if ($project eq "") {
320 opendir(my $fd, "$projectroot/$defaultprojects");
321 my (@users) = sort grep(!/^\./, readdir($fd));
322 closedir($fd);
323 git_header_html();
324 print "<div class=\"page_body\">\n";
325 print "<br/><br/>\n";
326 foreach my $user (@users) {
327 opendir($fd, "$projectroot/$defaultprojects/$user");
328 my (@repos) = sort grep(/\.git$/, readdir($fd));
329 closedir($fd);
330 foreach my $repo (@repos) {
331 if (-e "$projectroot/$defaultprojects/$user/$repo/HEAD") {
332 print $cgi->a({-href => "$my_uri?p=$defaultprojects/$user/$repo;a=log"}, "$defaultprojects/$user/$repo") . "<br/>\n";
333 }
334 }
335 }
336 print "<br/></div>";
337 git_footer_html();
338 exit;
339}
340
341if ($action eq "") {
342 $action = "log";
343}
344
345if ($action eq "blob") {
346 git_header_html();
347 print "<div class=\"page_body\"><pre><br/><br/>\n";
348 open my $fd, "-|", "$gitbin/cat-file blob $hash";
349 my $nr;
350 while (my $line = <$fd>) {
351 $nr++;
352 printf "<span style =\"color: #999999;\">%4i\t</span>%s", $nr, escapeHTML($line);;
353 }
354 close $fd;
355 print "<br/><br/></pre>\n";
356 print "</div>";
357 git_footer_html();
358} elsif ($action eq "tree") {
359 if ($hash eq "") {
360 $hash = git_head($project);
361 }
362 open my $fd, "-|", "$gitbin/ls-tree $hash";
363 my (@entries) = map { chomp; $_ } <$fd>;
364 close $fd;
365 git_header_html();
366 print "<div class=\"page_body\">\n";
367 print "<br/><pre>\n";
368 foreach my $line (@entries) {
369 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
370 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
371 my $t_mode = $1;
372 my $t_type = $2;
373 my $t_hash = $3;
374 my $t_name = $4;
375 if ($t_type eq "blob") {
376 print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash"}, $t_name) . "\n";
377 } elsif ($t_type eq "tree") {
378 print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash"}, $t_name) . "\n";
379 }
380 }
381 print "</pre>\n";
382 print "<br/></div>";
383 git_footer_html();
384} elsif ($action eq "log" || $action eq "rss") {
385 open my $fd, "-|", "$gitbin/rev-list " . git_head($project);
386 my (@revtree) = map { chomp; $_ } <$fd>;
387 close $fd;
388
389 if ($action eq "log") {
390 git_header_html();
391 print "<div class=\"page_nav\">\n";
392 print "view ";
393 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, "last day") . " | \n" .
394 $cgi->a({-href => "$my_uri?p=$project;a=log;t=7"}, "week") . " | \n" .
395 $cgi->a({-href => "$my_uri?p=$project;a=log;t=31"}, "month") . " | \n" .
396 $cgi->a({-href => "$my_uri?p=$project;a=log;t=365"}, "year") . " | \n" .
397 $cgi->a({-href => "$my_uri?p=$project;a=log;t=0"}, "all") . "<br/>\n";
398 print "<br/><br/>\n" .
399 "</div>\n";
400 } elsif ($action eq "rss") {
401 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
402 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
403 "<rss version=\"0.91\">\n";
404 print "<channel>\n";
405 print "<title>$project</title>\n".
406 "<link> " . $my_url . "/$project/log</link>\n".
407 "<description>$project log</description>\n".
408 "<language>en</language>\n";
409 }
410
411 for (my $i = 0; $i <= $#revtree; $i++) {
412 my $commit = $revtree[$i];
413 my %co = git_commit($commit);
414 my %ad = date_str($co{'author_epoch'});
415 my $age = time - $co{'committer_epoch'};
416 my $age_string;
417 if ($age > 60*60*24*365*2) {
418 $age_string = int $age/60/60/24/365;
419 $age_string .= " years ago";
420 } elsif ($age > 60*60*24*365/12*2) {
421 $age_string = int $age/60/60/24/365/12;
422 $age_string .= " months ago";
423 } elsif ($age > 60*60*24*7*2) {
424 $age_string = int $age/60/60/24/7;
425 $age_string .= " weeks ago";
426 } elsif ($age > 60*60*24*2) {
427 $age_string = int $age/60/60/24;
428 $age_string .= " days ago";
429 } elsif ($age > 60*60*2) {
430 $age_string = int $age/60/60;
431 $age_string .= " hours ago";
432 } elsif ($age > 60*2) {
433 $age_string = int $age/60;
434 $age_string .= " minutes ago";
435 }
436 if ($action eq "log") {
437 if ($time_back > 0 && $age > $time_back*60*60*24) {
438 if ($i == 0) {
439 print "<div class=\"page_body\"> Last change $age_string.<br/><br/></div>\n";
440 }
441 last;
442 }
443 print "<div><a href=\"$my_uri?p=$project;a=commit;h=$commit\" class=\"log_title\">\n" .
444 "<span class=\"log_age\">" . $age_string . "</span>\n" . escapeHTML($co{'title'}) . "</a>\n" .
445 "</div>\n";
446 print "<div class=\"log_head\">\n" .
447 "<div class=\"log_functions\">\n" .
448 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "view commit") . "<br/>\n" .
449 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "view diff") . "<br/>\n" .
450 "</div>\n" .
451 escapeHTML($co{'author_name'}) . " [" . $ad{'rfc2822'} . "]<br/>\n" .
452 "</div>\n" .
453 "<div class=\"log_body\">\n";
454 my $comment = $co{'comment'};
455 foreach my $line (@$comment) {
456 if ($line =~ m/^(signed-off|acked)-by:/i) {
457 print '<div class="signed_off">' . escapeHTML($line) . "<br/></div>\n";
458 } else {
459 print escapeHTML($line) . "<br/>\n";
460 }
461 }
462 print "<br/><br/>\n" .
463 "</div>\n";
464 } elsif ($action eq "rss") {
465 last if ($i >= 20);
466 print "<item>\n" .
467 "\t<title>" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'min'}) . " - " . escapeHTML($co{'title'}) . "</title>\n" .
468 "\t<link> " . $my_url . "?p=$project;a==commit;h=$commit</link>\n" .
469 "\t<description>";
470 my $comment = $co{'comment'};
471 foreach my $line (@$comment) {
472 print escapeHTML($line) . "\n";
473 }
474 print "\t</description>\n" .
475 "</item>\n";
476 }
477 }
478 if ($action eq "log") {
479 git_footer_html();
480 } elsif ($action eq "rss") {
481 print "</channel></rss>";
482 }
483} elsif ($action eq "commit") {
484 my %co = git_commit($hash);
485 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
486 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
487 open my $fd, "-|", "$gitbin/diff-tree -r " . $co{'parent'} . " $hash";
488 my (@difftree) = map { chomp; $_ } <$fd>;
489 close $fd;
490
491 git_header_html();
492 print "<div class=\"page_nav\"> view\n" .
493 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
494 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diff") . "\n" .
495 "<br/><br/></div>\n";
496 print "<a class=\"log_title\" href=\"$my_uri?p=$project;a=commitdiff;h=$hash\">$co{'title'}</a>\n";
497 print "<div class=\"log_head\">\n";
498 print "author " . escapeHTML($co{'author'}) . "<br/>\n";
499 print "author-time " . $ad{'rfc2822'};
500 if ($ad{'hour_local'} < 6) { print "<span style=\"color: #cc0000;\">"; }
501 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
502 if ($ad{'hour_local'} < 6 ) { print "</span>"; }
503 print "<br/>\n";
504 print "committer " . escapeHTML($co{'committer'}) . "<br/>\n";
505 print "commit-time " . $ad{'rfc2822'};
506 printf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'});
507 print "<br/>\n";
508 print "commit   $hash<br/>\n";
509 print "tree  " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'}"}, $co{'tree'}) . "<br/>\n";
510 my $parents = $co{'parents'};
511 foreach my $par (@$parents) {
512 print "parent    " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, $par) . "<br/>\n";
513 }
514 print "</div>\n";
515 print "<div class=\"page_body\">\n";
516 my $comment = $co{'comment'};
517 foreach my $line (@$comment) {
518 if ($line =~ m/(signed-off|acked)-by:/i) {
519 print '<div class="signed_off">' . escapeHTML($line) . "<br/></div>\n";
520 } else {
521 print escapeHTML($line) . "<br/>\n";
522 }
523 }
524 print "<br/><br/>\n";
525 print "<pre>\n";
526 foreach my $line (@difftree) {
527 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
528 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
529 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
530 my $op = $1;
531 my $mode = $2;
532 my $type = $3;
533 my $id = $4;
534 my $file = $5;
535 $mode =~ m/^([0-7]{6})/;
536 my $modestr = mode_str($1);
537 if ($type eq "blob") {
538 if ($op eq "+") {
539 print "$modestr " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$id"}, $file) . " (new)\n";
540 } elsif ($op eq "-") {
541 print "$modestr " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;hp=$id"}, $file) . " (removed)\n";
542 } elsif ($op eq "*") {
543 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
544 my $from = $1;
545 my $to = $2;
546 print "$modestr " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to;hp=$from"}, $file) . "\n";
547 }
548 }
549 }
550 print "</pre>\n" .
551 "<br/></div>\n";
552 git_footer_html();
553} elsif ($action eq "blobdiff") {
554 git_header_html();
555 print "<div class=\"page_body\"><br/><br/>\n" .
556 "<pre>\n";
557 git_diff_html($hash_parent, $hash, $hash_parent, $hash);
558 print "</pre>\n" .
559 "<br/></div>";
560 git_footer_html();
561} elsif ($action eq "commitdiff") {
562 my %co = git_commit($hash);
563 open my $fd, "-|", "$gitbin/diff-tree -r " . $co{'parent'} . " $hash";
564 my (@difftree) = map { chomp; $_ } <$fd>;
565 close $fd;
566
567 git_header_html();
568 print "<div class=\"page_nav\"> view\n" .
569 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
570 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diff") . "\n" .
571 "<br/><br/></div>\n";
572 print $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "log_title"}, $co{'title'}) ."\n";
573 print "<div class=\"page_body\">\n" .
574 "<pre>\n";
575 foreach my $line (@difftree) {
576 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
577 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
578 my $op = $1;
579 my $mode = $2;
580 my $type = $3;
581 my $id = $4;
582 my $file = $5;
583 if ($type eq "blob") {
584 if ($op eq "+") {
585 git_diff_html("", $file, "", $id);
586 } elsif ($op eq "-") {
587 git_diff_html($file, "", $id, "");
588 } elsif ($op eq "*") {
589 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
590 git_diff_html($file, $file, $1, $2);
591 }
592 }
593 }
594 print "<br/></pre>\n";
595 print "</div>";
596 git_footer_html();
597} else {
598 error_page("403 Forbidden", "unknown action");
599}