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 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);
27 my $project = $cgi->param('p');
28 if (defined($project)) {
29 if ($project =~ /(^|\/)(|\
.|\
.\
.)($|\
/)/) {
31 die_error
("", "Invalid project parameter.");
33 if (!(-d
"$projectroot/$project")) {
35 die_error
("", "No such project.");
37 $rss_link = "<link rel=\"alternate\" title=\"$project log\" href=\"$my_uri?p=$project;a=rss\" type=\"application/rss+xml\"/>";
40 my $file_name = $cgi->param('f');
41 if (defined($file_name) && $file_name =~ /(^|\/)(|\
.|\
.\
.)($|\
/)/) {
43 die_error
("", "Invalid file parameter.");
46 my $action = $cgi->param('a');
47 if (defined($action) && $action =~ m/[^0-9a-zA-Z\.\-]+$/) {
49 die_error
("", "Invalid action parameter.");
52 my $hash = $cgi->param('h');
53 if (defined($hash) && !($hash =~ m/^[0-9a-fA-F]{40}$/)) {
55 die_error
("", "Invalid hash parameter.");
58 my $hash_parent = $cgi->param('hp');
59 if (defined($hash_parent) && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
61 die_error
("", "Invalid parent hash parameter.");
64 my $time_back = $cgi->param('t');
65 if (defined($time_back) && !($time_back =~ m/^[0-9]+$/)) {
67 die_error
("", "Invalid time parameter.");
70 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
74 my $status = shift || "200 OK";
76 print $cgi->header(-type
=>'text/html', -charset
=> 'utf-8', -status
=> $status);
78 <?xml version="1.0" encoding="utf-8"?>
79 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
80 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
83 <title>git - $project</title>
85 <style type="text/css">
86 body { font-family: sans-serif; font-size: 12px; margin:0px; }
88 a:hover { color:#880000; }
89 a:visited { color:#880000; }
90 a:active { color:#880000; }
92 margin:15px 25px 0px; height:25px; padding:8px;
93 font-size:18px; font-weight:bold; background-color:#d9d8d1;
95 div.page_header a:visited { color:#0000cc; }
96 div.page_header a:hover { color:#880000; }
97 div.page_nav { margin:0px 25px; padding:8px; border:solid #d9d8d1; border-width:0px 1px; }
98 div.page_nav a:visited { color:#0000cc; }
99 div.page_footer { margin:0px 25px 15px; height:17px; padding:4px; padding-left:8px; background-color: #d9d8d1; }
100 div.page_footer_text { float:left; color:#555555; font-style:italic; }
101 div.page_body { margin:0px 25px; padding:8px; border:solid #d9d8d1; border-width:0px 1px; }
103 display:block; margin:0px 25px; padding:6px 8px;
104 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
106 a.title:hover { background-color: #d9d8d1; }
107 div.title_text { margin:0px 25px; padding:6px 8px; border: solid #d9d8d1; border-width:0px 1px 1px; }
108 div.log_body { margin:0px 25px; padding:8px; padding-left:150px; border:solid #d9d8d1; border-width:0px 1px; }
109 span.log_age { position:relative; float:left; width:142px; font-style:italic; }
110 div.log_link { font-size:10px; font-family:sans-serif; font-style:normal; position:relative; float:left; width:142px; }
112 display:block; margin:0px 25px; padding:4px 6px 2px; border:solid #d9d8d1; border-width:1px 1px 0px;
116 display:block; margin:0px 25px; padding:4px 6px 4px; border:solid #d9d8d1; border-width:1px 1px 0px;
119 div.list a { text-decoration:none; color:#000000; }
120 div.list a:hover { color:#880000; }
122 margin:0px 25px; padding:0px 6px 8px; border:solid #d9d8d1; border-width:0px 1px;
123 font-family:sans-serif; font-size:10px;
125 td.key { padding-right:10px; }
126 a.xml_logo { float:right; border:1px solid;
128 border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e; width:35px;
129 color:#ffffff; background-color:#ff6600;
130 font-weight:bold; font-family:sans-serif; text-align:center;
131 font-size:10px; display:block; text-decoration:none;
133 a.xml_logo:hover { background-color:#ee5500; }
138 print "<div class=\"page_header\">\n" .
139 "<a href=\"$logo_link\">" .
140 "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
141 print $cgi->a({-href
=> "$my_uri"}, "projects") . " / ";
142 if ($project ne "") {
143 print $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, escapeHTML
($project));
151 sub git_footer_html
{
152 print "<div class=\"page_footer\">\n";
153 if ($project ne "") {
154 if (-e
"$projectroot/$project/description") {
155 open(my $fd, "$projectroot/$project/description");
157 print "<div class=\"page_footer_text\">" . escapeHTML
($descr) . "</div>\n";
160 print $cgi->a({-href
=> "$my_uri?p=$project;a=rss", -class => "xml_logo"}, "XML") . "\n";
168 my $status = shift || "403 Forbidden";
169 my $error = shift || "Malformed query, file missing or permission denied";
171 git_header_html
($status);
172 print "<div class=\"page_body\">\n" .
174 print "$status - $error\n";
175 print "<br/></div>\n";
182 open(my $fd, "$projectroot/$path/HEAD") || die_error
("", "Invalid project directory.");
194 open my $fd, "-|", "$gitbin/cat-file commit $commit";
195 while (my $line = <$fd>) {
198 if ($line =~ m/^tree (.*)$/) {
200 } elsif ($line =~ m/^parent (.*)$/) {
202 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
204 $co{'author_epoch'} = $2;
205 $co{'author_tz'} = $3;
206 $co{'author_name'} = $co{'author'};
207 $co{'author_name'} =~ s/ <.*//;
208 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
209 $co{'committer'} = $1;
210 $co{'committer_epoch'} = $2;
211 $co{'committer_tz'} = $3;
212 $co{'committer_name'} = $co{'committer'};
213 $co{'committer_name'} =~ s/ <.*//;
216 if (!defined($co{'tree'})) {
219 $co{'parents'} = \
@parents;
220 $co{'parent'} = $parents[0];
221 my (@comment) = map { chomp; $_ } <$fd>;
222 $co{'comment'} = \
@comment;
223 $co{'title'} = $comment[0];
226 my $age = time - $co{'committer_epoch'};
228 if ($age > 60*60*24*365*2) {
229 $co{'age_string'} = (int $age/60/60/24/365);
230 $co{'age_string'} .= " years ago";
231 } elsif ($age > 60*60*24*365/12*2) {
232 $co{'age_string'} = int $age/60/60/24/365/12;
233 $co{'age_string'} .= " months ago";
234 } elsif ($age > 60*60*24*7*2) {
235 $co{'age_string'} = int $age/60/60/24/7;
236 $co{'age_string'} .= " weeks ago";
237 } elsif ($age > 60*60*24*2) {
238 $co{'age_string'} = int $age/60/60/24;
239 $co{'age_string'} .= " days ago";
240 } elsif ($age > 60*60*2) {
241 $co{'age_string'} = int $age/60/60;
242 $co{'age_string'} .= " hours ago";
243 } elsif ($age > 60*2) {
244 $co{'age_string'} = int $age/60;
245 $co{'age_string'} .= " minutes ago";
251 my $from_name = shift || "/dev/null";
252 my $to_name = shift || "/dev/null";
256 my $from_tmp = "/dev/null";
257 my $to_tmp = "/dev/null";
258 my $from_label = "/dev/null";
259 my $to_label = "/dev/null";
262 # create tmp from-file
264 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
265 open(my $fd2, "> $from_tmp");
266 open my $fd, "-|", "$gitbin/cat-file blob $from";
271 $from_label = "a/$from_name";
276 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
277 open my $fd2, "> $to_tmp";
278 open my $fd, "-|", "$gitbin/cat-file blob $to";
283 $to_label = "b/$to_name";
286 open my $fd, "-|", "/usr/bin/diff -u -p -L $from_label -L $to_label $from_tmp $to_tmp";
287 print "<span style=\"color: #000099;\">===== ";
289 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$from"}, $from);
295 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to"}, $to);
299 print " =====</span>\n";
300 while (my $line = <$fd>) {
301 my $char = substr($line,0,1);
302 print '<span style="color: #008800;">' if $char eq '+';
303 print '<span style="color: #CC0000;">' if $char eq '-';
304 print '<span style="color: #990099;">' if $char eq '@';
305 print escapeHTML
($line);
306 print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
319 my $perms = oct shift;
321 if ($perms & 040000) {
322 $modestr .= 'drwxr-xr-x';
324 # git cares only about the executable bit
326 $modestr .= '-rwxr-xr-x';
328 $modestr .= '-rw-r--r--';
336 my $tz = shift || "-0000";
339 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
340 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
341 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
342 $date{'hour'} = $hour;
343 $date{'minute'} = $min;
344 $date{'mday'} = $mday;
345 $date{'day'} = $days[$wday];
346 $date{'month'} = $months[$mon];
347 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
348 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
350 $tz =~ m/((-|\+)[0-9][0-9])([0-9][0-9])/;
351 my $local = $epoch + (($1 + ($2/60)) * 3600);
352 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
353 $date{'hour_local'} = $hour;
354 $date{'minute_local'} = $min;
355 $date{'tz_local'} = $tz;
359 if ($action eq "git-logo.png") {
360 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
361 print "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
362 "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
363 "\055\000\000\000\030\120\114\124\105\377\377\377\140\140\135\260".
364 "\257\252\000\200\000\316\315\307\300\000\000\350\350\346\367\367".
365 "\366\225\014\247\107\000\000\000\163\111\104\101\124\050\317\143".
366 "\110\147\040\004\112\134\030\012\010\052\142\123\141\040\002\010".
367 "\015\151\105\254\241\241\001\060\014\223\140\066\046\122\221\261".
368 "\001\021\326\341\125\144\154\154\314\154\154\014\242\014\160\052".
369 "\142\006\052\301\142\035\263\001\002\123\244\010\350\000\003\030".
370 "\046\126\021\324\341\040\227\033\340\264\016\065\044\161\051\202".
371 "\231\060\270\223\012\021\271\105\210\301\215\240\242\104\041\006".
372 "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305".
373 "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202";
377 if (!defined($project)) {
378 print $cgi->redirect($home_link);
382 if (!defined($action)) {
386 if (!defined($time_back)) {
390 if ($action eq "blob") {
392 print "<div class=\"page_nav\">\n";
393 print "<br/><br/></div>\n";
394 print "<div class=\"title\">$hash</div>\n";
395 print "<div class=\"page_body\"><pre>\n";
396 open(my $fd, "-|", "$gitbin/cat-file blob $hash");
398 while (my $line = <$fd>) {
400 printf "<span style =\"color: #999999;\">%4i\t</span>%s", $nr, escapeHTML
($line);;
403 print "<br/></pre>\n";
406 } elsif ($action eq "tree") {
408 $hash = git_head
($project);
410 open my $fd, "-|", "$gitbin/ls-tree $hash";
411 my (@entries) = map { chomp; $_ } <$fd>;
415 my %co = git_commit
($hash);
417 print "<div class=\"page_nav\"> view\n" .
418 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | " .
419 $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . " | " .
420 $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$hash"}, "tree") .
424 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML
($co{'title'})) . "\n" .
427 print "<div class=\"page_nav\">\n";
428 print "<br/><br/></div>\n";
429 print "<div class=\"title\">$hash</div>\n";
431 print "<div class=\"page_body\">\n";
432 print "<br/><pre>\n";
433 foreach my $line (@entries) {
434 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
435 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
440 if ($t_type eq "blob") {
441 print mode_str
($t_mode). " " . $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$t_hash"}, $t_name) . "\n";
442 } elsif ($t_type eq "tree") {
443 print mode_str
($t_mode). " " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$t_hash"}, $t_name) . "\n";
449 } elsif ($action eq "log" || $action eq "rss") {
450 open my $fd, "-|", "$gitbin/rev-list " . git_head
($project);
451 my (@revlist) = map { chomp; $_ } <$fd>;
454 if ($action eq "log") {
456 print "<div class=\"page_nav\">\n";
458 print $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, "last day") . " | " .
459 $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=7"}, "week") . " | " .
460 $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=31"}, "month") . " | " .
461 $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=365"}, "year") . " | " .
462 $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=0"}, "all") . "<br/>\n";
463 print "<br/><br/>\n" .
465 } elsif ($action eq "rss") {
466 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
467 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
468 "<rss version=\"0.91\">\n";
470 print "<title>$project</title>\n".
471 "<link> " . $my_url . "/$project/log</link>\n".
472 "<description>$project log</description>\n".
473 "<language>en</language>\n";
476 for (my $i = 0; $i <= $#revlist; $i++) {
477 my $commit = $revlist[$i];
478 my %co = git_commit
($commit);
479 my %ad = date_str
($co{'author_epoch'});
480 if ($action eq "log") {
481 if ($time_back > 0 && $co{'age'} > $time_back*60*60*24) {
483 print "<div class=\"page_body\"> Last change " . $co{'age_string'} . ".<br/><br/></div>\n";
488 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
489 "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML
($co{'title'})) . "\n" .
491 print "<div class=\"title_text\">\n" .
492 "<div class=\"log_link\">\n" .
493 "view " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit"}, "commit") . " | " .
494 $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$commit"}, "diff") . "<br/>\n" .
496 "<i>" . escapeHTML
($co{'author_name'}) . " [" . $ad{'rfc2822'} . "]</i><br/>\n" .
498 "<div class=\"log_body\">\n";
499 my $comment = $co{'comment'};
500 foreach my $line (@
$comment) {
501 last if ($line =~ m/^(signed-off|acked)-by:/i);
502 print escapeHTML
($line) . "<br/>\n";
506 } elsif ($action eq "rss") {
509 "\t<title>" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'min'}) . " - " . escapeHTML
($co{'title'}) . "</title>\n" .
510 "\t<link> " . $my_url . "?p=$project;a=commit;h=$commit</link>\n" .
512 my $comment = $co{'comment'};
513 foreach my $line (@
$comment) {
514 print escapeHTML
($line) . "\n";
516 print "\t</description>\n" .
520 if ($action eq "log") {
522 } elsif ($action eq "rss") {
523 print "</channel></rss>";
525 } elsif ($action eq "commit") {
526 my %co = git_commit
($hash);
528 die_error
("", "Unknown commit object.");
530 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
531 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
534 if (defined($co{'parent'})) {
535 open my $fd, "-|", "$gitbin/diff-tree -r " . $co{'parent'} . " $hash";
536 @difftree = map { chomp; $_ } <$fd>;
539 # fake git-diff-tree output for initial revision
540 open my $fd, "-|", "$gitbin/ls-tree -r $hash";
541 @difftree = map { chomp; "+" . $_ } <$fd>;
545 print "<div class=\"page_nav\"> view\n" .
546 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
547 $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . " | \n" .
548 $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$hash"}, "tree") . "\n" .
549 "<br/><br/></div>\n";
551 $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "title"}, escapeHTML
($co{'title'})) . "\n" .
553 print "<div class=\"title_text\">\n" .
554 "<table cellspacing=\"0\">";
555 print "<tr><td class=\"key\">author</td><td>" . escapeHTML
($co{'author'}) . "</td><tr><td></td><td>" .
556 " " . $ad{'rfc2822'};
557 if ($ad{'hour_local'} < 6) {
558 print "<span style=\"color: #cc0000;\">";
560 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
561 if ($ad{'hour_local'} < 6 ) {
566 print "<tr><td class=\"key\">committer</td><td>" . escapeHTML
($co{'committer'}) . "</td><tr><td></td><td>" .
567 " " . $cd{'rfc2822'} . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</i>\n" .
569 print "<tr><td class=\"key\">commit</td><td style=\"font-family: monospace;\">$hash</td></tr>\n";
570 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";
571 my $parents = $co{'parents'};
572 foreach my $par (@
$parents) {
573 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";
575 print "</table></div>\n";
576 print "<div class=\"page_body\">\n";
577 my $comment = $co{'comment'};
578 foreach my $line (@
$comment) {
579 if ($line =~ m/(signed-off|acked)-by:/i) {
580 print "<span style=\"color: #888888\">" . escapeHTML
($line) . "</span><br/>\n";
582 print escapeHTML
($line) . "<br/>\n";
586 if ($#difftree > 10) {
587 print "<div class=\"list_head\">" . ($#difftree + 1) . " files changed:<br/></div>\n";
589 foreach my $line (@difftree) {
590 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
591 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
592 # '*100664->100644 blob b1a8e3dd5556b61dd771d32307c6ee5d7150fa43->b1a8e3dd5556b61dd771d32307c6ee5d7150fa43 show-files.c'
593 # '*100664->100644 blob d08e895238bac36d8220586fdc28c27e1a7a76d3->d08e895238bac36d8220586fdc28c27e1a7a76d3 update-cache.c'
594 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
601 if ($type eq "blob") {
603 print "<div class=\"list\">\n" .
604 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$id"},
605 escapeHTML
($file) . " <span style=\"color: #008000;\">[new]</span>") . "\n" .
607 print "<div class=\"link\">\n" .
609 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$id"}, "file") . "<br/>\n" .
611 } elsif ($op eq "-") {
612 print "<div class=\"list\">\n" .
613 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$id"},
614 escapeHTML
($file) . " <span style=\"color: #c00000;\">[removed]</span>") . "\n" .
616 print "<div class=\"link\">\n" .
618 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$id"}, "file") . " | " .
619 $cgi->a({-href
=> "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "<br/>\n" .
621 } elsif ($op eq "*") {
622 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
625 $mode =~ m/^([0-7]{6})->([0-7]{6})$/;
629 if ($from_mode != $to_mode) {
630 $mode_chnge = " <span style=\"color: #888888;\"> [chmod $mode]</span>\n";
632 print "<div class=\"list\">\n";
633 if ($to_id ne $from_id) {
634 print $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id"},
635 escapeHTML
($file) . $mode_chnge) . "\n" .
638 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to_id"},
639 escapeHTML
($file) . $mode_chnge) . "\n" .
642 print "<div class=\"link\">\n" .
644 if ($to_id ne $from_id) {
645 print $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id"}, "diff") . " | ";
647 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to_id"}, "file") . " | " .
648 $cgi->a({-href
=> "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "<br/>\n" .
654 } elsif ($action eq "blobdiff") {
656 print "<div class=\"page_nav\">\n";
657 print "<br/><br/></div>\n";
658 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
659 print "<div class=\"page_body\">\n" .
661 git_diff_html
($hash_parent, $hash, $hash_parent, $hash);
665 } elsif ($action eq "commitdiff") {
666 my %co = git_commit
($hash);
668 die_error
("", "Unknown commit object.");
670 open my $fd, "-|", "$gitbin/diff-tree -r " . $co{'parent'} . " $hash";
671 my (@difftree) = map { chomp; $_ } <$fd>;
675 print "<div class=\"page_nav\"> view\n" .
676 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
677 $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . " | \n" .
678 $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$hash"}, "tree") . "\n" .
679 "<br/><br/></div>\n";
681 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML
($co{'title'})) . "\n" .
683 print "<div class=\"page_body\">\n" .
685 foreach my $line (@difftree) {
686 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
687 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
693 if ($type eq "blob") {
695 git_diff_html
("", $file, "", $id);
696 } elsif ($op eq "-") {
697 git_diff_html
($file, "", $id, "");
698 } elsif ($op eq "*") {
699 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
701 git_diff_html
($file, $file, $1, $2);
706 print "<br/></pre>\n";
709 } elsif ($action eq "history") {
710 if (!(defined($hash))) {
711 $hash = git_head
($project);
713 open my $fd, "-|", "$gitbin/rev-list $hash";
714 my (@revlist) = map { chomp; $_ } <$fd>;
718 print "<div class=\"page_nav\">\n";
719 print "<br/><br/></div>\n";
721 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML
($file_name)) . "\n" .
723 foreach my $rev (@revlist) {
724 my %co = git_commit
($rev);
725 my $parents = $co{'parents'};
727 foreach my $parent (@
$parents) {
728 open $fd, "-|", "$gitbin/diff-tree -r $parent $rev $file_name";
729 my (@difftree) = map { chomp; $_ } <$fd>;
732 foreach my $line (@difftree) {
733 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
735 if ($file eq $file_name) {
742 print "<div class=\"list\">\n" .
743 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$rev"},
744 "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML
($co{'title'})) . "\n" .
746 print "<div class=\"link\">\n" .
748 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$rev"}, "commit") . " | " .
749 $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$rev"}, "tree") . "<br/><br/>\n" .
756 die_error
("", "Unknown action.");