]>
Lady’s Gitweb - Gitweb/blob - gitweb.pl
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 = "/";
19 my $defaultprojects = "home/kay/public_html";
20 my $gitbin = "/home/kay/bin/git";
22 my $my_url = $cgi->url();
23 my $my_uri = $cgi->url(-absolute
=> 1);
25 my $project = $cgi->param('p');
26 my $action = $cgi->param('a');
27 my $hash = $cgi->param('h');
28 my $hash_parent = $cgi->param('hp');
29 my $time_back = $cgi->param('t');
30 if (!(defined($time_back))) {
33 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/.git/objects";
36 $action =~ s/[^0-9a-zA-Z\.\-]//g;
37 $project =~ s/\/\.//g
;
38 $project =~ s/^\/+//g
;
39 $project =~ s/\/+$//g
;
41 $hash =~ s/[^0-9a-fA-F]//g;
42 $hash_parent =~ s/[^0-9a-fA-F]//g;
43 $time_back =~ s/[^0-9]+//g;
46 print $cgi->header(-type
=> 'text/html', -charset
=> 'utf-8');
48 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
51 <title>git - $project $action</title>
52 <link rel="alternate" title="$project log" href="$my_uri?p=$project;a=rss" type="application/rss+xml"/>
53 <style type="text/css">
54 body { font-family: sans-serif; font-size: 12px; margin:0px; }
56 a:hover { color:#880000; }
57 a:visited { color:#880000; }
58 a:active { color:#880000; }
59 div.page_header { margin:15px 25px 0px; height:25px; padding:8px; font-size:18px; clear:both; font-weight:bold; background-color: #d9d8d1; }
60 div.page_header a:visited { color:#0000cc; }
61 div.page_nav { margin:0px 25px; padding:8px; clear:both; border: solid #d9d8d1; border-width:0px 1px; }
62 div.page_nav a:visited { color:#0000cc; }
63 div.page_footer { margin:0px 25px 15px; height:17px; padding:4px; padding-left:8px; clear:both; background-color: #d9d8d1; }
64 div.page_footer_text { float:left; color:#888888; font-size:10px;}
65 div.page_body { margin:0px 25px; padding:8px; clear:both; border: solid #d9d8d1; border-width:0px 1px; }
66 a.log_title { display:block; margin:0px 25px; padding:8px; clear:both; font-weight:bold; background-color: #d9d8d1; text-decoration:none; color:#000000; }
67 a.log_title:hover { background-color: #c9c8c1; }
68 a.xml_logo { float:right; border:1px solid;
69 border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e; width:35px; color:#ffffff; background-color:#ff6600;
70 font-weight:bold; font-family:sans-serif; text-align:center; font-size:11px; display:block; text-decoration:none;
72 a.xml_logo:hover { background-color:#ee5500; }
73 div.log_head { margin:0px 25px; min-height: 30px; padding:8px; clear:both;
74 border: solid #d9d8d1; border-width:0px 1px; font-family:monospace; background-color: #edece6;
76 div.log_body { margin:0px 25px; padding:8px; padding-left:150px; clear:both; border: solid #d9d8d1; border-width:0px 1px; }
77 span.log_age { position:relative; float:left; width:142px; }
78 div.log_functions { font-size:10px; font-family:sans-serif; position:relative; float:left; width:142px; }
79 div.signed_off { color: #a9a8a1; }
84 print "<div class=\"page_header\">\n" .
85 "<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);
100 print "<div class=\"page_footer\">";
101 print "<div class=\"page_footer_text\">version $version</div>";
102 if ($project ne '') {
103 print $cgi->a({-href
=> "$my_uri?p=$project;a=rss", -class => "xml_logo"}, "XML") . "\n";
106 print "</body>\n</html>";
111 open my $fd, "$projectroot/$path/.git/HEAD";
123 open my $fd, "-|", "$gitbin/cat-file commit $commit";
124 while (my $line = <$fd>) {
127 if ($line =~ m/^tree (.*)$/) {
129 } elsif ($line =~ m/^parent (.*)$/) {
131 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
133 $co{'author_time_epoch'} = $2;
134 $co{'author_timezone'} = $3;
135 $co{'author_name'} = $co{'author'};
136 $co{'author_name'} =~ s/ <.*//;
137 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
138 $co{'committer'} = $1;
139 $co{'committer_time_epoch'} = $2;
140 $co{'committer_timezone'} = $3;
141 $co{'committer_name'} = $co{'committer'};
142 $co{'committer_name'} =~ s/ <.*//;
145 $co{'parents'} = \
@parents;
146 $co{'parent'} = $parents[0];
147 my (@comment) = map { chomp; $_ } <$fd>;
148 $co{'comment'} = \
@comment;
149 $co{'title'} = $comment[0];
155 my $from_name = shift || "/dev/null";
156 my $to_name = shift || "/dev/null";
160 my $from_tmp = "/dev/null";
161 my $to_tmp = "/dev/null";
162 my $from_label = "/dev/null";
163 my $to_label = "/dev/null";
166 # create tmp from-file
168 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
169 open my $fd2, "> $from_tmp";
170 open my $fd, "-|", "$gitbin/cat-file blob $from";
175 $from_label = "a/$from_name";
180 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
181 open my $fd2, "> $to_tmp";
182 open my $fd, "-|", "$gitbin/cat-file blob $to";
187 $to_label = "b/$to_name";
190 open my $fd, "-|", "/usr/bin/diff -u -p -L $from_label -L $to_label $from_tmp $to_tmp";
191 print "<span style=\"color: #000099;\">===== ";
193 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$from"}, $from);
199 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to"}, $to);
203 print " =====</span>\n";
204 while (my $line = <$fd>) {
205 my $char = substr($line,0,1);
206 print '<span style="color: #008800;">' if $char eq '+';
207 print '<span style="color: #CC0000;">' if $char eq '-';
208 print '<span style="color: #990099;">' if $char eq '@';
209 print escapeHTML
($line);
210 print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
223 my $perms = oct shift;
225 if ($perms & 040000) {
226 $modestr .= 'drwxrwxr-x';
228 # git cares only about the executable bit
230 $modestr .= '-rwxrwxr-x';
232 $modestr .= '-rw-rw-r--';
240 my $tz = shift || "-0000";
243 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
244 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
245 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
246 $date{'hour'} = $hour;
247 $date{'minute'} = $min;
248 $date{'mday'} = $mday;
249 $date{'day'} = $days[$wday];
250 $date{'month'} = $months[$mon];
251 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
252 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
254 $tz =~ m/((-|\+)[0-9][0-9])([0-9][0-9])/;
255 my $local = $epoch + (($1 + ($2/60)) * 3600);
256 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
257 $date{'rfc2822_local'} = sprintf "%s, %d %s %4d %02d:%02d:%02d %s", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec, $tz;
261 if ($action eq "git-logo.png") {
262 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
263 print "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
264 "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
265 "\055\000\000\000\030\120\114\124\105\377\377\377\140\140\135\260".
266 "\257\252\000\200\000\316\315\307\300\000\000\350\350\346\367\367".
267 "\366\225\014\247\107\000\000\000\163\111\104\101\124\050\317\143".
268 "\110\147\040\004\112\134\030\012\010\052\142\123\141\040\002\010".
269 "\015\151\105\254\241\241\001\060\014\223\140\066\046\122\221\261".
270 "\001\021\326\341\125\144\154\154\314\154\154\014\242\014\160\052".
271 "\142\006\052\301\142\035\263\001\002\123\244\010\350\000\003\030".
272 "\046\126\021\324\341\040\227\033\340\264\016\065\044\161\051\202".
273 "\231\060\270\223\012\021\271\105\210\301\215\240\242\104\041\006".
274 "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305".
275 "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202";
279 # show list of default projects
280 if ($project eq "") {
281 opendir(my $fd, "$projectroot/$defaultprojects");
282 my (@path) = sort grep(!/^\./, readdir($fd));
285 print "<div class=\"page_body\">\n";
286 print "<br/><br/>\n";
287 foreach my $line (@path) {
288 if (-e
"$projectroot/$defaultprojects/$line/.git/HEAD") {
289 print $cgi->a({-href
=> "$my_uri?p=$defaultprojects/$line;a=log"}, "$defaultprojects/$line") . "<br/>\n";
301 if ($action eq "blob") {
303 print "<div class=\"page_body\"><pre><br/><br/>\n";
304 open my $fd, "-|", "$gitbin/cat-file blob $hash";
306 while (my $line = <$fd>) {
308 printf "<span style =\"color: #999999;\">%4i\t</span>%s", $nr, escapeHTML
($line);;
311 print "<br/><br/></pre>\n";
314 } elsif ($action eq "tree") {
316 $hash = git_head
($project);
318 open my $fd, "-|", "$gitbin/ls-tree $hash";
319 my (@entries) = map { chomp; $_ } <$fd>;
322 print "<div class=\"page_body\">\n";
323 print "<br/><pre>\n";
324 foreach my $line (@entries) {
325 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
326 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
331 if ($t_type eq "blob") {
332 print mode_str
($t_mode). " " . $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$t_hash"}, $t_name) . "\n";
333 } elsif ($t_type eq "tree") {
334 print mode_str
($t_mode). " " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$t_hash"}, $t_name) . "\n";
340 } elsif ($action eq "log" || $action eq "rss") {
341 open my $fd, "-|", "$gitbin/rev-list " . git_head
($project);
342 my (@revtree) = map { chomp; $_ } <$fd>;
345 if ($action eq "log") {
347 print "<div class=\"page_nav\">\n";
349 print $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, "last day") . " | \n" .
350 $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=7"}, "week") . " | \n" .
351 $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=31"}, "month") . " | \n" .
352 $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=365"}, "year") . " | \n" .
353 $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=0"}, "all") . "<br/>\n";
354 print "<br/><br/>\n" .
356 } elsif ($action eq "rss") {
357 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
358 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
359 "<rss version=\"0.91\">\n";
361 print "<title>$project</title>\n".
362 "<link> " . $my_url . "/$project/log</link>\n".
363 "<description>$project log</description>\n".
364 "<language>en</language>\n";
367 for (my $i = 0; $i <= $#revtree; $i++) {
368 my $commit = $revtree[$i];
369 my %co = git_commit
($commit);
370 my %ad = date_str
($co{'author_time_epoch'});
371 my $age = time - $co{'committer_time_epoch'};
373 if ($age > 60*60*24*365*2) {
374 $age_string = int $age/60/60/24/365;
375 $age_string .= " years ago";
376 } elsif ($age > 60*60*24*365/12*2) {
377 $age_string = int $age/60/60/24/365/12;
378 $age_string .= " months ago";
379 } elsif ($age > 60*60*24*7*2) {
380 $age_string = int $age/60/60/24/7;
381 $age_string .= " weeks ago";
382 } elsif ($age > 60*60*24*2) {
383 $age_string = int $age/60/60/24;
384 $age_string .= " days ago";
385 } elsif ($age > 60*60*2) {
386 $age_string = int $age/60/60;
387 $age_string .= " hours ago";
388 } elsif ($age > 60*2) {
389 $age_string = int $age/60;
390 $age_string .= " minutes ago";
392 if ($action eq "log") {
393 if ($time_back > 0 && $age > $time_back*60*60*24) {
395 print "<div class=\"page_body\"> Last change $age_string.<br/><br/></div>\n";
399 print "<div><a href=\"$my_uri?p=$project;a=commit;h=$commit\" class=\"log_title\">\n" .
400 "<span class=\"log_age\">" . $age_string . "</span>\n" . escapeHTML
($co{'title'}) . "</a>\n" .
402 print "<div class=\"log_head\">\n" .
403 "<div class=\"log_functions\">\n" .
404 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit"}, "view commit") . "<br/>\n" .
405 $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$commit"}, "view diff") . "<br/>\n" .
407 escapeHTML
($co{'author_name'}) . " [" . $ad{'rfc2822'} . "]<br/>\n" .
409 "<div class=\"log_body\">\n";
410 my $comment = $co{'comment'};
411 foreach my $line (@$comment) {
412 if ($line =~ m/^(signed-off|acked)-by:/i) {
413 print '<div class="signed_off">' . escapeHTML
($line) . "<br/></div>\n";
415 print escapeHTML
($line) . "<br/>\n";
418 print "<br/><br/>\n" .
420 } elsif ($action eq "rss") {
423 "\t<title>" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'min'}) . " - " . escapeHTML
($co{'title'}) . "</title>\n" .
424 "\t<link> " . $my_url . "?p=$project;a==commit;h=$commit</link>\n" .
426 my $comment = $co{'comment'};
427 foreach my $line (@$comment) {
428 print escapeHTML
($line) . "\n";
430 print "\t</description>\n" .
434 if ($action eq "log") {
436 } elsif ($action eq "rss") {
437 print "</channel></rss>";
439 } elsif ($action eq "commit") {
440 my %co = git_commit
($hash);
441 my %ad = date_str
($co{'author_time_epoch'}, $co{'author_time_zone'});
442 my %cd = date_str
($co{'committer_time_epoch'}, $co{'committer_time_zone'});
443 open my $fd, "-|", "$gitbin/diff-tree -r " . $co{'parent'} . " $hash";
444 my (@difftree) = map { chomp; $_ } <$fd>;
448 print "<div class=\"page_nav\"> view\n" .
449 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
450 $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diff") . "\n" .
451 "<br/><br/></div>\n";
452 print "<a class=\"log_title\" href=\"$my_uri?p=$project;a=commitdiff;h=$hash\">$co{'title'}</a>\n";
453 print "<div class=\"log_head\">" .
454 "author " . escapeHTML
($co{'author'}) . " [" . $ad{'rfc2822'} . "]<br/>\n";
455 if ($ad{'hour'} < 7 ) { print "<span style=\"color: #990000;\">"; }
456 if ($ad{'hour'} < 7 ) { print "</span>"; }
457 print "committer " . escapeHTML
($co{'committer'}) . " [" . $cd{'rfc2822'} . "]<br/>\n" .
458 "commit $hash<br/>\n" .
459 "tree " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'}"}, $co{'tree'}) . "<br/>\n";
460 my $parents = $co{'parents'};
461 foreach my $par (@$parents) {
462 print "parent " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$par"}, $par) . "<br/>\n";
465 print "<div class=\"page_body\">\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";
476 foreach my $line (@difftree) {
477 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
478 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
479 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
485 $mode =~ m/^([0-7]{6})/;
486 my $modestr = mode_str
($1);
487 if ($type eq "blob") {
489 print "$modestr " . $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$id"}, $file) . " (new)\n";
490 } elsif ($op eq "-") {
491 print "$modestr " . $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;hp=$id"}, $file) . " (removed)\n";
492 } elsif ($op eq "*") {
493 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
496 print "$modestr " . $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$to;hp=$from"}, $file) . "\n";
503 } elsif ($action eq "blobdiff") {
505 print "<div class=\"page_body\"><br/><br/>\n" .
507 git_diff_html
($hash_parent, $hash, $hash_parent, $hash);
511 } elsif ($action eq "commitdiff") {
512 my %co = git_commit
($hash);
513 open my $fd, "-|", "$gitbin/diff-tree -r " . $co{'parent'} . " $hash";
514 my (@difftree) = map { chomp; $_ } <$fd>;
518 print "<div class=\"page_nav\"> view\n" .
519 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
520 $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diff") . "\n" .
521 "<br/><br/></div>\n";
522 print $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash", -class => "log_title"}, $co{'title'}) ."\n";
523 print "<div class=\"page_body\">\n" .
525 foreach my $line (@difftree) {
526 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
527 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
533 if ($type eq "blob") {
535 git_diff_html
("", $file, "", $id);
536 } elsif ($op eq "-") {
537 git_diff_html
($file, "", $id, "");
538 } elsif ($op eq "*") {
539 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
540 git_diff_html
($file, $file, $1, $2);
544 print "<br/></pre>\n";
549 print "<div class=\"page_body\">\n" .
551 print "unknown action\n";
552 print "<br/></div>\n";
This page took 0.846602 seconds and 5 git commands to generate.