3 # This file is licensed under the GPL v2, or a later version
4 # (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
5 # (C) 2005, Christian Gierke <ch@gierke.de>
9 use CGI qw(:standard :escapeHTML);
10 use CGI::Carp qw(fatalsToBrowser);
13 my $gitbin = "/home/kay/bin";
14 my $gitroot = "/home/kay/public_html";
16 my $myself = $cgi->url(-relative => 1);
18 my $project = $cgi->param("project") || "";
19 my $action = $cgi->param("action") || "";
20 my $hash = $cgi->param("hash") || "";
21 my $parent = $cgi->param("parent") || "";
22 my $view_back = $cgi->param("view_back") || 60*60*24;
23 my $projectroot = "$gitroot/$project";
24 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/.git/objects";
26 $hash =~ s/[^0-9a-fA-F]//g;
27 $parent =~ s/[^0-9a-fA-F]//g;
28 $project =~ s/[^0-9a-zA-Z\-\._]//g;
31 print $cgi->header(-type => 'text/html; charset: utf-8');
33 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
37 <style type="text/css">
38 body { font-family: sans-serif; font-size: 12px; margin:25px; }
39 div.body { border-width:1px; border-style:solid; border-color:#D9D8D1; }
40 div.head1 { font-size:20px; padding:8px; background-color: #D9D8D1; font-weight:bold; }
41 div.head1 a:visited { color:#0000cc; }
42 div.head1 a:hover { color:#880000; }
43 div.head1 a:active { color:#880000; }
44 div.head2 { padding:8px; }
45 div.head2 a:visited { color:#0000cc; }
46 div.head2 a:hover { color:#880000; }
47 div.head2 a:active { color:#880000; }
48 div.main { padding:8px; font-family: sans-serif; font-size: 12px; }
49 table { padding:0px; margin:0px; width:100%; }
50 tr { vertical-align:top; }
51 td { padding:8px; margin:0px; font-family: sans-serif; font-size: 12px; }
52 td.head1 { background-color: #D9D8D1; font-weight:bold; }
53 td.head1 a { color:#000000; text-decoration:none; }
54 td.head1 a:hover { color:#880000; text-decoration:underline; }
55 td.head1 a:visited { color:#000000; }
56 td.head2 { background-color: #EDECE6; font-family: monospace; font-size:12px; }
57 td.head3 { background-color: #EDECE6; font-size:10px; }
58 div.add { color: #008800; }
59 div.subtract { color: #CC0000; }
60 div.diff_head { color: #990099; }
62 a:hover { color:#880000; }
63 a:visited { color:#880000; }
64 a:active { color:#880000; }
69 print "<div class=\"body\">\n";
70 print "<div class=\"head1\">";
71 print "<a href=\"http://kernel.org/pub/software/scm/git/\"><img src=\"git_logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
72 print $cgi->a({-href => "$myself"}, "projects");
74 print " / " . $cgi->a({-href => "$myself?project=$project&action=log&view_back=" . 60*60*24}, $project);
77 print " / " . $action . " " . $hash;
84 print $cgi->end_html();
93 my $label_old = "/dev/null";
94 my $label_new = "/dev/null";
95 my $tmp_old = "/dev/null";
96 my $tmp_new = "/dev/null";
99 open my $fd2, "> $gittmp/$old";
100 open my $fd, "-|", "$gitbin/cat-file", "blob", $old;
101 while (my $line = <$fd>) {
106 $tmp_old = "$gittmp/$old";
107 $label_old = "a/$old_name";
111 open my $fd2, "> $gittmp/$new";
112 open my $fd, "-|", "$gitbin/cat-file", "blob", $new;
113 while (my $line = <$fd>) {
118 $tmp_new = "$gittmp/$new";
119 $label_new = "b/$new_name";
122 open my $fd, "-|", "/usr/bin/diff", "-L", $label_old, "-L", $label_new, "-u", "-p", $tmp_old, $tmp_new;
123 while (my $line = <$fd>) {
124 my $char = substr($line,0,1);
125 print '<div class="add">' if $char eq '+';
126 print '<div class="subtract">' if $char eq '-';
127 print '<div class="diff_head">' if $char eq '@';
128 print escapeHTML($line);
129 print '</div>' if $char eq '+' or $char eq '-' or $char eq '@';
132 #unlink("$gittmp/$new");
133 #unlink("$gittmp/$old");
136 if ($project eq "") {
137 open my $fd, "-|", "ls", "-1", $gitroot;
138 my (@path) = map { chomp; $_ } <$fd>;
141 print "<br/><br/><div class=\"main\">\n";
142 foreach my $line (@path) {
143 if (-e "$gitroot/$line/.git/HEAD") {
144 print $cgi->a({-href => "$myself?project=$line"}, $line) . "<br/>\n";
153 print $cgi->redirect("$myself?project=$project&action=log&view_back=$view_back");
157 if ($action eq "file") {
159 print "<br/><br/><div class=\"main\">\n";
161 open my $fd, "-|", "$gitbin/cat-file", "blob", $hash;
163 while (my $line = <$fd>) {
165 print "$nr\t" . escapeHTML($line);;
171 } elsif ($action eq "tree") {
173 open my $fd, "$projectroot/.git/HEAD";
177 open $fd, "-|", "$gitbin/cat-file", "commit", $head;
184 open my $fd, "-|", "$gitbin/ls-tree", $hash;
185 my (@entries) = map { chomp; $_ } <$fd>;
188 print "<br/><br/><div class=\"main\">\n";
190 foreach my $line (@entries) {
191 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
195 if ($t_type eq "blob") {
196 print "FILE\t" . $cgi->a({-href => "$myself?project=$project&action=file&hash=$3"}, $4) . "\n";
197 } elsif ($t_type eq "tree") {
198 print "DIR\t" . $cgi->a({-href => "$myself?project=$project&action=tree&hash=$3"}, $4) . "\n";
204 } elsif ($action eq "log" || $action eq "show_log" ) {
205 open my $fd, "$projectroot/.git/HEAD";
209 open $fd, "-|", "$gitbin/rev-tree", $head;
210 my (@revtree) = map { chomp; $_ } <$fd>;
213 print "<div class=\"head2\">\n";
215 print $cgi->a({-href => "$myself?project=$project&action=log&view_back=" . 60*60*24}, "last day") . " | ";
216 print $cgi->a({-href => "$myself?project=$project&action=log&view_back=" . 60*60*24*7}, "week") . " | ";
217 print $cgi->a({-href => "$myself?project=$project&action=log&view_back=" . 60*60*24*30}, "month") . " | ";
218 print $cgi->a({-href => "$myself?project=$project&action=log&view_back=" . 60*60*24*365}, "year") . " | ";
219 print $cgi->a({-href => "$myself?project=$project&action=log&view_back=-1"}, "all") . "<br/>\n";
220 print "<br/><br/>\n";
222 print "<table cellspacing=\"0\" class=\"log\">\n";
223 foreach my $rev (reverse sort @revtree) {
224 if (!($rev =~ m/^([0-9]+) ([0-9a-fA-F]+).* ([0-9a-fA-F]+)/)) {
237 my $committer_timezone;
241 open my $fd, "-|", "$gitbin/cat-file", "commit", $commit;
242 while (my $line = <$fd>) {
247 if ($line =~ m/^tree (.*)$/) {
249 } elsif ($line =~ m/^parent (.*)$/) {
251 } elsif ($line =~ m/^committer (.*>) ([0-9]+) (.*)$/) {
253 $committer_time = $2;
254 $committer_timezone = $3;
255 } elsif ($line =~ m/^author (.*>) ([0-9]+) (.*)$/) {
258 $author_timezone = $3;
259 $author =~ m/^(.*) </;
264 $shortlog = escapeHTML($shortlog);
265 $comment = $shortlog . "<br/>";
266 while (my $line = <$fd>) {
268 $comment .= escapeHTML($line) . "<br/>\n";
271 my $age = time-$author_time;
272 if ($view_back > 0 && $age > $view_back) {
277 if ($age > 60*60*24*365*2) {
278 $age_string = int $age/60/60/24/365;
279 $age_string .= " years ago";
280 } elsif ($age > 60*60*24*365/12*2) {
281 $age_string = int $age/60/60/24/365/12;
282 $age_string .= " months ago";
283 } elsif ($age > 60*60*24*7*2) {
284 $age_string = int $age/60/60/24/7;
285 $age_string .= " weeks ago";
286 } elsif ($age > 60*60*24*2) {
287 $age_string = int $age/60/60/24;
288 $age_string .= " days ago";
289 } elsif ($age > 60*60*2) {
290 $age_string = int $age/60/60;
291 $age_string .= " hours ago";
292 } elsif ($age > 60*2) {
293 $age_string = int $age/60;
294 $age_string .= " minutes ago";
297 print "<td class=\"head1\">" . $age_string . "</td>\n";
298 print "<td class=\"head1\"><a href=\"$myself?project=$project&action=commit&hash=$commit&parent=$parent\">" . $shortlog . "</a></td>";
301 print "<td class=\"head3\">";
302 print $cgi->a({-href => "$myself?project=$project&action=diffs&hash=$commit&parent=$parent"}, "view diff") . "<br/>\n";
303 print $cgi->a({-href => "$myself?project=$project&action=commit&hash=$commit&parent=$parent"}, "view commit") . "<br/>\n";
304 print $cgi->a({-href => "$myself?project=$project&action=tree&hash=$tree"}, "view tree") . "<br/>\n";
306 print "<td class=\"head2\">\n";
307 print "author " . escapeHTML($author) . " [" . gmtime($author_time) . " " . $author_timezone . "]<br/>\n";
308 print "committer " . escapeHTML($committer) . " [" . gmtime($committer_time) . " " . $committer_timezone . "]<br/>\n";
309 print "commit $commit<br/>\n";
310 print "tree $tree<br/>\n";
311 foreach my $par (@parents) {
312 print "parent $par<br/>\n";
319 print "$comment<br/><br/>\n";
325 } elsif ($action eq "commit") {
326 open my $fd, "-|", "$gitbin/cat-file", "commit", $hash;
332 open $fd, "-|", "$gitbin/cat-file", "commit", $parent;
333 my $parent_tree = <$fd>;
335 $parent_tree =~ s/tree //;
338 open $fd, "-|", "$gitbin/diff-tree", "-r", $parent_tree, $tree;
339 my (@difftree) = map { chomp; $_ } <$fd>;
343 print "<br/><br/><div class=\"main\">\n";
345 foreach my $line (@difftree) {
346 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
352 if ($type eq "blob") {
354 print "NEW\t" . $cgi->a({-href => "$myself?project=$project&action=file&hash=$id"}, $file) . "\n";
355 } elsif ($op eq "-") {
356 print "DEL\t" . $cgi->a({-href => "$myself?project=$project&action=file&hash=$id"}, $file) . "\n";
357 } elsif ($op eq "*") {
358 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
361 print "DIFF\t" . $cgi->a({-href => "$myself?project=$project&action=diff&hash=$old&parent=$new"}, $file) . "\n";
368 } elsif ($action eq "diff") {
370 print "<br/><br/><div class=\"main\">\n";
372 git_diff($hash, $parent, $hash, $parent);
376 } elsif ($action eq "diffs") {
377 open my $fd, "-|", "$gitbin/cat-file", "commit", $hash;
383 open $fd, "-|", "$gitbin/cat-file", "commit", $parent;
384 my $parent_tree = <$fd>;
386 $parent_tree =~ s/tree //;
389 open $fd, "-|", "$gitbin/diff-tree", "-r", $parent_tree, $tree;
390 my (@difftree) = map { chomp; $_ } <$fd>;
394 print "<br/><br/><div class=\"main\">\n";
396 foreach my $line (@difftree) {
397 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
403 if ($type eq "blob") {
405 git_diff("", $file, "", $id);
406 } elsif ($op eq "-") {
407 git_diff($file, "", $id, "");
408 } elsif ($op eq "*") {
409 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
410 git_diff($file, $file, $1, $2);
421 print "<br/><br/><div class=\"main\">\n";
422 print "unknown action\n";