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*2;
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.main { 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.head2 { padding:8px; }
42 td { padding:8px; margin:0px; font-family: sans-serif; font-size: 12px; }
43 td.head1 { background-color: #D9D8D1; font-weight:bold; }
44 td.head2 { background-color: #EDECE6; font-family: monospace; font-size:12px; }
45 table.log { padding:0px; margin:0px; width:100%; }
46 tr { vertical-align:top; }
48 a:hover { color:#880000; }
49 a:visited { color:#880000; }
50 a:active { color:#880000; }
56 print "<div class=\"main\">\n";
57 print "<div class=\"head1\">" . $project . "</div>\n";
58 print "<div class=\"head2\">\n";
59 print $cgi->a({-href
=> "$myself?project=$project&action=show_tree"}, "Browse Project") . "<br/>\n";
61 print $cgi->a({-href
=> "$myself?project=$project&action=show_log&view_back=" . 60*60*24}, "day") . "\n";
62 print $cgi->a({-href
=> "$myself?project=$project&action=show_log&view_back=" . 60*60*24*7}, "week") . "\n";
63 print $cgi->a({-href
=> "$myself?project=$project&action=show_log&view_back=" . 60*60*24*30}, "month") . "\n";
64 print $cgi->a({-href
=> "$myself?project=$project&action=show_log&view_back=" . 60*60*24*365}, "year") . "<br/>\n";
72 print $cgi->end_html();
76 open my $fd, "-|", "ls", "-1", $gitroot;
77 my (@path) = map { chomp; $_ } <$fd>;
80 print "Projects:<br/><br/>\n";
81 foreach my $line (@path) {
82 if (-e
"$gitroot/$line/.git/HEAD") {
83 print $cgi->a({-href
=> "$myself?project=$line"}, $line) . "<br/>\n";
91 print $cgi->redirect("$myself?project=$project&action=show_log&view_back=$view_back");
95 if ($action eq "show_file") {
98 open my $fd, "-|", "$gitbin/cat-file", "blob", $hash;
100 while (my $line = <$fd>) {
102 print "$nr\t" . escapeHTML
($line);;
107 } elsif ($action eq "show_tree") {
109 open my $fd, "$projectroot/.git/HEAD";
114 open $fd, "-|", "$gitbin/cat-file", "commit", $head;
121 open my $fd, "-|", "$gitbin/ls-tree", $hash;
122 my (@entries) = map { chomp; $_ } <$fd>;
126 foreach my $line (@entries) {
127 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
131 if ($t_type eq "blob") {
132 print "FILE\t" . $cgi->a({-href
=> "$myself?project=$project&action=show_file&hash=$3"}, $4) . "\n";
133 } elsif ($t_type eq "tree") {
134 print "DIR\t" . $cgi->a({-href
=> "$myself?project=$project&action=show_tree&hash=$3"}, $4) . "\n";
139 } elsif ($action eq "show_log") {
140 open my $fd, "$projectroot/.git/HEAD";
144 open my $fd, "-|", "$gitbin/rev-tree", $head;
145 my (@revtree) = map { chomp; $_ } <$fd>;
148 print "<table cellspacing=\"0\" class=\"log\">\n";
149 foreach my $rev (reverse sort @revtree) {
150 if (!($rev =~ m/^([0-9]+) ([0-9a-fA-F]+).* ([0-9a-fA-F]+)/)) {
163 my $committer_timezone;
167 open my $fd, "-|", "$gitbin/cat-file", "commit", $commit;
168 while (my $line = <$fd>) {
173 if ($line =~ m/^tree (.*)$/) {
175 } elsif ($line =~ m/^parent (.*)$/) {
177 } elsif ($line =~ m/^committer (.*>) ([0-9]+) (.*)$/) {
179 $committer_time = $2;
180 $committer_timezone = $3;
181 } elsif ($line =~ m/^author (.*>) ([0-9]+) (.*)$/) {
184 $author_timezone = $3;
185 $author =~ m/^(.*) </;
190 $shortlog = escapeHTML
($shortlog);
191 $comment = $shortlog . "<br/>";
192 while (my $line = <$fd>) {
194 $comment .= escapeHTML
($line) . "<br/>\n";
197 my $age = time-$author_time;
198 if ($view_back > 0 && $age > $view_back) {
203 if ($age > 60*60*24*365*2) {
204 $age_string = int $age/60/60/24/365;
205 $age_string .= " years ago";
206 } elsif ($age > 60*60*24*365/12*2) {
207 $age_string = int $age/60/60/24/365/12;
208 $age_string .= " months ago";
209 } elsif ($age > 60*60*24*7*2) {
210 $age_string = int $age/60/60/24/7;
211 $age_string .= " weeks ago";
212 } elsif ($age > 60*60*24*2) {
213 $age_string = int $age/60/60/24;
214 $age_string .= " days ago";
215 } elsif ($age > 60*60*2) {
216 $age_string = int $age/60/60;
217 $age_string .= " hours ago";
218 } elsif ($age > 60*2) {
219 $age_string = int $age/60;
220 $age_string .= " minutes ago";
223 print "<td class=\"head1\">" . $age_string . "</td>\n";
224 print "<td class=\"head1\"><a href=\"$myself?project=$project&action=show_cset&hash=$commit&parent=$parent\">" . $shortlog . "</a></td>";
227 print "<td class=\"head2\"></td>\n";
228 print "<td class=\"head2\">\n";
229 print "author " . escapeHTML
($author) . " [" . gmtime($author_time) . " " . $author_timezone . "]<br/>\n";
230 print "committer " . escapeHTML
($committer) . " [" . gmtime($committer_time) . " " . $committer_timezone . "]<br/>\n";
231 print "commit <a href=\"$myself?project=$project&action=show_cset&hash=$commit&parent=$parent\">$commit</a><br/>\n";
232 print "tree <a href=\"$myself?project=$project&action=show_tree&hash=$tree\">$tree</a><br/>\n";
233 foreach my $par (@parents) {
234 print "parent $par<br/>\n";
241 print "$comment<br/><br/>\n";
247 } elsif ($action eq "show_cset") {
248 open my $fd, "-|", "$gitbin/cat-file", "commit", $hash;
254 open my $fd, "-|", "$gitbin/cat-file", "commit", $parent;
255 my $parent_tree = <$fd>;
257 $parent_tree =~ s/tree //;
260 open my $fd, "-|", "$gitbin/diff-tree", "-r", $parent_tree, $tree;
261 my (@difftree) = map { chomp; $_ } <$fd>;
266 foreach my $line (@difftree) {
267 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
273 if ($type eq "blob") {
275 print "NEW\t" . $cgi->a({-href
=> "$myself?project=$project&action=show_file&hash=$id"}, $file) . "\n";
276 } elsif ($op eq "-") {
277 print "DEL\t" . $cgi->a({-href
=> "$myself?project=$project&action=show_file&hash=$id"}, $file) . "\n";
278 } elsif ($op eq "*") {
279 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
282 print "DIFF\t" . $cgi->a({-href
=> "$myself?project=$project&action=show_diff&hash=$old&parent=$new"}, $file) . "\n";
288 } elsif ($action eq "show_diff") {
289 open my $fd2, "> $gittmp/$hash";
290 open my $fd, "-|", "$gitbin/cat-file", "blob", $hash;
291 while (my $line = <$fd>) {
297 open my $fd2, "> $gittmp/$parent";
298 open my $fd, "-|", "$gitbin/cat-file", "blob", $parent;
299 while (my $line = <$fd>) {
307 open my $fd, "-|", "/usr/bin/diff", "-L", "$hash", "-L", "$parent", "-u", "-p", "$gittmp/$hash", "$gittmp/$parent";
308 while (my $line = <$fd>) {
309 print escapeHTML
($line);
312 unlink("$gittmp/$hash");
313 unlink("$gittmp/$parent");
318 print "unknown action\n";