]>
Lady’s Gitweb - Gitweb/blob - gitweb.cgi
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 $defaultprojects = "linux/kernel/git";
20 my $gitbin = "/usr/bin";
21 my $gittmp = "/tmp/gitweb";
22 my $giturl = "/pub/software/scm/cogito";
23 my $my_url = $cgi->url();
24 my $my_uri = $cgi->url(-absolute
=> 1);
28 my $project = $cgi->param('p');
29 my $action = $cgi->param('a');
30 my $hash = $cgi->param('h');
31 my $hash_parent = $cgi->param('hp');
32 my $time_back = $cgi->param('t');
33 if (!(defined($time_back))) {
36 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
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;
43 if (defined($project) && $project =~ /(^|\/)(|\
.|\
.\
.)($|\
/)/) {
44 print $cgi->header(-type
=>'text/plain', -status
=>'403 Permission denied');
45 print "Malformed query, file missing or permission denied\n";
51 print $cgi->header(-type
=> 'text/html', -charset
=> 'utf-8');
53 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
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; }
61 a:hover { color:#880000; }
62 a:visited { color:#880000; }
63 a:active { color:#880000; }
65 margin:15px 25px 0px; height:25px; padding:8px;
66 font-size:18px; clear:both; font-weight:bold; background-color: #d9d8d1;
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; }
72 margin:0px 25px 15px; height:17px; padding:4px; padding-left:8px;
73 clear:both; background-color: #d9d8d1;
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; }
78 display:block; margin:0px 25px; padding:8px; clear:both;
79 font-weight:bold; background-color: #d9d8d1; text-decoration:none; color:#000000;
81 a.log_title:hover { background-color: #c9c8c1; }
82 a.xml_logo { float:right; border:1px solid;
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;
89 a.xml_logo:hover { background-color:#ee5500; }
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;
96 margin:0px 25px; padding:8px; padding-left:150px; clear:both;
97 border:solid #d9d8d1; border-width:0px 1px;
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; }
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") . " / ";
112 if ($project ne "") {
113 print $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, $project);
121 sub 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";
128 print "</body>\n</html>";
133 open my $fd, "$projectroot/$path/HEAD";
145 open my $fd, "-|", "$gitbin/cat-file commit $commit";
146 while (my $line = <$fd>) {
149 if ($line =~ m/^tree (.*)$/) {
151 } elsif ($line =~ m/^parent (.*)$/) {
153 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
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/ <.*//;
167 $co{'parents'} = \
@parents;
168 $co{'parent'} = $parents[0];
169 my (@comment) = map { chomp; $_ } <$fd>;
170 $co{'comment'} = \
@comment;
171 $co{'title'} = $comment[0];
177 my $from_name = shift || "/dev/null";
178 my $to_name = shift || "/dev/null";
182 my $from_tmp = "/dev/null";
183 my $to_tmp = "/dev/null";
184 my $from_label = "/dev/null";
185 my $to_label = "/dev/null";
188 # create tmp from-file
190 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
191 open my $fd2, "> $from_tmp";
192 open my $fd, "-|", "$gitbin/cat-file blob $from";
197 $from_label = "a/$from_name";
202 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
203 open my $fd2, "> $to_tmp";
204 open my $fd, "-|", "$gitbin/cat-file blob $to";
209 $to_label = "b/$to_name";
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;\">===== ";
215 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$from"}, $from);
221 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to"}, $to);
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 '@';
245 my $perms = oct shift;
247 if ($perms & 040000) {
248 $modestr .= 'drwxrwxr-x';
250 # git cares only about the executable bit
252 $modestr .= '-rwxrwxr-x';
254 $modestr .= '-rw-rw-r--';
262 my $tz = shift || "-0000";
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;
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;
285 if ($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";
303 # show list of default projects
304 if ($project eq "") {
305 opendir(my $fd, "$projectroot/$defaultprojects");
306 my (@users) = sort grep(!/^\./, readdir($fd));
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));
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";
330 if ($action eq "blob") {
332 print "<div class=\"page_body\"><pre><br/><br/>\n";
333 open my $fd, "-|", "$gitbin/cat-file blob $hash";
335 while (my $line = <$fd>) {
337 printf "<span style =\"color: #999999;\">%4i\t</span>%s", $nr, escapeHTML
($line);;
340 print "<br/><br/></pre>\n";
343 } elsif ($action eq "tree") {
345 $hash = git_head
($project);
347 open my $fd, "-|", "$gitbin/ls-tree $hash";
348 my (@entries) = map { chomp; $_ } <$fd>;
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(.*)$/;
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";
369 } elsif ($action eq "log" || $action eq "rss") {
370 open my $fd, "-|", "$gitbin/rev-list " . git_head
($project);
371 my (@revtree) = map { chomp; $_ } <$fd>;
374 if ($action eq "log") {
376 print "<div class=\"page_nav\">\n";
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" .
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";
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";
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'};
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";
421 if ($action eq "log") {
422 if ($time_back > 0 && $age > $time_back*60*60*24) {
424 print "<div class=\"page_body\"> Last change $age_string.<br/><br/></div>\n";
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" .
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" .
436 escapeHTML
($co{'author_name'}) . " [" . $ad{'rfc2822'} . "]<br/>\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";
444 print escapeHTML
($line) . "<br/>\n";
447 print "<br/><br/>\n" .
449 } elsif ($action eq "rss") {
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" .
455 my $comment = $co{'comment'};
456 foreach my $line (@$comment) {
457 print escapeHTML
($line) . "\n";
459 print "\t</description>\n" .
463 if ($action eq "log") {
465 } elsif ($action eq "rss") {
466 print "</channel></rss>";
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>;
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>"; }
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'});
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";
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";
506 print escapeHTML
($line) . "<br/>\n";
509 print "<br/><br/>\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(.*)$/;
520 $mode =~ m/^([0-7]{6})/;
521 my $modestr = mode_str
($1);
522 if ($type eq "blob") {
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]+)/;
531 print "$modestr " . $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$to;hp=$from"}, $file) . "\n";
538 } elsif ($action eq "blobdiff") {
540 print "<div class=\"page_body\"><br/><br/>\n" .
542 git_diff_html
($hash_parent, $hash, $hash_parent, $hash);
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>;
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" .
560 foreach my $line (@difftree) {
561 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
562 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
568 if ($type eq "blob") {
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);
579 print "<br/></pre>\n";
584 print "<div class=\"page_body\">\n" .
586 print "unknown action\n";
587 print "<br/></div>\n";
This page took 0.877496 seconds and 5 git commands to generate.