]>
Lady’s Gitweb - Gitweb/blob - gitweb.pl
7820d7dfedd38868c912cb0887a23e93a455393d7e66b7fdd95b376ffc7c96a3
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 = "/home/kay/public_html";
20 my $defaultprojects = ".";
21 my $gitbin = "/home/kay/bin/git";
23 my $my_url = $cgi->url();
24 my $my_uri = $cgi->url(-absolute
=> 1);
25 my $my_url_parm = $cgi->url(-path
=> 1);
26 $my_url_parm =~ s/.*$my_uri//;
35 if ($my_url_parm =~ m
#/+(.+)/+commit/+([0-9a-fA-F]+)$#) {
39 } elsif ($my_url_parm =~ m
#/+(.+)/+commitdiff/+([0-9a-fA-F]+)$#) {
41 $action = "commitdiff";
43 } elsif ($my_url_parm =~ m
#/+(.+)/+blobdiff/+([0-9a-fA-F]+)/([0-9a-fA-F]+)$#) {
48 } elsif ($my_url_parm =~ m
#/+(.+)/+blob/+([0-9a-fA-F]+)$#) {
52 } elsif ($my_url_parm =~ m
#/+(.+)/+tree/+([0-9a-fA-F]+)$#) {
56 } elsif ($my_url_parm =~ m
#/+(.+)/+log/+([0-9]+)$#) {
60 } elsif ($my_url_parm =~ m
#/+(.+)/+log$#) {
64 } elsif ($my_url_parm =~ m
#/+(.+)/rss$#) {
68 } elsif ($my_url_parm =~ m
#/+git-logo.png$#) {
69 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
70 print "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
71 "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
72 "\055\000\000\000\030\120\114\124\105\377\377\377\140\140\135\260".
73 "\257\252\000\200\000\316\315\307\300\000\000\350\350\346\367\367".
74 "\366\225\014\247\107\000\000\000\163\111\104\101\124\050\317\143".
75 "\110\147\040\004\112\134\030\012\010\052\142\123\141\040\002\010".
76 "\015\151\105\254\241\241\001\060\014\223\140\066\046\122\221\261".
77 "\001\021\326\341\125\144\154\154\314\154\154\014\242\014\160\052".
78 "\142\006\052\301\142\035\263\001\002\123\244\010\350\000\003\030".
79 "\046\126\021\324\341\040\227\033\340\264\016\065\044\161\051\202".
80 "\231\060\270\223\012\021\271\105\210\301\215\240\242\104\041\006".
81 "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305".
82 "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202";
84 } elsif ($my_url_parm =~ m
#/(.+)$#) {
91 $project =~ s
#\/\.+##g;
93 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/.git/objects";
96 print $cgi->header(-type
=> 'text/html', -charset
=> 'utf-8');
98 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
101 <title>git - $project $action</title>
102 <link rel="alternate" title="$project log" href="$my_uri/$project/rss" type="application/rss+xml"/>
103 <style type="text/css">
104 body { font-family: sans-serif; font-size: 12px; margin:25px; }
105 div.body { border-width:1px; border-style:solid; border-color:#D9D8D1; }
106 div.head1 { font-size:20px; padding:8px; background-color: #D9D8D1; font-weight:bold; }
107 div.head1 a:visited { color:#0000cc; }
108 div.head1 a:hover { color:#880000; }
109 div.head1 a:active { color:#880000; }
110 div.head2 { padding:8px; }
111 div.head2 a:visited { color:#0000cc; }
112 div.head2 a:hover { color:#880000; }
113 div.head2 a:active { color:#880000; }
114 div.title { padding:8px; background-color: #D9D8D1; font-weight:bold; }
115 div.title a { color:#000000; text-decoration:none; }
116 div.title a:hover { color:#880000; text-decoration:underline; }
117 div.title a:visited { color:#000000; }
118 table { padding:0px; margin:0px; width:100%; }
119 tr { vertical-align:top; }
120 td { padding:8px; margin:0px; font-family: sans-serif; font-size: 12px; }
121 td.head1 { background-color: #D9D8D1; font-weight:bold; }
122 td.head1 a { color:#000000; text-decoration:none; }
123 td.head1 a:hover { color:#880000; text-decoration:underline; }
124 td.head1 a:visited { color:#000000; }
125 td.head2 { background-color: #EDECE6; font-family: monospace; font-size:12px; }
126 td.head3 { background-color: #EDECE6; font-size:10px; }
127 div.signed_off { color: #a9a8a1; }
129 a:hover { color:#880000; }
130 a:visited { color:#880000; }
131 a:active { color:#880000; }
137 print "<div class=\"body\">\n";
138 print "<div class=\"head1\">";
139 print "<a href=\"http://kernel.org/pub/software/scm/git/\">" .
140 "<img src=\"$my_uri/git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
141 if ($defaultprojects ne "") {
142 print $cgi->a({-href
=> "$my_uri"}, "projects") . " / ";
144 if ($project ne "") {
145 print $cgi->a({-href
=> "$my_uri/$project/log"}, $project);
153 sub git_footer_html
{
155 print "</body>\n</html>";
159 open my $fd, "$projectroot/$project/.git/HEAD";
171 open my $fd, "-|", "$gitbin/cat-file", "commit", $commit;
172 while (my $line = <$fd>) {
175 if ($line =~ m/^tree (.*)$/) {
177 } elsif ($line =~ m/^parent (.*)$/) {
179 } elsif ($line =~ m/^committer (.*>) ([0-9]+) (.*)$/) {
180 $co{'committer'} = $1;
181 $co{'committer_time'} = $2;
182 $co{'committer_timezone'} = $3;
183 } elsif ($line =~ m/^author (.*>) ([0-9]+) (.*)$/) {
185 $co{'author_time'} = $2;
186 $co{'author_timezone'} = $3;
189 $co{'parents'} = \
@parents;
190 $co{'parent'} = $parents[0];
191 my (@comment) = map { chomp; $_ } <$fd>;
192 $co{'comment'} = \
@comment;
193 $co{'title'} = $comment[0];
199 my $from_name = shift || "/dev/null";
200 my $to_name = shift || "/dev/null";
204 my $from_tmp = "/dev/null";
205 my $to_tmp = "/dev/null";
206 my $from_label = "/dev/null";
207 my $to_label = "/dev/null";
210 # create temp from-file
212 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
213 open my $fd2, "> $from_tmp";
214 open my $fd, "-|", "$gitbin/cat-file", "blob", $from;
219 $from_label = "a/$from_name";
224 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
225 open my $fd2, "> $to_tmp";
226 open my $fd, "-|", "$gitbin/cat-file", "blob", $to;
231 $to_label = "b/$to_name";
234 open my $fd, "-|", "/usr/bin/diff", "-L", $from_label, "-L", $to_label, "-u", "-p", $from_tmp, $to_tmp;
235 print "<span style =\"color: #000099;\">===== ";
237 print $cgi->a({-href
=> "$my_uri/$project/blob/$from"}, $from);
243 print $cgi->a({-href
=> "$my_uri/$project/blob/$to"}, $to);
247 print " =====</span>\n";
248 while (my $line = <$fd>) {
249 my $char = substr($line,0,1);
250 print '<span style ="color: #008800;">' if $char eq '+';
251 print '<span style ="color: #CC0000;">' if $char eq '-';
252 print '<span style ="color: #990099;">' if $char eq '@';
253 print escapeHTML
($line);
254 print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
267 my $perms = oct shift;
269 if ($perms & 040000) { $modestr .= 'd' } else { $modestr .= '-' };
270 for (my $i = 0; $i < 3; $i++) {
271 if ($perms & 0400) { $modestr .= 'r' } else { $modestr .= '-' };
272 if ($perms & 0200) { $modestr .= 'w' } else { $modestr .= '-' };
273 if ($perms & 0100) { $modestr .= 'x' } else { $modestr .= '-' };
279 # show list of default projects
280 if ($project eq "") {
281 opendir(my $fd, "$projectroot/$defaultprojects");
282 my (@path) = grep(!/^\./, readdir($fd));
285 print "<div class=\"head2\">\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/$defaultprojects/$line/log"}, $line) . "<br/>\n";
297 if ($action eq "blob") {
299 print "<br/><br/>\n";
301 open my $fd, "-|", "$gitbin/cat-file", "blob", $hash;
303 while (my $line = <$fd>) {
305 print "$nr\t" . escapeHTML
($line);;
311 } elsif ($action eq "tree") {
315 open my $fd, "-|", "$gitbin/ls-tree", $hash;
316 my (@entries) = map { chomp; $_ } <$fd>;
319 print "<br/><br/>\n";
321 foreach my $line (@entries) {
322 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
323 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
328 if ($t_type eq "blob") {
329 print mode_str
($t_mode). " " . $cgi->a({-href
=> "$my_uri/$project/blob/$t_hash"}, $t_name) . "\n";
330 } elsif ($t_type eq "tree") {
331 print mode_str
($t_mode). " " . $cgi->a({-href
=> "$my_uri/$project/tree/$t_hash"}, $t_name) . "\n";
337 } elsif ($action eq "log" || $action eq "rss") {
338 open my $fd, "-|", "$gitbin/rev-list", git_head
();
339 my (@revtree) = map { chomp; $_ } <$fd>;
342 if ($action eq "log") {
344 print "<div class=\"head2\">\n";
346 print $cgi->a({-href
=> "$my_uri/$project/log"}, "last day") . " | ";
347 print $cgi->a({-href
=> "$my_uri/$project/log/7"}, "week") . " | ";
348 print $cgi->a({-href
=> "$my_uri/$project/log/31"}, "month") . " | ";
349 print $cgi->a({-href
=> "$my_uri/$project/log/365"}, "year") . " | ";
350 print $cgi->a({-href
=> "$my_uri/$project/log/0"}, "all") . "<br/>\n";
351 print "<br/><br/>\n";
353 print "<table cellspacing=\"0\" class=\"log\">\n";
354 } elsif ($action eq "rss") {
355 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
356 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
357 "<rss version=\"0.91\">\n";
359 print "<title>$project</title>\n".
360 "<link> " . $my_url . "/$project/log</link>\n".
361 "<description>$project log</description>\n".
362 "<language>en</language>\n";
365 for (my $i = 0; $i <= $#revtree; $i++) {
366 my $commit = $revtree[$i];
368 my %co = git_commit
($commit);
369 my $age = time - $co{'committer_time'};
371 if ($age > 60*60*24*365*2) {
372 $age_string = int $age/60/60/24/365;
373 $age_string .= " years ago";
374 } elsif ($age > 60*60*24*365/12*2) {
375 $age_string = int $age/60/60/24/365/12;
376 $age_string .= " months ago";
377 } elsif ($age > 60*60*24*7*2) {
378 $age_string = int $age/60/60/24/7;
379 $age_string .= " weeks ago";
380 } elsif ($age > 60*60*24*2) {
381 $age_string = int $age/60/60/24;
382 $age_string .= " days ago";
383 } elsif ($age > 60*60*2) {
384 $age_string = int $age/60/60;
385 $age_string .= " hours ago";
386 } elsif ($age > 60*2) {
387 $age_string = int $age/60;
388 $age_string .= " minutes ago";
390 if ($action eq "log") {
391 if ($view_back > 0 && $age > $view_back*60*60*24) {
394 print "<td class=\"head1\"> Last change $age_string. </td>\n";
400 print "<td class=\"head1\">" . $age_string . "</td>\n";
401 print "<td class=\"head1\">" . $cgi->a({-href
=> "$my_uri/$project/commit/$commit"}, $co{'title'}) . "</td>";
404 print "<td class=\"head3\">";
405 print $cgi->a({-href
=> "$my_uri/$project/commit/$commit"}, "view commit") . "<br/>\n";
406 print $cgi->a({-href
=> "$my_uri/$project/commitdiff/$commit"}, "view diff") . "<br/>\n";
408 print "<td class=\"head2\">\n";
409 print "author " . escapeHTML
($co{'author'}) . " [" . gmtime($co{'author_time'}) . " " . $co{'author_timezone'} . "]<br/>\n";
410 print "committer " . escapeHTML
($co{'committer'}) . " [" . gmtime($co{'committer_time'}) . " " . $co{'committer_timezone'} . "]<br/>\n";
416 my $comment = $co{'comment'};
417 foreach my $line (@$comment) {
418 if ($line =~ m/^(signed-off|acked)-by:/i) {
419 print '<div class="signed_off">' . escapeHTML
($line) . "<br/></div>\n";
421 print escapeHTML
($line) . "<br/>\n";
424 print "<br/><br/>\n";
427 } elsif ($action eq "rss") {
429 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime($co{'author_time'});
430 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
431 print "<item>\n\t<title>";
432 printf("%s %02d, %02d:%02d - ", $months[$mon], $mday, $hour, $min);
433 print escapeHTML
($co{'title'}) . "</title>\n";
434 print "\t<link> " . $my_url . "/$project/commit/$commit</link>\n";
435 print "\t<description>";
436 my $comment = $co{'comment'};
437 foreach my $line (@$comment) {
438 print escapeHTML
($line) . "\n";
440 print "\t</description>\n";
444 if ($action eq "log") {
447 } elsif ($action eq "rss") {
448 print "</channel></rss>";
450 } elsif ($action eq "commit") {
451 my %co = git_commit
($hash);
452 open my $fd, "-|", "$gitbin/diff-tree", "-r", $co{'parent'}, $hash;
453 my (@difftree) = map { chomp; $_ } <$fd>;
457 print "<div class=\"head2\"> view\n";
458 print $cgi->a({-href
=> "$my_uri/$project/commit/$hash"}, "commit") . " | ";
459 print $cgi->a({-href
=> "$my_uri/$project/commitdiff/$hash"}, "diff");
460 print "</div><br/><br/>\n";
461 print "<div class=\"title\">" . $cgi->a({-href
=> "$my_uri/$project/commitdiff/$hash"}, $co{'title'}) . "<br/></div>\n";
462 print "<table cellspacing=\"0\" class=\"log\">\n";
464 print "<td class=\"head2\">";
465 print "author " . escapeHTML
($co{'author'}) . " [" . gmtime($co{'author_time'}) . " " . $co{'author_timezone'} . "]<br/>\n";
466 print "committer " . escapeHTML
($co{'committer'}) . " [" . gmtime($co{'committer_time'}) . " " . $co{'committer_timezone'} . "]<br/>\n";
467 print "commit $hash<br/>\n";
468 print "tree " . $cgi->a({-href
=> "$my_uri/$project/tree/$co{'tree'}"}, $co{'tree'}) . "<br/>\n";
469 my $parents = $co{'parents'};
470 foreach my $par (@$parents) {
471 print "parent " . $cgi->a({-href
=> "$my_uri/$project/tree/$par"}, $par) . "<br/>\n";
477 my $comment = $co{'comment'};
478 foreach my $line (@$comment) {
479 if ($line =~ m/(signed-off|acked)-by:/i) {
480 print '<div class="signed_off">' . escapeHTML
($line) . "<br/></div>\n";
482 print escapeHTML
($line) . "<br/>\n";
485 print "<br/><br/>\n";
491 foreach my $line (@difftree) {
492 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
493 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
494 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
500 $mode =~ m/^([0-7]{6})/;
501 my $modestr = mode_str
($1);
502 if ($type eq "blob") {
504 print "added\t$modestr " . $cgi->a({-href
=> "$my_uri/$project/blob/$id"}, $file) . "\n";
505 } elsif ($op eq "-") {
506 print "removed\t$modestr " . $cgi->a({-href
=> "$my_uri/$project/blob/$id"}, $file) . "\n";
507 } elsif ($op eq "*") {
508 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
511 print "changed\t$modestr " . $cgi->a({-href
=> "$my_uri/$project/blobdiff/$old/$new"}, $file) . "\n";
518 } elsif ($action eq "blobdiff") {
520 print "<br/><br/>\n";
522 git_diff_html
($hash, $hash_parent, $hash, $hash_parent);
526 } elsif ($action eq "commitdiff") {
527 my %co = git_commit
($hash);
528 open my $fd, "-|", "$gitbin/diff-tree", "-r", $co{'parent'}, $hash;
529 my (@difftree) = map { chomp; $_ } <$fd>;
533 print "<div class=\"head2\"> view\n";
534 print $cgi->a({-href
=> "$my_uri/$project/commit/$hash"}, "commit") . " | ";
535 print $cgi->a({-href
=> "$my_uri/$project/commitdiff/$hash"}, "diff");
536 print "</div><br/><br/>\n";
537 print "<div class=\"title\">" . $cgi->a({-href
=> "$my_uri/$project/commit/$hash"}, $co{'title'}) . "<br/></div>\n";
539 foreach my $line (@difftree) {
540 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
541 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
547 if ($type eq "blob") {
549 git_diff_html
("", $file, "", $id);
550 } elsif ($op eq "-") {
551 git_diff_html
($file, "", $id, "");
552 } elsif ($op eq "*") {
553 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
554 git_diff_html
($file, $file, $1, $2);
This page took 0.99376 seconds and 3 git commands to generate.