]>
Lady’s Gitweb - Gitweb/blob - gitweb.pl
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') || 1;
31 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/.git/objects";
34 $action =~ s/[^0-9a-zA-Z\.\-]//g;
35 $project =~ s/\/\.//g
;
36 $project =~ s/^\/+//g
;
37 $project =~ s/\/+$//g
;
39 $hash =~ s/[^0-9a-fA-F]//g;
40 $hash_parent =~ s/[^0-9a-fA-F]//g;
41 $time_back =~ s/[^0-9]+//g;
44 print $cgi->header(-type
=> 'text/html', -charset
=> 'utf-8');
46 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
49 <title>git - $project $action</title>
50 <link rel="alternate" title="$project log" href="$my_uri?p=$project;a=rss" type="application/rss+xml"/>
51 <style type="text/css">
52 body { font-family: sans-serif; font-size: 12px; margin:25px; }
53 div.body { border-width:1px; border-style:solid; border-color:#D9D8D1; }
54 div.head1 { font-size:18px; padding:8px; background-color: #D9D8D1; font-weight:bold; }
55 div.head1 a:visited { color:#0000cc; }
56 div.head1 a:hover { color:#880000; }
57 div.head1 a:active { color:#880000; }
58 div.head2 { padding:8px; }
59 div.head2 a:visited { color:#0000cc; }
60 div.head2 a:hover { color:#880000; }
61 div.head2 a:active { color:#880000; }
62 div.title { padding:8px; background-color: #D9D8D1; font-weight:bold; }
63 div.title a { color:#000000; text-decoration:none; }
64 div.title a:hover { color:#880000; text-decoration:underline; }
65 div.title a:visited { color:#000000; }
66 table { padding:0px; margin:0px; width:100%; }
67 tr { vertical-align:top; }
68 td { padding:8px; margin:0px; font-family: sans-serif; font-size: 12px; }
69 td.head1 { background-color: #D9D8D1; font-weight:bold; }
70 td.head1 a { color:#000000; text-decoration:none; }
71 td.head1 a:hover { color:#880000; text-decoration:underline; }
72 td.head1 a:visited { color:#000000; }
73 td.head2 { background-color: #EDECE6; font-family: monospace; font-size:12px; }
74 td.head3 { background-color: #EDECE6; font-size:10px; }
75 div.signed_off { color: #a9a8a1; }
77 a:hover { color:#880000; }
78 a:visited { color:#880000; }
79 a:active { color:#880000; }
85 print "<div class=\"body\">\n";
86 print "<div class=\"head1\">";
87 print "<a href=\"http://kernel.org/pub/software/scm/git/\">" .
88 "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
89 if ($defaultprojects ne "") {
90 print $cgi->a({-href
=> "$my_uri"}, "projects") . " / ";
93 print $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, $project);
101 sub git_footer_html
{
103 print "</body>\n</html>";
108 open my $fd, "$projectroot/$path/.git/HEAD";
120 open my $fd, "-|", "$gitbin/cat-file", "commit", $commit;
121 while (my $line = <$fd>) {
124 if ($line =~ m/^tree (.*)$/) {
126 } elsif ($line =~ m/^parent (.*)$/) {
128 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
130 $co{'author_time_utc'} = $2;
131 $co{'author_timezone'} = $3;
132 $co{'author_timezone'} =~ m/((-|\+)[0-9][0-9])([0-9][0-9])/;
133 $co{'author_time_local'} = $co{'author_time_utc'} + (($1 + ($2/60)) * 3600);
134 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
135 $co{'committer'} = $1;
136 $co{'committer_time_utc'} = $2;
137 $co{'committer_timezone'} = $3;
138 $co{'committer_timezone'} =~ m/((-|\+)[0-9][0-9])([0-9][0-9])/;
139 $co{'committer_time_local'} = $co{'committer_time_utc'} + (($1 + ($2/60)) * 3600);
142 $co{'parents'} = \
@parents;
143 $co{'parent'} = $parents[0];
144 my (@comment) = map { chomp; $_ } <$fd>;
145 $co{'comment'} = \
@comment;
146 $co{'title'} = $comment[0];
152 my $from_name = shift || "/dev/null";
153 my $to_name = shift || "/dev/null";
157 my $from_tmp = "/dev/null";
158 my $to_tmp = "/dev/null";
159 my $from_label = "/dev/null";
160 my $to_label = "/dev/null";
163 # create temp from-file
165 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
166 open my $fd2, "> $from_tmp";
167 open my $fd, "-|", "$gitbin/cat-file", "blob", $from;
172 $from_label = "a/$from_name";
177 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
178 open my $fd2, "> $to_tmp";
179 open my $fd, "-|", "$gitbin/cat-file", "blob", $to;
184 $to_label = "b/$to_name";
187 open my $fd, "-|", "/usr/bin/diff", "-L", $from_label, "-L", $to_label, "-u", "-p", $from_tmp, $to_tmp;
188 print "<span style=\"color: #000099;\">===== ";
190 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$from"}, $from);
196 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to"}, $to);
200 print " =====</span>\n";
201 while (my $line = <$fd>) {
202 my $char = substr($line,0,1);
203 print '<span style="color: #008800;">' if $char eq '+';
204 print '<span style="color: #CC0000;">' if $char eq '-';
205 print '<span style="color: #990099;">' if $char eq '@';
206 print escapeHTML
($line);
207 print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
219 # git cares only about the executable bit
221 my $perms = oct shift;
223 if ($perms & 040000) {
224 $modestr .= 'drwxrwxr-x';
227 $modestr .= '-rwxrwxr-x';
229 $modestr .= '-rw-rw-r--';
236 my $date_utc = shift;
237 my $format = shift || "date-time";
239 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
240 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
241 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($date_utc);
242 if ($format eq "date-time") {
243 return sprintf "%s, %d %s %4d %02d:%02d:%02d", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
244 } elsif ($format eq "day-time") {
245 return sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
249 if ($action eq "git-logo.png") {
250 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
251 print "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
252 "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
253 "\055\000\000\000\030\120\114\124\105\377\377\377\140\140\135\260".
254 "\257\252\000\200\000\316\315\307\300\000\000\350\350\346\367\367".
255 "\366\225\014\247\107\000\000\000\163\111\104\101\124\050\317\143".
256 "\110\147\040\004\112\134\030\012\010\052\142\123\141\040\002\010".
257 "\015\151\105\254\241\241\001\060\014\223\140\066\046\122\221\261".
258 "\001\021\326\341\125\144\154\154\314\154\154\014\242\014\160\052".
259 "\142\006\052\301\142\035\263\001\002\123\244\010\350\000\003\030".
260 "\046\126\021\324\341\040\227\033\340\264\016\065\044\161\051\202".
261 "\231\060\270\223\012\021\271\105\210\301\215\240\242\104\041\006".
262 "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305".
263 "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202";
267 # show list of default projects
268 if ($project eq "") {
269 opendir(my $fd, "$projectroot/$defaultprojects");
270 my (@path) = sort grep(!/^\./, readdir($fd));
273 print "<div class=\"head2\">\n";
274 print "<br/><br/>\n";
275 foreach my $line (@path) {
276 if (-e
"$projectroot/$defaultprojects/$line/.git/HEAD") {
277 print $cgi->a({-href
=> "$my_uri?p=$defaultprojects/$line;a=log"}, "$defaultprojects/$line") . "<br/>\n";
285 if ($action eq "blob") {
287 print "<br/><br/>\n";
289 open my $fd, "-|", "$gitbin/cat-file", "blob", $hash;
291 while (my $line = <$fd>) {
293 printf "<span style =\"color: #999999;\">%3i\t</span>%s", $nr, escapeHTML
($line);;
299 } elsif ($action eq "tree") {
301 $hash = git_head
($project);
303 open my $fd, "-|", "$gitbin/ls-tree", $hash;
304 my (@entries) = map { chomp; $_ } <$fd>;
307 print "<br/><br/>\n";
309 foreach my $line (@entries) {
310 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
311 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
316 if ($t_type eq "blob") {
317 print mode_str
($t_mode). " " . $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$t_hash"}, $t_name) . "\n";
318 } elsif ($t_type eq "tree") {
319 print mode_str
($t_mode). " " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$t_hash"}, $t_name) . "\n";
325 } elsif ($action eq "log" || $action eq "rss") {
326 open my $fd, "-|", "$gitbin/rev-list", git_head
($project);
327 my (@revtree) = map { chomp; $_ } <$fd>;
330 if ($action eq "log") {
332 print "<div class=\"head2\">\n";
334 print $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, "last day") . " | ";
335 print $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=7"}, "week") . " | ";
336 print $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=31"}, "month") . " | ";
337 print $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=365"}, "year") . " | ";
338 print $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=0"}, "all") . "<br/>\n";
339 print "<br/><br/>\n";
341 print "<table cellspacing=\"0\" class=\"log\">\n";
342 } elsif ($action eq "rss") {
343 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
344 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
345 "<rss version=\"0.91\">\n";
347 print "<title>$project</title>\n".
348 "<link> " . $my_url . "/$project/log</link>\n".
349 "<description>$project log</description>\n".
350 "<language>en</language>\n";
353 for (my $i = 0; $i <= $#revtree; $i++) {
354 my $commit = $revtree[$i];
355 my %co = git_commit
($commit);
356 my $age = time - $co{'committer_time_utc'};
358 if ($age > 60*60*24*365*2) {
359 $age_string = int $age/60/60/24/365;
360 $age_string .= " years ago";
361 } elsif ($age > 60*60*24*365/12*2) {
362 $age_string = int $age/60/60/24/365/12;
363 $age_string .= " months ago";
364 } elsif ($age > 60*60*24*7*2) {
365 $age_string = int $age/60/60/24/7;
366 $age_string .= " weeks ago";
367 } elsif ($age > 60*60*24*2) {
368 $age_string = int $age/60/60/24;
369 $age_string .= " days ago";
370 } elsif ($age > 60*60*2) {
371 $age_string = int $age/60/60;
372 $age_string .= " hours ago";
373 } elsif ($age > 60*2) {
374 $age_string = int $age/60;
375 $age_string .= " minutes ago";
377 if ($action eq "log") {
378 if ($time_back > 0 && $age > $time_back*60*60*24) {
381 print "<td class=\"head1\"> Last change $age_string. </td>\n";
387 print "<td class=\"head1\">" . $age_string . "</td>\n";
388 print "<td class=\"head1\">" . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit"}, $co{'title'}) . "</td>";
391 print "<td class=\"head3\">";
392 print $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit"}, "view commit") . "<br/>\n";
393 print $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$commit"}, "view diff") . "<br/>\n";
395 print "<td class=\"head2\">\n";
396 print "author " . escapeHTML
($co{'author'}) . " [" . date_str
($co{'author_time_utc'}) . "]<br/>\n";
397 print "committer " . escapeHTML
($co{'committer'}) . " [" . date_str
($co{'committer_time_utc'}) . "]<br/>\n";
403 my $comment = $co{'comment'};
404 foreach my $line (@$comment) {
405 if ($line =~ m/^(signed-off|acked)-by:/i) {
406 print '<div class="signed_off">' . escapeHTML
($line) . "<br/></div>\n";
408 print escapeHTML
($line) . "<br/>\n";
411 print "<br/><br/>\n";
414 } elsif ($action eq "rss") {
416 print "<item>\n\t<title>" . date_str
($co{'author_time_utc'}, "day-time") . " - " . escapeHTML
($co{'title'}) . "</title>\n";
417 print "\t<link> " . $my_url . "/$project/commit/$commit</link>\n";
418 print "\t<description>";
419 my $comment = $co{'comment'};
420 foreach my $line (@$comment) {
421 print escapeHTML
($line) . "\n";
423 print "\t</description>\n";
427 if ($action eq "log") {
430 } elsif ($action eq "rss") {
431 print "</channel></rss>";
433 } elsif ($action eq "commit") {
434 my %co = git_commit
($hash);
435 open my $fd, "-|", "$gitbin/diff-tree", "-r", $co{'parent'}, $hash;
436 my (@difftree) = map { chomp; $_ } <$fd>;
440 print "<div class=\"head2\"> view\n";
441 print $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | ";
442 print $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diff");
443 print "</div><br/><br/>\n";
444 print "<div class=\"title\">" . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, $co{'title'}) . "<br/></div>\n";
445 print "<table cellspacing=\"0\" class=\"log\">\n";
447 print "<td class=\"head2\">";
448 print "author " . escapeHTML
($co{'author'}) . " [" . date_str
($co{'author_time_utc'}) . "]<br/>\n";
450 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'author_time_local'});
451 if ($hour < 7 ) { print "<span style=\"color: #990000;\">"; }
452 print "localtime " . date_str
($co{'author_time_local'}) . " " . $co{'author_timezone'} . "<br/>\n";
453 if ($hour < 7 ) { print "</span>"; }
454 print "committer " . escapeHTML
($co{'committer'}) . " [" . date_str
($co{'committer_time_utc'}) . "]<br/>\n";
455 print "localtime " . date_str
($co{'committer_time_local'}) . " " . $co{'committer_timezone'} . "<br/>\n";
456 print "commit $hash<br/>\n";
457 print "tree " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'}"}, $co{'tree'}) . "<br/>\n";
458 my $parents = $co{'parents'};
459 foreach my $par (@$parents) {
460 print "parent " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$par"}, $par) . "<br/>\n";
466 my $comment = $co{'comment'};
467 foreach my $line (@$comment) {
468 if ($line =~ m/(signed-off|acked)-by:/i) {
469 print '<div class="signed_off">' . escapeHTML
($line) . "<br/></div>\n";
471 print escapeHTML
($line) . "<br/>\n";
474 print "<br/><br/>\n";
480 foreach my $line (@difftree) {
481 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
482 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
483 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
489 $mode =~ m/^([0-7]{6})/;
490 my $modestr = mode_str
($1);
491 if ($type eq "blob") {
493 print "$modestr " . $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$id"}, $file) . " (new)\n";
494 } elsif ($op eq "-") {
495 print "$modestr " . $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;hp=$id"}, $file) . " (removed)\n";
496 } elsif ($op eq "*") {
497 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
500 print "$modestr " . $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$to;hp=$from"}, $file) . "\n";
507 } elsif ($action eq "blobdiff") {
509 print "<br/><br/>\n";
511 git_diff_html
($hash_parent, $hash, $hash_parent, $hash);
515 } elsif ($action eq "commitdiff") {
516 my %co = git_commit
($hash);
517 open my $fd, "-|", "$gitbin/diff-tree", "-r", $co{'parent'}, $hash;
518 my (@difftree) = map { chomp; $_ } <$fd>;
522 print "<div class=\"head2\"> view\n";
523 print $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | ";
524 print $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diff");
525 print "</div><br/><br/>\n";
526 print "<div class=\"title\">" . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, $co{'title'}) . "<br/></div>\n";
528 foreach my $line (@difftree) {
529 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
530 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
536 if ($type eq "blob") {
538 git_diff_html
("", $file, "", $id);
539 } elsif ($op eq "-") {
540 git_diff_html
($file, "", $id, "");
541 } elsif ($op eq "*") {
542 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
543 git_diff_html
($file, $file, $1, $2);
552 print "<div class=\"head2\">\n";
553 print "unknown action";
554 print "</div><br/><br/>\n";
This page took 1.264616 seconds and 5 git commands to generate.