]>
Lady’s Gitweb - Gitweb/blob - gitweb.pl
bb5b95292270bf7a1cb32cc6cad8efc30aec0bc92e5b505e20bb1a9769dd84fb
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);
17 my $projectroot = "/home/kay/public_html";
18 my $defaultprojects = ".";
19 my $gitbin = "/home/kay/bin/git";
28 my $myself = $cgi->url(-absolute
=> 1);
29 my $url_parm = $cgi->url(-path
=> 1);
30 $url_parm =~ s/.*$myself//;
33 if ($url_parm =~ m
#/(.+)/commit/([0-9a-fA-F]+)$#) {
37 } elsif ($url_parm =~ m
#/(.+)/commitdiff/([0-9a-fA-F]+)$#) {
39 $action = "commitdiff";
41 } elsif ($url_parm =~ m
#/(.+)/blobdiff/([0-9a-fA-F]+)/([0-9a-fA-F]+)$#) {
46 } elsif ($url_parm =~ m
#/(.+)/blob/([0-9a-fA-F]+)$#) {
50 } elsif ($url_parm =~ m
#/(.+)/tree/([0-9a-fA-F]+)$#) {
54 } elsif ($url_parm =~ m
#/(.+)/log/([0-9]+)$#) {
58 } elsif ($url_parm =~ m
#/(.+)/log$#) {
62 } elsif ($url_parm =~ m
#/(.+)/rss$#) {
66 } elsif ($url_parm =~ m
#/git-logo.png$#) {
67 print $cgi->header(-type
=> 'image/png');
68 print "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
69 "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
70 "\055\000\000\000\030\120\114\124\105\377\377\377\140\140\135\260".
71 "\257\252\000\200\000\316\315\307\300\000\000\350\350\346\367\367".
72 "\366\225\014\247\107\000\000\000\163\111\104\101\124\050\317\143".
73 "\110\147\040\004\112\134\030\012\010\052\142\123\141\040\002\010".
74 "\015\151\105\254\241\241\001\060\014\223\140\066\046\122\221\261".
75 "\001\021\326\341\125\144\154\154\314\154\154\014\242\014\160\052".
76 "\142\006\052\301\142\035\263\001\002\123\244\010\350\000\003\030".
77 "\046\126\021\324\341\040\227\033\340\264\016\065\044\161\051\202".
78 "\231\060\270\223\012\021\271\105\210\301\215\240\242\104\041\006".
79 "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305".
80 "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202";
82 } elsif ($url_parm =~ m
#/(.+)$#) {
89 $project =~ s
#\/\.+##g;
91 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/.git/objects";
94 print $cgi->header(-type
=> 'text/html; charset: utf-8');
96 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
99 <title>git - $project $action</title>
100 <link rel="alternate" title="$project log" href="$myself/$project/rss" type="application/rss+xml">
101 <style type="text/css">
102 body { font-family: sans-serif; font-size: 12px; margin:25px; }
103 div.body { border-width:1px; border-style:solid; border-color:#D9D8D1; }
104 div.head1 { font-size:20px; padding:8px; background-color: #D9D8D1; font-weight:bold; }
105 div.head1 a:visited { color:#0000cc; }
106 div.head1 a:hover { color:#880000; }
107 div.head1 a:active { color:#880000; }
108 div.head2 { padding:8px; }
109 div.head2 a:visited { color:#0000cc; }
110 div.head2 a:hover { color:#880000; }
111 div.head2 a:active { color:#880000; }
112 div.shortlog { padding:8px; background-color: #D9D8D1; font-weight:bold; }
113 table { padding:0px; margin:0px; width:100%; }
114 tr { vertical-align:top; }
115 td { padding:8px; margin:0px; font-family: sans-serif; font-size: 12px; }
116 td.head1 { background-color: #D9D8D1; font-weight:bold; }
117 td.head1 a { color:#000000; text-decoration:none; }
118 td.head1 a:hover { color:#880000; text-decoration:underline; }
119 td.head1 a:visited { color:#000000; }
120 td.head2 { background-color: #EDECE6; font-family: monospace; font-size:12px; }
121 td.head3 { background-color: #EDECE6; font-size:10px; }
122 div.signed_off { color: #a9a8a1; }
124 a:hover { color:#880000; }
125 a:visited { color:#880000; }
126 a:active { color:#880000; }
132 print "<div class=\"body\">\n";
133 print "<div class=\"head1\">";
134 print "<a href=\"http://kernel.org/pub/software/scm/git/\"><img src=\"$myself/git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
135 if ($defaultprojects ne "") {
136 print $cgi->a({-href
=> "$myself"}, "projects") . " / ";
138 if ($project ne "") {
139 print $cgi->a({-href
=> "$myself/$project/log"}, $project);
147 sub git_footer_html
{
149 print $cgi->end_html();
153 open my $fd, "$projectroot/$project/.git/HEAD";
165 open my $fd, "-|", "$gitbin/cat-file", "commit", $commit;
166 while (my $line = <$fd>) {
169 if ($line =~ m/^tree (.*)$/) {
171 } elsif ($line =~ m/^parent (.*)$/) {
173 } elsif ($line =~ m/^committer (.*>) ([0-9]+) (.*)$/) {
174 $co{'committer'} = $1;
175 $co{'committer_time'} = $2;
176 $co{'committer_timezone'} = $3;
177 } elsif ($line =~ m/^author (.*>) ([0-9]+) (.*)$/) {
179 $co{'$author_time'} = $2;
180 $co{'$author_timezone'} = $3;
183 my $shortlog = <$fd>;
185 $co{'shortlog'} = escapeHTML
($shortlog);
186 my $comment = $shortlog . "<br/>";
187 while (my $line = <$fd>) {
189 if ($line =~ m/signed-off-by:/i) {
190 $comment .= '<div class="signed_off">' . escapeHTML
($line) . "<br/></div>\n";
192 $comment .= escapeHTML
($line) . "<br/>\n";
195 $co{'comment'} = $comment;
202 my $old_name = shift || "/dev/null";
203 my $new_name = shift || "/dev/null";
207 my $tmp_old = "/dev/null";
208 my $tmp_new = "/dev/null";
209 my $old_label = "/dev/null";
210 my $new_label = "/dev/null";
212 # create temp from-file
214 open my $fd2, "> $gittmp/$old";
215 open my $fd, "-|", "$gitbin/cat-file", "blob", $old;
216 while (my $line = <$fd>) {
221 $tmp_old = "$gittmp/$old";
222 $old_label = "a/$old_name";
227 open my $fd2, "> $gittmp/$new";
228 open my $fd, "-|", "$gitbin/cat-file", "blob", $new;
229 while (my $line = <$fd>) {
234 $tmp_new = "$gittmp/$new";
235 $new_label = "b/$new_name";
238 open my $fd, "-|", "/usr/bin/diff", "-L", $old_label, "-L", $new_label, "-u", "-p", $tmp_old, $tmp_new;
239 print "<span style =\"color: #000099;\">===== ";
241 print $cgi->a({-href
=> "$myself/$project/blob/$old"}, $old);
247 print $cgi->a({-href
=> "$myself/$project/blob/$new"}, $new);
251 print " =====</span>\n";
252 while (my $line = <$fd>) {
253 my $char = substr($line,0,1);
254 print '<span style ="color: #008800;">' if $char eq '+';
255 print '<span style ="color: #CC0000;">' if $char eq '-';
256 print '<span style ="color: #990099;">' if $char eq '@';
257 print escapeHTML
($line);
258 print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
261 unlink("$gittmp/$new");
262 unlink("$gittmp/$old");
265 if ($project eq "") {
266 opendir(my $fd, "$projectroot/$defaultprojects");
267 my (@path) = grep(!/^\./, readdir($fd));
270 print "<div class=\"head2\">\n";
271 print "<br/><br/>\n";
272 foreach my $line (@path) {
273 if (-e
"$projectroot/$defaultprojects/$line/.git/HEAD") {
274 print $cgi->a({-href
=> "$myself/$defaultprojects/$line/log"}, $line) . "<br/>\n";
282 if ($action eq "blob") {
284 print "<br/><br/>\n";
286 open my $fd, "-|", "$gitbin/cat-file", "blob", $hash;
288 while (my $line = <$fd>) {
290 print "$nr\t" . escapeHTML
($line);;
296 } elsif ($action eq "tree") {
300 open my $fd, "-|", "$gitbin/ls-tree", $hash;
301 my (@entries) = map { chomp; $_ } <$fd>;
304 print "<br/><br/>\n";
306 foreach my $line (@entries) {
307 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
308 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
312 if ($t_type eq "blob") {
313 print "BLOB\t" . $cgi->a({-href
=> "$myself/$project/blob/$3"}, $4) . "\n";
314 } elsif ($t_type eq "tree") {
315 print "TREE\t" . $cgi->a({-href
=> "$myself/$project/tree/$3"}, $4) . "\n";
321 } elsif ($action eq "log" || $action eq "rss") {
322 open my $fd, "-|", "$gitbin/rev-tree", git_head
();
323 my (@revtree) = reverse sort map { chomp; $_ } <$fd>;
326 if ($action eq "log") {
328 print "<div class=\"head2\">\n";
330 print $cgi->a({-href
=> "$myself/$project/log"}, "last day") . " | ";
331 print $cgi->a({-href
=> "$myself/$project/log/7"}, "week") . " | ";
332 print $cgi->a({-href
=> "$myself/$project/log/31"}, "month") . " | ";
333 print $cgi->a({-href
=> "$myself/$project/log/365"}, "year") . " | ";
334 print $cgi->a({-href
=> "$myself/$project/log/0"}, "all") . "<br/>\n";
335 print "<br/><br/>\n";
337 print "<table cellspacing=\"0\" class=\"log\">\n";
338 } elsif ($action eq "rss") {
339 print $cgi->header(-type
=> 'text/xml; charset: utf-8');
340 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
341 "<rss version=\"0.91\">\n";
343 print "<title>$project</title>\n".
344 "<link> " . $cgi->url() . "/$project/log</link>\n".
345 "<description>$project log</description>\n".
346 "<language>en</language>\n";
349 for (my $i = 0; $i <= $#revtree; $i++) {
350 my $rev = $revtree[$i];
351 #foreach my $rev (@revtree) {
352 # '1114106118 755e3010ee10dadf42a8a80770e1b115fb038d9b:1 2af17b4854036a1c2ec6c101d93c8dd1ed80d24e:1'
353 last if !($rev =~ m/^([0-9]+) ([0-9a-fA-F]+).* ([0-9a-fA-F]+)/);
358 my ($author, $author_time, $author_timezone);
359 my ($committer, $committer_time, $committer_timezone);
363 open my $fd, "-|", "$gitbin/cat-file", "commit", $commit;
364 while (my $line = <$fd>) {
367 if ($line =~ m/^tree (.*)$/) {
369 } elsif ($line =~ m/^parent (.*)$/) {
371 } elsif ($line =~ m/^committer (.*>) ([0-9]+) (.*)$/) {
373 $committer_time = $2;
374 $committer_timezone = $3;
375 } elsif ($line =~ m/^author (.*>) ([0-9]+) (.*)$/) {
378 $author_timezone = $3;
383 $shortlog = escapeHTML
($shortlog);
384 $comment = $shortlog . "<br/>";
385 while (my $line = <$fd>) {
387 if ($line =~ m/signed-off-by:/i) {
388 $comment .= '<div class="signed_off">' . escapeHTML
($line) . "<br/></div>\n";
390 $comment .= escapeHTML
($line) . "<br/>\n";
395 my $age = time-
$committer_time;
397 if ($age > 60*60*24*365*2) {
398 $age_string = int $age/60/60/24/365;
399 $age_string .= " years ago";
400 } elsif ($age > 60*60*24*365/12*2) {
401 $age_string = int $age/60/60/24/365/12;
402 $age_string .= " months ago";
403 } elsif ($age > 60*60*24*7*2) {
404 $age_string = int $age/60/60/24/7;
405 $age_string .= " weeks ago";
406 } elsif ($age > 60*60*24*2) {
407 $age_string = int $age/60/60/24;
408 $age_string .= " days ago";
409 } elsif ($age > 60*60*2) {
410 $age_string = int $age/60/60;
411 $age_string .= " hours ago";
412 } elsif ($age > 60*2) {
413 $age_string = int $age/60;
414 $age_string .= " minutes ago";
416 if ($action eq "log") {
417 if ($view_back > 0 && $age > $view_back*60*60*24) {
420 print "<td class=\"head1\"> Last change $age_string. </td>\n";
426 print "<td class=\"head1\">" . $age_string . "</td>\n";
427 print "<td class=\"head1\">" . $cgi->a({-href
=> "$myself/$project/commit/$commit"}, $shortlog) . "</td>";
430 print "<td class=\"head3\">";
431 print $cgi->a({-href
=> "$myself/$project/commitdiff/$commit"}, "view diff") . "<br/>\n";
432 print $cgi->a({-href
=> "$myself/$project/commit/$commit"}, "view commit") . "<br/>\n";
433 print $cgi->a({-href
=> "$myself/$project/tree/$tree"}, "view tree") . "<br/>\n";
435 print "<td class=\"head2\">\n";
436 print "author " . escapeHTML
($author) . " [" . gmtime($author_time) . " " . $author_timezone . "]<br/>\n";
437 print "committer " . escapeHTML
($committer) . " [" . gmtime($committer_time) . " " . $committer_timezone . "]<br/>\n";
438 print "commit $commit<br/>\n";
439 print "tree $tree<br/>\n";
440 foreach my $par (@parents) {
441 print "parent $par<br/>\n";
448 print "$comment<br/><br/>\n";
451 } elsif ($action eq "rss") {
453 print "<item>\n\t<title>$age_string: $shortlog</title>\n";
454 print "\t<link> " . $cgi->url() . "/$project/commit/$commit</link>\n";
458 if ($action eq "log") {
461 } elsif ($action eq "rss") {
462 print "</channel></rss>";
464 } elsif ($action eq "commit") {
466 open my $fd, "-|", "$gitbin/cat-file", "commit", $hash;
467 while (my $line = <$fd>) {
470 if ($line =~ m/^parent (.*)$/ && $parent eq "") {
474 my $shortlog = <$fd>;
475 $shortlog = escapeHTML
($shortlog);
478 open $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash;
479 my (@difftree) = map { chomp; $_ } <$fd>;
483 print "<div class=\"head2\">\n";
484 print "view " . $cgi->a({-href
=> "$myself/$project/commitdiff/$hash"}, "diff") . "</div><br/><br/>\n";
485 print "<div class=\"shortlog\">$shortlog<br/></div>\n";
487 foreach my $line (@difftree) {
488 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
489 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
490 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
496 if ($type eq "blob") {
498 print "added\t" . $cgi->a({-href
=> "$myself/$project/blob/$id"}, $file) . "\n";
499 } elsif ($op eq "-") {
500 print "removed\t" . $cgi->a({-href
=> "$myself/$project/blob/$id"}, $file) . "\n";
501 } elsif ($op eq "*") {
502 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
505 print "changed\t" . $cgi->a({-href
=> "$myself/$project/blobdiff/$old/$new"}, $file) . "\n";
512 } elsif ($action eq "blobdiff") {
514 print "<br/><br/>\n";
516 git_diff
($hash, $hash_parent, $hash, $hash_parent);
520 } elsif ($action eq "commitdiff") {
522 open my $fd, "-|", "$gitbin/cat-file", "commit", $hash;
523 while (my $line = <$fd>) {
526 if ($line =~ m/^parent (.*)$/ && $parent eq "") {
530 my $shortlog = <$fd>;
531 $shortlog = escapeHTML
($shortlog);
534 open $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash;
535 my (@difftree) = map { chomp; $_ } <$fd>;
539 print "<div class=\"head2\">\n";
540 print "view " . $cgi->a({-href
=> "$myself/$project/commit/$hash"}, "commit") . "</div><br/><br/>\n";
541 print "<div class=\"shortlog\">$shortlog<br/></div>\n";
543 foreach my $line (@difftree) {
544 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
545 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
551 if ($type eq "blob") {
553 git_diff
("", $file, "", $id);
554 } elsif ($op eq "-") {
555 git_diff
($file, "", $id, "");
556 } elsif ($op eq "*") {
557 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
558 git_diff
($file, $file, $1, $2);
This page took 0.424082 seconds and 3 git commands to generate.