]>
Lady’s Gitweb - Gitweb/blob - gitweb.pl
ecd62f8cb97c6cb1c33c83ef98bf2b49557233dd8c1e54e227a9df782f1533a5
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 $gitbin = "/home/kay/bin/git"; # path to the git executables
18 my $gitroot = "/home/kay/public_html"; # path to the git repositories
19 my $gittmp = "/tmp"; # temporary files location
27 my $myself = $cgi->url(-absolute
=> 1);
28 my $url_path = $cgi->url(-path
=> 1);
31 if ($url_path =~ m
#/([^/]+)/commit/([0-9a-fA-F]+)$#) {
35 } elsif ($url_path =~ m
#/([^/]+)/treediff/([0-9a-fA-F]+)$#) {
39 } elsif ($url_path =~ m
#/([^/]+)/diff/([0-9a-fA-F]+)/([0-9a-fA-F]+)$#) {
44 } elsif ($url_path =~ m
#/([^/]+)/blob/([0-9a-fA-F]+)$#) {
48 } elsif ($url_path =~ m
#/([^/]+)/tree/([0-9a-fA-F]+)$#) {
52 } elsif ($url_path =~ m
#/([^/]+)/log/([0-9]+)$#) {
56 } elsif ($url_path =~ m
#/([^/]+)/log$#) {
60 } elsif ($url_path =~ m
#/git-logo.png$#) {
61 print $cgi->header(-type
=> 'image/png');
62 print "\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104\122".
63 "\000\000\000\110\000\000\000\033\004\003\000\000\000\055\331\324".
64 "\055\000\000\000\030\120\114\124\105\377\377\377\140\140\135\260".
65 "\257\252\000\200\000\316\315\307\300\000\000\350\350\346\367\367".
66 "\366\225\014\247\107\000\000\000\163\111\104\101\124\050\317\143".
67 "\110\147\040\004\112\134\030\012\010\052\142\123\141\040\002\010".
68 "\015\151\105\254\241\241\001\060\014\223\140\066\046\122\221\261".
69 "\001\021\326\341\125\144\154\154\314\154\154\014\242\014\160\052".
70 "\142\006\052\301\142\035\263\001\002\123\244\010\350\000\003\030".
71 "\046\126\021\324\341\040\227\033\340\264\016\065\044\161\051\202".
72 "\231\060\270\223\012\021\271\105\210\301\215\240\242\104\041\006".
73 "\047\101\202\100\205\301\105\211\040\160\001\000\244\075\041\305".
74 "\022\034\232\376\000\000\000\000\111\105\116\104\256\102\140\202";
79 $hash =~ s/[^0-9a-fA-F]//g;
80 $hash_parent =~ s/[^0-9a-fA-F]//g;
81 $project =~ s/[^0-9a-zA-Z\-\._]//g;
83 my $projectroot = "$gitroot/$project";
84 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/.git/objects";
87 print $cgi->header(-type
=> 'text/html; charset: utf-8');
89 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
92 <title>git - $project $action</title>
93 <style type="text/css">
94 body { font-family: sans-serif; font-size: 12px; margin:25px; }
95 div.body { border-width:1px; border-style:solid; border-color:#D9D8D1; }
96 div.head1 { font-size:20px; padding:8px; background-color: #D9D8D1; font-weight:bold; }
97 div.head1 a:visited { color:#0000cc; }
98 div.head1 a:hover { color:#880000; }
99 div.head1 a:active { color:#880000; }
100 div.head2 { padding:8px; }
101 div.head2 a:visited { color:#0000cc; }
102 div.head2 a:hover { color:#880000; }
103 div.head2 a:active { color:#880000; }
104 div.main { padding:8px; font-family: sans-serif; font-size: 12px; }
105 table { padding:0px; margin:0px; width:100%; }
106 tr { vertical-align:top; }
107 td { padding:8px; margin:0px; font-family: sans-serif; font-size: 12px; }
108 td.head1 { background-color: #D9D8D1; font-weight:bold; }
109 td.head1 a { color:#000000; text-decoration:none; }
110 td.head1 a:hover { color:#880000; text-decoration:underline; }
111 td.head1 a:visited { color:#000000; }
112 td.head2 { background-color: #EDECE6; font-family: monospace; font-size:12px; }
113 td.head3 { background-color: #EDECE6; font-size:10px; }
114 div.add { color: #008800; }
115 div.subtract { color: #CC0000; }
116 div.diff_head { color: #000099; }
117 div.diff_head a:visited { color:#0000cc; }
118 div.diff_line { color: #990099; }
120 a:hover { color:#880000; }
121 a:visited { color:#880000; }
122 a:active { color:#880000; }
127 print "<div class=\"body\">\n";
128 print "<div class=\"head1\">";
129 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>";
130 print $cgi->a({-href
=> "$myself"}, "projects");
131 if ($project ne "") {
132 print " / " . $cgi->a({-href
=> "$myself/$project/log"}, $project);
142 print $cgi->end_html();
146 my $old_name = shift || "/dev/null";
147 my $new_name = shift || "/dev/null";
151 my $tmp_old = "/dev/null";
152 my $tmp_new = "/dev/null";
153 my $old_label = "/dev/null";
154 my $new_label = "/dev/null";
156 # create temp from-file
158 open my $fd2, "> $gittmp/$old";
159 open my $fd, "-|", "$gitbin/cat-file", "blob", $old;
160 while (my $line = <$fd>) {
165 $tmp_old = "$gittmp/$old";
166 $old_label = "a/$old_name";
171 open my $fd2, "> $gittmp/$new";
172 open my $fd, "-|", "$gitbin/cat-file", "blob", $new;
173 while (my $line = <$fd>) {
178 $tmp_new = "$gittmp/$new";
179 $new_label = "b/$new_name";
182 open my $fd, "-|", "/usr/bin/diff", "-L", $old_label, "-L", $new_label, "-u", "-p", $tmp_old, $tmp_new;
183 print '<div class="diff_head">===== ';
185 print $cgi->a({-href
=> "$myself/$project/blob/$old"}, $old);
191 print $cgi->a({-href
=> "$myself/$project/blob/$new"}, $new);
195 print ' =====</div>';
196 while (my $line = <$fd>) {
197 my $char = substr($line,0,1);
198 print '<div class="add">' if $char eq '+';
199 print '<div class="subtract">' if $char eq '-';
200 print '<div class="diff_line">' if $char eq '@';
201 print escapeHTML
($line);
202 print '</div>' if $char eq '+' or $char eq '-' or $char eq '@';
205 unlink("$gittmp/$new");
206 unlink("$gittmp/$old");
209 if ($project eq "") {
210 opendir(my $fd, $gitroot);
211 my (@path) = grep(!/^\./, readdir($fd));
214 print "<br/><br/><div class=\"main\">\n";
215 foreach my $line (@path) {
216 if (-e
"$gitroot/$line/.git/HEAD") {
217 print $cgi->a({-href
=> "$myself/$line/log"}, $line) . "<br/>\n";
226 print $cgi->redirect("$myself/$project/log/$view_back");
230 if ($action eq "blob") {
232 print "<br/><br/><div class=\"main\">\n";
234 open my $fd, "-|", "$gitbin/cat-file", "blob", $hash;
236 while (my $line = <$fd>) {
238 print "$nr\t" . escapeHTML
($line);;
244 } elsif ($action eq "tree") {
246 open my $fd, "$projectroot/.git/HEAD";
252 open my $fd, "-|", "$gitbin/ls-tree", $hash;
253 my (@entries) = map { chomp; $_ } <$fd>;
256 print "<br/><br/><div class=\"main\">\n";
258 foreach my $line (@entries) {
259 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
260 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
264 if ($t_type eq "blob") {
265 print "BLOB\t" . $cgi->a({-href
=> "$myself/$project/blob/$3"}, $4) . "\n";
266 } elsif ($t_type eq "tree") {
267 print "TREE\t" . $cgi->a({-href
=> "$myself/$project/tree/$3"}, $4) . "\n";
273 } elsif ($action eq "log") {
274 open my $fd, "$projectroot/.git/HEAD";
278 open $fd, "-|", "$gitbin/rev-tree", $head;
279 my (@revtree) = map { chomp; $_ } <$fd>;
282 print "<div class=\"head2\">\n";
284 print $cgi->a({-href
=> "$myself/$project/log"}, "last day") . " | ";
285 print $cgi->a({-href
=> "$myself/$project/log/7"}, "week") . " | ";
286 print $cgi->a({-href
=> "$myself/$project/log/31"}, "month") . " | ";
287 print $cgi->a({-href
=> "$myself/$project/log/365"}, "year") . " | ";
288 print $cgi->a({-href
=> "$myself/$project/log/0"}, "all") . "<br/>\n";
289 print "<br/><br/>\n";
291 print "<table cellspacing=\"0\" class=\"log\">\n";
292 foreach my $rev (reverse sort @revtree) {
293 # '1114106118 755e3010ee10dadf42a8a80770e1b115fb038d9b:1 2af17b4854036a1c2ec6c101d93c8dd1ed80d24e:1'
294 last if !($rev =~ m/^([0-9]+) ([0-9a-fA-F]+).* ([0-9a-fA-F]+)/);
299 my ($author, $author_time, $author_timezone);
300 my ($committer, $committer_time, $committer_timezone);
304 open my $fd, "-|", "$gitbin/cat-file", "commit", $commit;
305 while (my $line = <$fd>) {
308 if ($line =~ m/^tree (.*)$/) {
310 } elsif ($line =~ m/^parent (.*)$/) {
312 } elsif ($line =~ m/^committer (.*>) ([0-9]+) (.*)$/) {
314 $committer_time = $2;
315 $committer_timezone = $3;
316 } elsif ($line =~ m/^author (.*>) ([0-9]+) (.*)$/) {
319 $author_timezone = $3;
323 $shortlog = escapeHTML
($shortlog);
324 $comment = $shortlog . "<br/>";
325 while (my $line = <$fd>) {
327 $comment .= escapeHTML
($line) . "<br/>\n";
330 my $age = time-
$committer_time;
331 last if ($view_back > 0 && $age > $view_back*60*60*24);
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";
354 print "<td class=\"head1\">" . $age_string . "</td>\n";
355 print "<td class=\"head1\">" . $cgi->a({-href
=> "$myself/$project/commit/$commit"}, $shortlog) . "</td>";
358 print "<td class=\"head3\">";
359 print $cgi->a({-href
=> "$myself/$project/treediff/$commit"}, "view diff") . "<br/>\n";
360 print $cgi->a({-href
=> "$myself/$project/commit/$commit"}, "view commit") . "<br/>\n";
361 print $cgi->a({-href
=> "$myself/$project/tree/$tree"}, "view tree") . "<br/>\n";
363 print "<td class=\"head2\">\n";
364 print "author " . escapeHTML
($author) . " [" . gmtime($author_time) . " " . $author_timezone . "]<br/>\n";
365 print "committer " . escapeHTML
($committer) . " [" . gmtime($committer_time) . " " . $committer_timezone . "]<br/>\n";
366 print "commit $commit<br/>\n";
367 print "tree $tree<br/>\n";
368 foreach my $par (@parents) {
369 print "parent $par<br/>\n";
376 print "$comment<br/><br/>\n";
382 } elsif ($action eq "commit") {
384 open my $fd, "-|", "$gitbin/cat-file", "commit", $hash;
385 while (my $line = <$fd>) {
388 if ($line =~ m/^parent (.*)$/ && $parent eq "") {
392 my $shortlog = <$fd>;
393 $shortlog = escapeHTML
($shortlog);
396 open $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash;
397 my (@difftree) = map { chomp; $_ } <$fd>;
401 print "<div class=\"main\">\n";
402 print "view " . $cgi->a({-href
=> "$myself/$project/treediff/$hash"}, "diff") . "<br/><br/><br/>\n";
403 print "$shortlog<br/>\n";
405 foreach my $line (@difftree) {
406 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
407 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
408 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
414 if ($type eq "blob") {
416 print "NEW\t" . $cgi->a({-href
=> "$myself/$project/blob/$id"}, $file) . "\n";
417 } elsif ($op eq "-") {
418 print "DEL\t" . $cgi->a({-href
=> "$myself/$project/blob/$id"}, $file) . "\n";
419 } elsif ($op eq "*") {
420 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
423 print "CHANGED\t" . $cgi->a({-href
=> "$myself/$project/diff/$old/$new"}, $file) . "\n";
430 } elsif ($action eq "diff") {
432 print "<br/><br/><div class=\"main\">\n";
434 git_diff
($hash, $hash_parent, $hash, $hash_parent);
438 } elsif ($action eq "treediff") {
440 open my $fd, "-|", "$gitbin/cat-file", "commit", $hash;
441 while (my $line = <$fd>) {
444 if ($line =~ m/^parent (.*)$/ && $parent eq "") {
448 my $shortlog = <$fd>;
449 $shortlog = escapeHTML
($shortlog);
452 open $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash;
453 my (@difftree) = map { chomp; $_ } <$fd>;
457 print "<div class=\"main\">\n";
458 print "view " . $cgi->a({-href
=> "$myself/$project/commit/$hash"}, "commit") . "<br/><br/><br/>\n";
459 print "$shortlog<br/>\n";
461 foreach my $line (@difftree) {
462 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
463 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
469 if ($type eq "blob") {
471 git_diff
("", $file, "", $id);
472 } elsif ($op eq "-") {
473 git_diff
($file, "", $id, "");
474 } elsif ($op eq "*") {
475 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
476 git_diff
($file, $file, $1, $2);
485 print "<br/><br/><div class=\"main\">\n";
486 print "unknown action\n";
This page took 0.652571 seconds and 3 git commands to generate.