]>
Lady’s Gitweb - Gitweb/blob - gitweb.pl
9cf2dc74c5f0f67226da87801c10baddce3255da3d44ac9005358d7bc3fd0d86
3 # gitweb.pl - simple web interface to track changes in git repositories
7 # (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
8 # (C) 2005, Christian Gierke <ch@gierke.de>
10 # This file is licensed under the GPL v2, or a later version
14 use CGI
qw(:standard :escapeHTML);
15 use CGI
::Carp
qw(fatalsToBrowser);
19 my $projectroot = "/";
20 my $defaultprojects = "home/kay/public_html";
21 my $gitbin = "/home/kay/bin/git";
23 my $my_url = $cgi->url();
24 my $my_uri = $cgi->url(-absolute
=> 1);
26 my $project = $cgi->param('p');
27 my $action = $cgi->param('a');
28 my $hash = $cgi->param('h');
29 my $hash_parent = $cgi->param('hp');
30 my $time_back = $cgi->param('t');
31 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/.git/objects";
34 $action =~ s/[^0-9a-zA-Z\.\-]//g;
35 $project =~ s/\/\.//g
;
37 $hash =~ s/[^0-9a-fA-F]//g;
38 $hash_parent =~ s/[^0-9a-fA-F]//g;
39 $time_back =~ s/[^0-9]+//g;
42 print $cgi->header(-type
=> 'text/html', -charset
=> 'utf-8');
44 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
47 <title>git - $project $action</title>
48 <link rel="alternate" title="$project log" href="$my_uri/$project/rss" type="application/rss+xml"/>
49 <style type="text/css">
50 body { font-family: sans-serif; font-size: 12px; margin:25px; }
51 div.body { border-width:1px; border-style:solid; border-color:#D9D8D1; }
52 div.head1 { font-size:20px; padding:8px; background-color: #D9D8D1; font-weight:bold; }
53 div.head1 a:visited { color:#0000cc; }
54 div.head1 a:hover { color:#880000; }
55 div.head1 a:active { color:#880000; }
56 div.head2 { padding:8px; }
57 div.head2 a:visited { color:#0000cc; }
58 div.head2 a:hover { color:#880000; }
59 div.head2 a:active { color:#880000; }
60 div.title { padding:8px; background-color: #D9D8D1; font-weight:bold; }
61 div.title a { color:#000000; text-decoration:none; }
62 div.title a:hover { color:#880000; text-decoration:underline; }
63 div.title a:visited { color:#000000; }
64 table { padding:0px; margin:0px; width:100%; }
65 tr { vertical-align:top; }
66 td { padding:8px; margin:0px; font-family: sans-serif; font-size: 12px; }
67 td.head1 { background-color: #D9D8D1; font-weight:bold; }
68 td.head1 a { color:#000000; text-decoration:none; }
69 td.head1 a:hover { color:#880000; text-decoration:underline; }
70 td.head1 a:visited { color:#000000; }
71 td.head2 { background-color: #EDECE6; font-family: monospace; font-size:12px; }
72 td.head3 { background-color: #EDECE6; font-size:10px; }
73 div.signed_off { color: #a9a8a1; }
75 a:hover { color:#880000; }
76 a:visited { color:#880000; }
77 a:active { color:#880000; }
83 print "<div class=\"body\">\n";
84 print "<div class=\"head1\">";
85 print "<a href=\"http://kernel.org/pub/software/scm/git/\">" .
86 "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
87 if ($defaultprojects ne "") {
88 print $cgi->a({-href
=> "$my_uri"}, "projects") . " / ";
91 print $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, $project);
101 print "</body>\n</html>";
105 open my $fd, "$projectroot/$project/.git/HEAD";
117 open my $fd, "-|", "$gitbin/cat-file", "commit", $commit;
118 while (my $line = <$fd>) {
121 if ($line =~ m/^tree (.*)$/) {
123 } elsif ($line =~ m/^parent (.*)$/) {
125 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
126 $co{'committer'} = $1;
127 $co{'committer_time'} = $2;
128 $co{'committer_timezone'} = $3;
129 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
131 $co{'author_time'} = $2;
132 $co{'author_timezone'} = $3;
135 $co{'parents'} = \
@parents;
136 $co{'parent'} = $parents[0];
137 my (@comment) = map { chomp; $_ } <$fd>;
138 $co{'comment'} = \
@comment;
139 $co{'title'} = $comment[0];
145 my $from_name = shift || "/dev/null";
146 my $to_name = shift || "/dev/null";
150 my $from_tmp = "/dev/null";
151 my $to_tmp = "/dev/null";
152 my $from_label = "/dev/null";
153 my $to_label = "/dev/null";
156 # create temp from-file
158 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
159 open my $fd2, "> $from_tmp";
160 open my $fd, "-|", "$gitbin/cat-file", "blob", $from;
165 $from_label = "a/$from_name";
170 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
171 open my $fd2, "> $to_tmp";
172 open my $fd, "-|", "$gitbin/cat-file", "blob", $to;
177 $to_label = "b/$to_name";
180 open my $fd, "-|", "/usr/bin/diff", "-L", $from_label, "-L", $to_label, "-u", "-p", $from_tmp, $to_tmp;
181 print "<span style =\"color: #000099;\">===== ";
183 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$from"}, $from);
189 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to"}, $to);
193 print " =====</span>\n";
194 while (my $line = <$fd>) {
195 my $char = substr($line,0,1);
196 print '<span style ="color: #008800;">' if $char eq '+';
197 print '<span style ="color: #CC0000;">' if $char eq '-';
198 print '<span style ="color: #990099;">' if $char eq '@';
199 print escapeHTML
($line);
200 print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
213 my $perms = oct shift;
215 if ($perms & 040000) { $modestr .= 'd' } else { $modestr .= '-' };
216 for (my $i = 0; $i < 3; $i++) {
217 if ($perms & 0400) { $modestr .= 'r' } else { $modestr .= '-' };
218 if ($perms & 0200) { $modestr .= 'w' } else { $modestr .= '-' };
219 if ($perms & 0100) { $modestr .= 'x' } else { $modestr .= '-' };
225 if ($action eq "git-logo.png") {
226 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
227 print "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
228 "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
229 "\055\000\000\000\030\120\114\124\105\377\377\377\140\140\135\260".
230 "\257\252\000\200\000\316\315\307\300\000\000\350\350\346\367\367".
231 "\366\225\014\247\107\000\000\000\163\111\104\101\124\050\317\143".
232 "\110\147\040\004\112\134\030\012\010\052\142\123\141\040\002\010".
233 "\015\151\105\254\241\241\001\060\014\223\140\066\046\122\221\261".
234 "\001\021\326\341\125\144\154\154\314\154\154\014\242\014\160\052".
235 "\142\006\052\301\142\035\263\001\002\123\244\010\350\000\003\030".
236 "\046\126\021\324\341\040\227\033\340\264\016\065\044\161\051\202".
237 "\231\060\270\223\012\021\271\105\210\301\215\240\242\104\041\006".
238 "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305".
239 "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202";
243 # show list of default projects
244 if ($project eq "") {
245 opendir(my $fd, "$projectroot/$defaultprojects");
246 my (@path) = grep(!/^\./, readdir($fd));
249 print "<div class=\"head2\">\n";
250 print "<br/><br/>\n";
251 foreach my $line (@path) {
252 if (-e
"$projectroot/$defaultprojects/$line/.git/HEAD") {
253 print $cgi->a({-href
=> "$my_uri?p=$defaultprojects/$line;a=log"}, "$defaultprojects/$line") . "<br/>\n";
261 if ($action eq "blob") {
263 print "<br/><br/>\n";
265 open my $fd, "-|", "$gitbin/cat-file", "blob", $hash;
267 while (my $line = <$fd>) {
269 printf "<span style =\"color: #999999;\">%3i\t</span>%s", $nr, escapeHTML
($line);;
275 } elsif ($action eq "tree") {
279 open my $fd, "-|", "$gitbin/ls-tree", $hash;
280 my (@entries) = map { chomp; $_ } <$fd>;
283 print "<br/><br/>\n";
285 foreach my $line (@entries) {
286 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
287 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
292 if ($t_type eq "blob") {
293 print mode_str
($t_mode). " " . $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$t_hash"}, $t_name) . "\n";
294 } elsif ($t_type eq "tree") {
295 print mode_str
($t_mode). " " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$t_hash"}, $t_name) . "\n";
301 } elsif ($action eq "log" || $action eq "rss") {
302 open my $fd, "-|", "$gitbin/rev-list", git_head
();
303 my (@revtree) = map { chomp; $_ } <$fd>;
306 if ($action eq "log") {
308 print "<div class=\"head2\">\n";
310 print $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, "last day") . " | ";
311 print $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=7"}, "week") . " | ";
312 print $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=31"}, "month") . " | ";
313 print $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=365"}, "year") . " | ";
314 print $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=0"}, "all") . "<br/>\n";
315 print "<br/><br/>\n";
317 print "<table cellspacing=\"0\" class=\"log\">\n";
318 } elsif ($action eq "rss") {
319 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
320 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
321 "<rss version=\"0.91\">\n";
323 print "<title>$project</title>\n".
324 "<link> " . $my_url . "/$project/log</link>\n".
325 "<description>$project log</description>\n".
326 "<language>en</language>\n";
329 for (my $i = 0; $i <= $#revtree; $i++) {
330 my $commit = $revtree[$i];
331 my %co = git_commit
($commit);
332 my $age = time - $co{'committer_time'};
334 if ($age > 60*60*24*365*2) {
335 $age_string = int $age/60/60/24/365;
336 $age_string .= " years ago";
337 } elsif ($age > 60*60*24*365/12*2) {
338 $age_string = int $age/60/60/24/365/12;
339 $age_string .= " months ago";
340 } elsif ($age > 60*60*24*7*2) {
341 $age_string = int $age/60/60/24/7;
342 $age_string .= " weeks ago";
343 } elsif ($age > 60*60*24*2) {
344 $age_string = int $age/60/60/24;
345 $age_string .= " days ago";
346 } elsif ($age > 60*60*2) {
347 $age_string = int $age/60/60;
348 $age_string .= " hours ago";
349 } elsif ($age > 60*2) {
350 $age_string = int $age/60;
351 $age_string .= " minutes ago";
353 if ($action eq "log") {
354 if ($time_back > 0 && $age > $time_back*60*60*24) {
357 print "<td class=\"head1\"> Last change $age_string. </td>\n";
363 print "<td class=\"head1\">" . $age_string . "</td>\n";
364 print "<td class=\"head1\">" . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit"}, $co{'title'}) . "</td>";
367 print "<td class=\"head3\">";
368 print $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit"}, "view commit") . "<br/>\n";
369 print $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$commit"}, "view diff") . "<br/>\n";
371 print "<td class=\"head2\">\n";
372 print "author " . escapeHTML
($co{'author'}) . " [" . gmtime($co{'author_time'}) . " " . $co{'author_timezone'} . "]<br/>\n";
373 print "committer " . escapeHTML
($co{'committer'}) . " [" . gmtime($co{'committer_time'}) . " " . $co{'committer_timezone'} . "]<br/>\n";
379 my $comment = $co{'comment'};
380 foreach my $line (@$comment) {
381 if ($line =~ m/^(signed-off|acked)-by:/i) {
382 print '<div class="signed_off">' . escapeHTML
($line) . "<br/></div>\n";
384 print escapeHTML
($line) . "<br/>\n";
387 print "<br/><br/>\n";
390 } elsif ($action eq "rss") {
392 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime($co{'author_time'});
393 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
394 print "<item>\n\t<title>";
395 printf("%s %02d, %02d:%02d - ", $months[$mon], $mday, $hour, $min);
396 print escapeHTML
($co{'title'}) . "</title>\n";
397 print "\t<link> " . $my_url . "/$project/commit/$commit</link>\n";
398 print "\t<description>";
399 my $comment = $co{'comment'};
400 foreach my $line (@$comment) {
401 print escapeHTML
($line) . "\n";
403 print "\t</description>\n";
407 if ($action eq "log") {
410 } elsif ($action eq "rss") {
411 print "</channel></rss>";
413 } elsif ($action eq "commit") {
414 my %co = git_commit
($hash);
415 open my $fd, "-|", "$gitbin/diff-tree", "-r", $co{'parent'}, $hash;
416 my (@difftree) = map { chomp; $_ } <$fd>;
420 print "<div class=\"head2\"> view\n";
421 print $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | ";
422 print $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diff");
423 print "</div><br/><br/>\n";
424 print "<div class=\"title\">" . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, $co{'title'}) . "<br/></div>\n";
425 print "<table cellspacing=\"0\" class=\"log\">\n";
427 print "<td class=\"head2\">";
428 print "author " . escapeHTML
($co{'author'}) . " [" . gmtime($co{'author_time'}) . " " . $co{'author_timezone'} . "]<br/>\n";
429 print "committer " . escapeHTML
($co{'committer'}) . " [" . gmtime($co{'committer_time'}) . " " . $co{'committer_timezone'} . "]<br/>\n";
430 print "commit $hash<br/>\n";
431 print "tree " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'}"}, $co{'tree'}) . "<br/>\n";
432 my $parents = $co{'parents'};
433 foreach my $par (@$parents) {
434 print "parent " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$par"}, $par) . "<br/>\n";
440 my $comment = $co{'comment'};
441 foreach my $line (@$comment) {
442 if ($line =~ m/(signed-off|acked)-by:/i) {
443 print '<div class="signed_off">' . escapeHTML
($line) . "<br/></div>\n";
445 print escapeHTML
($line) . "<br/>\n";
448 print "<br/><br/>\n";
454 foreach my $line (@difftree) {
455 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
456 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
457 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
463 $mode =~ m/^([0-7]{6})/;
464 my $modestr = mode_str
($1);
465 if ($type eq "blob") {
467 print "added\t$modestr " . $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$id"}, $file) . "\n";
468 } elsif ($op eq "-") {
469 print "removed\t$modestr " . $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$id"}, $file) . "\n";
470 } elsif ($op eq "*") {
471 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
474 print "changed\t$modestr " . $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$old;hp=$new"}, $file) . "\n";
481 } elsif ($action eq "blobdiff") {
483 print "<br/><br/>\n";
485 git_diff_html
($hash, $hash_parent, $hash, $hash_parent);
489 } elsif ($action eq "commitdiff") {
490 my %co = git_commit
($hash);
491 open my $fd, "-|", "$gitbin/diff-tree", "-r", $co{'parent'}, $hash;
492 my (@difftree) = map { chomp; $_ } <$fd>;
496 print "<div class=\"head2\"> view\n";
497 print $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | ";
498 print $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diff");
499 print "</div><br/><br/>\n";
500 print "<div class=\"title\">" . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, $co{'title'}) . "<br/></div>\n";
502 foreach my $line (@difftree) {
503 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
504 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
510 if ($type eq "blob") {
512 git_diff_html
("", $file, "", $id);
513 } elsif ($op eq "-") {
514 git_diff_html
($file, "", $id, "");
515 } elsif ($op eq "*") {
516 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
517 git_diff_html
($file, $file, $1, $2);
526 print "<div class=\"head2\">\n";
527 print "unknown action";
528 print "</div><br/><br/>\n";
This page took 0.805136 seconds and 3 git commands to generate.