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