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