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 $projectroot = "/home/kay/public_html/pub/scm";
28 my $home_link = "/~kay/git";
29 my $logo_link = "/~kay/pub/software/scm/cogito";
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";
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.");
67 my $status = shift || "200 OK";
69 print $cgi->header(-type
=>'text/html', -charset
=> 'utf-8', -status
=> $status);
71 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
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; }
79 a:hover { color:#880000; }
80 a:visited { color:#880000; }
81 a:active { color:#880000; }
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; }
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; }
97 display:block; margin:0px 25px; padding:8px;
98 font-weight:bold; background-color:#d9d8d1; color:#000000;
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; }
106 margin:0px 25px; padding:8px;
107 border: solid #d9d8d1; border-width:0px 1px; font-family:monospace;
108 background-color: #edece6;
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; }
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;
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; }
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));
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";
160 my $status = shift || "403 Forbidden";
161 my $error = shift || "Malformed query, file missing or permission denied";
165 git_header_html
($status);
166 print "<div class=\"page_body\">\n" .
169 print "<br/></div>\n";
176 open(my $fd, "$projectroot/$path/HEAD") || die_error
("", "Invalid project directory.");;
188 open my $fd, "-|", "$gitbin/git-cat-file commit $commit";
189 while (my $line = <$fd>) {
192 if ($line =~ m/^tree (.*)$/) {
194 } elsif ($line =~ m/^parent (.*)$/) {
196 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
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'})) {
213 $co{'parents'} = \
@parents;
214 $co{'parent'} = $parents[0];
215 my (@comment) = map { chomp; $_ } <$fd>;
216 $co{'comment'} = \
@comment;
217 $co{'title'} = $comment[0];
220 my $age = time - $co{'committer_epoch'};
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";
245 my $from_name = shift || "/dev/null";
246 my $to_name = shift || "/dev/null";
250 my $from_tmp = "/dev/null";
251 my $to_tmp = "/dev/null";
252 my $from_label = "/dev/null";
253 my $to_label = "/dev/null";
256 # create tmp from-file
258 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
259 open(my $fd2, "> $from_tmp");
260 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
265 $from_label = "a/$from_name";
270 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
271 open my $fd2, "> $to_tmp";
272 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
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;\">===== ";
283 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$from"}, $from);
289 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to"}, $to);
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 '@';
313 my $perms = oct shift;
315 if ($perms & 040000) {
316 $modestr .= 'drwxr-xr-x';
318 # git cares only about the executable bit
320 $modestr .= '-rwxr-xr-x';
322 $modestr .= '-rw-r--r--';
330 my $tz = shift || "-0000";
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;
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";
371 if (!defined($project)) {
372 print $cgi->redirect($home_link);
376 if (!defined($action)) {
380 if (!defined($time_back)) {
384 if ($action eq "blob") {
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");
392 while (my $line = <$fd>) {
394 printf "<span style =\"color: #999999;\">%4i\t</span>%s", $nr, escapeHTML
($line);;
397 print "<br/></pre>\n";
400 } elsif ($action eq "tree") {
402 $hash = git_head
($project);
404 open my $fd, "-|", "$gitbin/git-ls-tree $hash";
405 my (@entries) = map { chomp; $_ } <$fd>;
409 my %co = git_commit
($hash);
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";
417 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash", -class => "log_title"}, escapeHTML
($co{'title'})) . "\n" .
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(.*)$/;
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";
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>;
447 if ($action eq "log") {
449 print "<div class=\"page_nav\">\n";
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" .
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";
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) {
476 print "<div class=\"page_body\"> Last change " . $co{'age_string'} . ".<br/><br/></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" .
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" .
489 escapeHTML
($co{'author_name'}) . " [" . $ad{'rfc2822'} . "]<br/>\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";
499 } elsif ($action eq "rss") {
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" .
505 my $comment = $co{'comment'};
506 foreach my $line (@
$comment) {
507 print escapeHTML
($line) . "\n";
509 print "\t</description>\n" .
513 if ($action eq "log") {
515 } elsif ($action eq "rss") {
516 print "</channel></rss>";
518 } elsif ($action eq "commit") {
519 my %co = git_commit
($hash);
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>;
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";
536 $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "log_title"}, escapeHTML
($co{'title'})) . "\n" .
538 print "<div class=\"log_head\">\n";
539 print "author " . 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>"; }
545 print "committer " . 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'});
549 print "commit   $hash<br/>\n";
550 print "tree  " . $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    " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$par"}, $par) . "<br/>\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";
562 print escapeHTML
($line) . "<br/>\n";
565 print "<br/><br/>\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(.*)$/;
579 if ($type eq "blob") {
582 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$id", -class => "list"},
583 escapeHTML
($file) . " <span style=\"color: #008000;\">[new]</span>") . "\n" .
585 print "<div class=\"link\">\n" .
587 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$id"}, "file") . "<br/><br/>\n" .
589 } elsif ($op eq "-") {
591 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$id", -class => "list"},
592 escapeHTML
($file) . " <span style=\"color: #c00000;\">[removed]</span>") . "\n" .
594 print "<div class=\"link\">\n" .
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" .
599 } elsif ($op eq "*") {
600 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
603 $mode =~ m/^([0-7]{6})->([0-7]{6})$/;
607 if ($from_mode != $to_mode) {
608 $mode_chnge = " <span style=\"color: #555555;\"> [chmod $mode]</span>\n";
611 $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$to_id", -class => "list"},
612 escapeHTML
($file) . $mode_chnge) . "\n" .
614 print "<div class=\"link\">\n" .
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" .
626 } elsif ($action eq "blobdiff") {
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" .
633 git_diff_html
($hash_parent, $hash, $hash_parent, $hash);
637 } elsif ($action eq "commitdiff") {
638 my %co = git_commit
($hash);
640 die_error
("", "Unknown commit object.");
642 open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash";
643 my (@difftree) = map { chomp; $_ } <$fd>;
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";
653 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash", -class => "log_title"}, escapeHTML
($co{'title'})) . "\n" .
655 print "<div class=\"page_body\">\n" .
657 foreach my $line (@difftree) {
658 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
659 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
665 if ($type eq "blob") {
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]+)/;
673 git_diff_html
($file, $file, $1, $2);
678 print "<br/></pre>\n";
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>;
690 print "<div class=\"page_nav\">\n";
691 print "<br/><br/></div>\n";
693 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash", -class => "log_title"}, escapeHTML
($file_name)) . "\n" .
695 print "<div class=\"page_body\">\n" .
698 foreach my $rev (@revlist) {
699 my %co = git_commit
($rev);
700 my $parents = $co{'parents'};
702 foreach my $parent (@
$parents) {
703 open $fd, "-|", "$gitbin/git-diff-tree -r $parent $rev $file_name";
704 my (@difftree) = map { chomp; $_ } <$fd>;
707 foreach my $line (@difftree) {
708 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
710 if ($file eq $file_name) {
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" .
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" .
730 die_error
("", "unknown action");