]>
Commit | Line | Data |
---|---|---|
161332a5 KS |
1 | #!/usr/bin/perl |
2 | ||
22fafb99 KS |
3 | # gitweb.pl - simple web interface to track changes in git repositories |
4 | # | |
e334d18c | 5 | # Version 021 |
22fafb99 | 6 | # |
161332a5 KS |
7 | # (C) 2005, Kay Sievers <kay.sievers@vrfy.org> |
8 | # (C) 2005, Christian Gierke <ch@gierke.de> | |
823d5dc8 KS |
9 | # |
10 | # This file is licensed under the GPL v2, or a later version | |
161332a5 KS |
11 | |
12 | use strict; | |
13 | use warnings; | |
14 | use CGI qw(:standard :escapeHTML); | |
15 | use CGI::Carp qw(fatalsToBrowser); | |
16 | ||
a7e09a96 KS |
17 | my $projectroot = "/home/kay/public_html"; |
18 | my $defaultprojects = "."; | |
19 | my $gitbin = "/home/kay/bin/git"; | |
20 | my $gittmp = "/tmp"; | |
44ad2978 | 21 | |
161332a5 | 22 | my $cgi = new CGI; |
44ad2978 KS |
23 | my $project = ""; |
24 | my $action = ""; | |
25 | my $hash = ""; | |
26 | my $hash_parent = ""; | |
27 | my $view_back; | |
28 | my $myself = $cgi->url(-absolute => 1); | |
1b143380 KS |
29 | my $url_parm = $cgi->url(-path => 1); |
30 | $url_parm =~ s/.*$myself//; | |
161332a5 | 31 | |
44ad2978 | 32 | # get values from url |
a7e09a96 | 33 | if ($url_parm =~ m#/(.+)/commit/([0-9a-fA-F]+)$#) { |
52ccdd40 KS |
34 | $project = $1; |
35 | $action = "commit"; | |
36 | $hash = $2; | |
e334d18c | 37 | } elsif ($url_parm =~ m#/(.+)/commitdiff/([0-9a-fA-F]+)$#) { |
52ccdd40 | 38 | $project = $1; |
e334d18c | 39 | $action = "commitdiff"; |
52ccdd40 | 40 | $hash = $2; |
e334d18c | 41 | } elsif ($url_parm =~ m#/(.+)/blobdiff/([0-9a-fA-F]+)/([0-9a-fA-F]+)$#) { |
52ccdd40 | 42 | $project = $1; |
e334d18c | 43 | $action = "blobdiff"; |
52ccdd40 KS |
44 | $hash = $2; |
45 | $hash_parent = $3; | |
a7e09a96 | 46 | } elsif ($url_parm =~ m#/(.+)/blob/([0-9a-fA-F]+)$#) { |
44ad2978 KS |
47 | $project = $1; |
48 | $action = "blob"; | |
49 | $hash = $2; | |
a7e09a96 | 50 | } elsif ($url_parm =~ m#/(.+)/tree/([0-9a-fA-F]+)$#) { |
44ad2978 KS |
51 | $project = $1; |
52 | $action = "tree"; | |
53 | $hash = $2; | |
a7e09a96 | 54 | } elsif ($url_parm =~ m#/(.+)/log/([0-9]+)$#) { |
52ccdd40 KS |
55 | $project = $1; |
56 | $action = "log"; | |
57 | $view_back = $2; | |
a7e09a96 | 58 | } elsif ($url_parm =~ m#/(.+)/log$#) { |
52ccdd40 KS |
59 | $project = $1; |
60 | $action = "log"; | |
44ad2978 | 61 | $view_back = 1; |
e334d18c KS |
62 | } elsif ($url_parm =~ m#/(.+)/rss$#) { |
63 | $project = $1; | |
64 | $action = "rss"; | |
65 | $view_back = 1; | |
1b143380 | 66 | } elsif ($url_parm =~ m#/git-logo.png$#) { |
44ad2978 KS |
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"; | |
81 | exit; | |
a7e09a96 | 82 | } elsif ($url_parm =~ m#/(.+)$#) { |
1b143380 KS |
83 | $project = $1; |
84 | $action = "log"; | |
85 | $view_back = 1; | |
52ccdd40 | 86 | } |
52ccdd40 | 87 | |
44ad2978 | 88 | # sanitize input |
a7e09a96 | 89 | $project =~ s#\/\.+##g; |
161332a5 | 90 | |
a7e09a96 | 91 | $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/.git/objects"; |
823d5dc8 | 92 | |
12a88f2f | 93 | sub git_header_html { |
161332a5 KS |
94 | print $cgi->header(-type => 'text/html; charset: utf-8'); |
95 | print <<EOF; | |
96 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
97 | <html> | |
98 | <head> | |
ecb378f5 | 99 | <title>git - $project $action</title> |
e334d18c | 100 | <link rel="alternate" title="$project log" href="$myself/$project/rss" type="application/rss+xml"> |
161332a5 KS |
101 | <style type="text/css"> |
102 | body { font-family: sans-serif; font-size: 12px; margin:25px; } | |
4c02e3c5 | 103 | div.body { border-width:1px; border-style:solid; border-color:#D9D8D1; } |
161332a5 | 104 | div.head1 { font-size:20px; padding:8px; background-color: #D9D8D1; font-weight:bold; } |
4c02e3c5 KS |
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; } | |
3f714537 | 112 | div.title { padding:8px; background-color: #D9D8D1; font-weight:bold; } |
4c02e3c5 KS |
113 | table { padding:0px; margin:0px; width:100%; } |
114 | tr { vertical-align:top; } | |
161332a5 KS |
115 | td { padding:8px; margin:0px; font-family: sans-serif; font-size: 12px; } |
116 | td.head1 { background-color: #D9D8D1; font-weight:bold; } | |
4c02e3c5 KS |
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; } | |
161332a5 | 120 | td.head2 { background-color: #EDECE6; font-family: monospace; font-size:12px; } |
4c02e3c5 | 121 | td.head3 { background-color: #EDECE6; font-size:10px; } |
1b143380 | 122 | div.signed_off { color: #a9a8a1; } |
4c02e3c5 KS |
123 | a { color:#0000cc; } |
124 | a:hover { color:#880000; } | |
125 | a:visited { color:#880000; } | |
126 | a:active { color:#880000; } | |
e334d18c | 127 | pre { padding:8px; } |
161332a5 KS |
128 | </style> |
129 | </head> | |
130 | <body> | |
131 | EOF | |
4c02e3c5 KS |
132 | print "<div class=\"body\">\n"; |
133 | print "<div class=\"head1\">"; | |
44ad2978 | 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>"; |
a7e09a96 KS |
135 | if ($defaultprojects ne "") { |
136 | print $cgi->a({-href => "$myself"}, "projects") . " / "; | |
137 | } | |
161332a5 | 138 | if ($project ne "") { |
a7e09a96 | 139 | print $cgi->a({-href => "$myself/$project/log"}, $project); |
161332a5 | 140 | } |
4c02e3c5 | 141 | if ($action ne "") { |
ecb378f5 | 142 | print " / $action"; |
4c02e3c5 KS |
143 | } |
144 | print "</div>\n"; | |
161332a5 KS |
145 | } |
146 | ||
12a88f2f | 147 | sub git_footer_html { |
161332a5 KS |
148 | print "</div>"; |
149 | print $cgi->end_html(); | |
150 | } | |
151 | ||
12a88f2f KS |
152 | sub git_head { |
153 | open my $fd, "$projectroot/$project/.git/HEAD"; | |
154 | my $head = <$fd>; | |
155 | close $fd; | |
156 | chomp $head; | |
157 | return $head; | |
158 | } | |
159 | ||
703ac710 KS |
160 | sub git_commit { |
161 | my $commit = shift; | |
162 | my %co; | |
163 | my @parents; | |
164 | ||
165 | open my $fd, "-|", "$gitbin/cat-file", "commit", $commit; | |
166 | while (my $line = <$fd>) { | |
167 | chomp($line); | |
168 | last if $line eq ""; | |
169 | if ($line =~ m/^tree (.*)$/) { | |
170 | $co{'tree'} = $1; | |
171 | } elsif ($line =~ m/^parent (.*)$/) { | |
172 | push @parents, $1; | |
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]+) (.*)$/) { | |
3f714537 KS |
178 | $co{'author'} = $1; |
179 | $co{'author_time'} = $2; | |
180 | $co{'author_timezone'} = $3; | |
703ac710 KS |
181 | } |
182 | } | |
3f714537 KS |
183 | $co{'parents'} = \@parents; |
184 | my (@comment) = map { chomp; $_ } <$fd>; | |
185 | $co{'comment'} = \@comment; | |
186 | $co{'title'} = $comment[0]; | |
703ac710 | 187 | close $fd; |
703ac710 KS |
188 | return %co; |
189 | } | |
190 | ||
4c02e3c5 | 191 | sub git_diff { |
c068cff1 KS |
192 | my $old_name = shift || "/dev/null"; |
193 | my $new_name = shift || "/dev/null"; | |
4c02e3c5 KS |
194 | my $old = shift; |
195 | my $new = shift; | |
196 | ||
4c02e3c5 KS |
197 | my $tmp_old = "/dev/null"; |
198 | my $tmp_new = "/dev/null"; | |
c068cff1 KS |
199 | my $old_label = "/dev/null"; |
200 | my $new_label = "/dev/null"; | |
4c02e3c5 | 201 | |
b531daf3 | 202 | # create temp from-file |
4c02e3c5 KS |
203 | if ($old ne "") { |
204 | open my $fd2, "> $gittmp/$old"; | |
205 | open my $fd, "-|", "$gitbin/cat-file", "blob", $old; | |
206 | while (my $line = <$fd>) { | |
207 | print $fd2 $line; | |
208 | } | |
209 | close $fd2; | |
210 | close $fd; | |
211 | $tmp_old = "$gittmp/$old"; | |
c068cff1 | 212 | $old_label = "a/$old_name"; |
4c02e3c5 KS |
213 | } |
214 | ||
b531daf3 | 215 | # create tmp to-file |
4c02e3c5 KS |
216 | if ($new ne "") { |
217 | open my $fd2, "> $gittmp/$new"; | |
218 | open my $fd, "-|", "$gitbin/cat-file", "blob", $new; | |
219 | while (my $line = <$fd>) { | |
220 | print $fd2 $line; | |
221 | } | |
222 | close $fd2; | |
223 | close $fd; | |
224 | $tmp_new = "$gittmp/$new"; | |
adf3ee8e | 225 | $new_label = "b/$new_name"; |
4c02e3c5 KS |
226 | } |
227 | ||
c068cff1 | 228 | open my $fd, "-|", "/usr/bin/diff", "-L", $old_label, "-L", $new_label, "-u", "-p", $tmp_old, $tmp_new; |
1b143380 | 229 | print "<span style =\"color: #000099;\">===== "; |
c068cff1 | 230 | if ($old ne "") { |
44ad2978 | 231 | print $cgi->a({-href => "$myself/$project/blob/$old"}, $old); |
c068cff1 KS |
232 | } else { |
233 | print $old_name; | |
234 | } | |
235 | print " vs "; | |
236 | if ($new ne "") { | |
44ad2978 | 237 | print $cgi->a({-href => "$myself/$project/blob/$new"}, $new); |
c068cff1 KS |
238 | } else { |
239 | print $new_name; | |
240 | } | |
1b143380 | 241 | print " =====</span>\n"; |
4c02e3c5 KS |
242 | while (my $line = <$fd>) { |
243 | my $char = substr($line,0,1); | |
1b143380 KS |
244 | print '<span style ="color: #008800;">' if $char eq '+'; |
245 | print '<span style ="color: #CC0000;">' if $char eq '-'; | |
246 | print '<span style ="color: #990099;">' if $char eq '@'; | |
4c02e3c5 | 247 | print escapeHTML($line); |
1b143380 | 248 | print '</span>' if $char eq '+' or $char eq '-' or $char eq '@'; |
4c02e3c5 KS |
249 | } |
250 | close $fd; | |
c068cff1 KS |
251 | unlink("$gittmp/$new"); |
252 | unlink("$gittmp/$old"); | |
4c02e3c5 KS |
253 | } |
254 | ||
161332a5 | 255 | if ($project eq "") { |
a7e09a96 | 256 | opendir(my $fd, "$projectroot/$defaultprojects"); |
44ad2978 KS |
257 | my (@path) = grep(!/^\./, readdir($fd)); |
258 | closedir($fd); | |
12a88f2f | 259 | git_header_html(); |
e334d18c KS |
260 | print "<div class=\"head2\">\n"; |
261 | print "<br/><br/>\n"; | |
161332a5 | 262 | foreach my $line (@path) { |
a7e09a96 KS |
263 | if (-e "$projectroot/$defaultprojects/$line/.git/HEAD") { |
264 | print $cgi->a({-href => "$myself/$defaultprojects/$line/log"}, $line) . "<br/>\n"; | |
161332a5 KS |
265 | } |
266 | } | |
e334d18c | 267 | print "</div><br/>"; |
12a88f2f | 268 | git_footer_html(); |
161332a5 KS |
269 | exit; |
270 | } | |
271 | ||
ecb378f5 | 272 | if ($action eq "blob") { |
12a88f2f | 273 | git_header_html(); |
e334d18c | 274 | print "<br/><br/>\n"; |
161332a5 KS |
275 | print "<pre>\n"; |
276 | open my $fd, "-|", "$gitbin/cat-file", "blob", $hash; | |
277 | my $nr; | |
278 | while (my $line = <$fd>) { | |
279 | $nr++; | |
280 | print "$nr\t" . escapeHTML($line);; | |
281 | } | |
282 | close $fd; | |
283 | print "</pre>\n"; | |
e334d18c | 284 | print "<br/>"; |
12a88f2f | 285 | git_footer_html(); |
4c02e3c5 | 286 | } elsif ($action eq "tree") { |
161332a5 | 287 | if ($hash eq "") { |
12a88f2f | 288 | $hash = git_head(); |
161332a5 KS |
289 | } |
290 | open my $fd, "-|", "$gitbin/ls-tree", $hash; | |
291 | my (@entries) = map { chomp; $_ } <$fd>; | |
292 | close $fd; | |
12a88f2f | 293 | git_header_html(); |
e334d18c | 294 | print "<br/><br/>\n"; |
161332a5 KS |
295 | print "<pre>\n"; |
296 | foreach my $line (@entries) { | |
c068cff1 | 297 | #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' |
161332a5 KS |
298 | $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/; |
299 | my $t_type = $2; | |
300 | my $t_hash = $3; | |
301 | my $t_name = $4; | |
302 | if ($t_type eq "blob") { | |
44ad2978 | 303 | print "BLOB\t" . $cgi->a({-href => "$myself/$project/blob/$3"}, $4) . "\n"; |
161332a5 | 304 | } elsif ($t_type eq "tree") { |
44ad2978 | 305 | print "TREE\t" . $cgi->a({-href => "$myself/$project/tree/$3"}, $4) . "\n"; |
161332a5 KS |
306 | } |
307 | } | |
308 | print "</pre>\n"; | |
e334d18c | 309 | print "<br/>"; |
12a88f2f | 310 | git_footer_html(); |
e334d18c | 311 | } elsif ($action eq "log" || $action eq "rss") { |
12a88f2f | 312 | open my $fd, "-|", "$gitbin/rev-tree", git_head(); |
a7e09a96 | 313 | my (@revtree) = reverse sort map { chomp; $_ } <$fd>; |
161332a5 | 314 | close $fd; |
e334d18c KS |
315 | |
316 | if ($action eq "log") { | |
12a88f2f | 317 | git_header_html(); |
e334d18c KS |
318 | print "<div class=\"head2\">\n"; |
319 | print "view "; | |
320 | print $cgi->a({-href => "$myself/$project/log"}, "last day") . " | "; | |
321 | print $cgi->a({-href => "$myself/$project/log/7"}, "week") . " | "; | |
322 | print $cgi->a({-href => "$myself/$project/log/31"}, "month") . " | "; | |
323 | print $cgi->a({-href => "$myself/$project/log/365"}, "year") . " | "; | |
324 | print $cgi->a({-href => "$myself/$project/log/0"}, "all") . "<br/>\n"; | |
325 | print "<br/><br/>\n"; | |
326 | print "</div>\n"; | |
327 | print "<table cellspacing=\"0\" class=\"log\">\n"; | |
328 | } elsif ($action eq "rss") { | |
329 | print $cgi->header(-type => 'text/xml; charset: utf-8'); | |
330 | print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n". | |
331 | "<rss version=\"0.91\">\n"; | |
332 | print "<channel>\n"; | |
333 | print "<title>$project</title>\n". | |
334 | "<link> " . $cgi->url() . "/$project/log</link>\n". | |
335 | "<description>$project log</description>\n". | |
336 | "<language>en</language>\n"; | |
337 | } | |
338 | ||
a7e09a96 KS |
339 | for (my $i = 0; $i <= $#revtree; $i++) { |
340 | my $rev = $revtree[$i]; | |
e334d18c | 341 | #foreach my $rev (@revtree) { |
22fafb99 | 342 | # '1114106118 755e3010ee10dadf42a8a80770e1b115fb038d9b:1 2af17b4854036a1c2ec6c101d93c8dd1ed80d24e:1' |
b531daf3 | 343 | last if !($rev =~ m/^([0-9]+) ([0-9a-fA-F]+).* ([0-9a-fA-F]+)/); |
161332a5 KS |
344 | my $time = $1; |
345 | my $commit = $2; | |
346 | my $parent = $3; | |
161332a5 | 347 | |
3f714537 KS |
348 | my %co = git_commit($commit); |
349 | my $age = time - $co{'committer_time'}; | |
161332a5 KS |
350 | my $age_string; |
351 | if ($age > 60*60*24*365*2) { | |
352 | $age_string = int $age/60/60/24/365; | |
353 | $age_string .= " years ago"; | |
354 | } elsif ($age > 60*60*24*365/12*2) { | |
355 | $age_string = int $age/60/60/24/365/12; | |
356 | $age_string .= " months ago"; | |
357 | } elsif ($age > 60*60*24*7*2) { | |
358 | $age_string = int $age/60/60/24/7; | |
359 | $age_string .= " weeks ago"; | |
360 | } elsif ($age > 60*60*24*2) { | |
361 | $age_string = int $age/60/60/24; | |
362 | $age_string .= " days ago"; | |
363 | } elsif ($age > 60*60*2) { | |
364 | $age_string = int $age/60/60; | |
365 | $age_string .= " hours ago"; | |
366 | } elsif ($age > 60*2) { | |
367 | $age_string = int $age/60; | |
368 | $age_string .= " minutes ago"; | |
369 | } | |
e334d18c KS |
370 | if ($action eq "log") { |
371 | if ($view_back > 0 && $age > $view_back*60*60*24) { | |
372 | if ($i == 0) { | |
373 | print "<tr>\n"; | |
374 | print "<td class=\"head1\"> Last change $age_string. </td>\n"; | |
375 | print "</tr>\n"; | |
376 | } | |
377 | last; | |
378 | } | |
a7e09a96 | 379 | print "<tr>\n"; |
e334d18c | 380 | print "<td class=\"head1\">" . $age_string . "</td>\n"; |
3f714537 | 381 | print "<td class=\"head1\">" . $cgi->a({-href => "$myself/$project/commit/$commit"}, $co{'title'}) . "</td>"; |
a7e09a96 | 382 | print "</tr>\n"; |
e334d18c KS |
383 | print "<tr>\n"; |
384 | print "<td class=\"head3\">"; | |
385 | print $cgi->a({-href => "$myself/$project/commitdiff/$commit"}, "view diff") . "<br/>\n"; | |
386 | print $cgi->a({-href => "$myself/$project/commit/$commit"}, "view commit") . "<br/>\n"; | |
3f714537 | 387 | print $cgi->a({-href => "$myself/$project/tree/$co{'tree'}"}, "view tree") . "<br/>\n"; |
e334d18c KS |
388 | print "</td>\n"; |
389 | print "<td class=\"head2\">\n"; | |
3f714537 KS |
390 | print "author " . escapeHTML($co{'author'}) . " [" . gmtime($co{'author_time'}) . " " . $co{'author_timezone'} . "]<br/>\n"; |
391 | print "committer " . escapeHTML($co{'committer'}) . " [" . gmtime($co{'committer_time'}) . " " . $co{'committer_timezone'} . "]<br/>\n"; | |
e334d18c | 392 | print "commit $commit<br/>\n"; |
3f714537 KS |
393 | print "tree $co{'tree'}<br/>\n"; |
394 | my $parents = $co{'parents'}; | |
395 | foreach my $par (@$parents) { | |
e334d18c KS |
396 | print "parent $par<br/>\n"; |
397 | } | |
398 | print "</td>"; | |
399 | print "</tr>\n"; | |
400 | print "<tr>\n"; | |
401 | print "<td></td>\n"; | |
402 | print "<td>\n"; | |
3f714537 KS |
403 | my $comment = $co{'comment'}; |
404 | foreach my $line (@$comment) { | |
405 | if ($line =~ m/signed-off-by:/i) { | |
406 | print '<div class="signed_off">' . escapeHTML($line) . "<br/></div>\n"; | |
407 | } else { | |
408 | print escapeHTML($line) . "<br/>\n"; | |
409 | } | |
410 | } | |
411 | print "<br/><br/>\n"; | |
e334d18c KS |
412 | print "</td>"; |
413 | print "</tr>\n"; | |
414 | } elsif ($action eq "rss") { | |
703ac710 | 415 | last if ($i >= 12); |
3f714537 | 416 | print "<item>\n\t<title>$age_string: " . escapeHTML($co{'title'}) . "</title>\n"; |
703ac710 KS |
417 | print "\t<link> " . $cgi->url() . "/$project/commit/$commit</link>\n"; |
418 | print "</item>\n"; | |
161332a5 | 419 | } |
161332a5 | 420 | } |
e334d18c KS |
421 | if ($action eq "log") { |
422 | print "</table>\n"; | |
12a88f2f | 423 | git_footer_html(); |
e334d18c KS |
424 | } elsif ($action eq "rss") { |
425 | print "</channel></rss>"; | |
426 | } | |
4c02e3c5 | 427 | } elsif ($action eq "commit") { |
823d5dc8 KS |
428 | my $parent = ""; |
429 | open my $fd, "-|", "$gitbin/cat-file", "commit", $hash; | |
430 | while (my $line = <$fd>) { | |
431 | chomp($line); | |
432 | last if $line eq ""; | |
433 | if ($line =~ m/^parent (.*)$/ && $parent eq "") { | |
434 | $parent = $1; | |
435 | } | |
436 | } | |
3f714537 KS |
437 | my $title = <$fd>; |
438 | $title = escapeHTML($title); | |
823d5dc8 KS |
439 | close $fd; |
440 | ||
441 | open $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash; | |
161332a5 KS |
442 | my (@difftree) = map { chomp; $_ } <$fd>; |
443 | close $fd; | |
444 | ||
12a88f2f | 445 | git_header_html(); |
e334d18c KS |
446 | print "<div class=\"head2\">\n"; |
447 | print "view " . $cgi->a({-href => "$myself/$project/commitdiff/$hash"}, "diff") . "</div><br/><br/>\n"; | |
3f714537 | 448 | print "<div class=\"title\">$title<br/></div>\n"; |
161332a5 KS |
449 | print "<pre>\n"; |
450 | foreach my $line (@difftree) { | |
c068cff1 KS |
451 | # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c' |
452 | # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h' | |
161332a5 KS |
453 | $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/; |
454 | my $op = $1; | |
455 | my $mode = $2; | |
456 | my $type = $3; | |
457 | my $id = $4; | |
458 | my $file = $5; | |
459 | if ($type eq "blob") { | |
460 | if ($op eq "+") { | |
1b143380 | 461 | print "added\t" . $cgi->a({-href => "$myself/$project/blob/$id"}, $file) . "\n"; |
161332a5 | 462 | } elsif ($op eq "-") { |
1b143380 | 463 | print "removed\t" . $cgi->a({-href => "$myself/$project/blob/$id"}, $file) . "\n"; |
161332a5 KS |
464 | } elsif ($op eq "*") { |
465 | $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/; | |
466 | my $old = $1; | |
467 | my $new = $2; | |
e334d18c | 468 | print "changed\t" . $cgi->a({-href => "$myself/$project/blobdiff/$old/$new"}, $file) . "\n"; |
161332a5 KS |
469 | } |
470 | } | |
471 | } | |
472 | print "</pre>\n"; | |
e334d18c | 473 | print "<br/>"; |
12a88f2f | 474 | git_footer_html(); |
e334d18c | 475 | } elsif ($action eq "blobdiff") { |
12a88f2f | 476 | git_header_html(); |
e334d18c | 477 | print "<br/><br/>\n"; |
4c02e3c5 | 478 | print "<pre>\n"; |
823d5dc8 | 479 | git_diff($hash, $hash_parent, $hash, $hash_parent); |
4c02e3c5 | 480 | print "</pre>\n"; |
e334d18c | 481 | print "<br/>"; |
12a88f2f | 482 | git_footer_html(); |
e334d18c | 483 | } elsif ($action eq "commitdiff") { |
823d5dc8 KS |
484 | my $parent = ""; |
485 | open my $fd, "-|", "$gitbin/cat-file", "commit", $hash; | |
486 | while (my $line = <$fd>) { | |
487 | chomp($line); | |
488 | last if $line eq ""; | |
489 | if ($line =~ m/^parent (.*)$/ && $parent eq "") { | |
490 | $parent = $1; | |
491 | } | |
492 | } | |
3f714537 KS |
493 | my $title = <$fd>; |
494 | $title = escapeHTML($title); | |
823d5dc8 KS |
495 | close $fd; |
496 | ||
497 | open $fd, "-|", "$gitbin/diff-tree", "-r", $parent, $hash; | |
4c02e3c5 | 498 | my (@difftree) = map { chomp; $_ } <$fd>; |
161332a5 KS |
499 | close $fd; |
500 | ||
12a88f2f | 501 | git_header_html(); |
e334d18c KS |
502 | print "<div class=\"head2\">\n"; |
503 | print "view " . $cgi->a({-href => "$myself/$project/commit/$hash"}, "commit") . "</div><br/><br/>\n"; | |
3f714537 | 504 | print "<div class=\"title\">$title<br/></div>\n"; |
161332a5 | 505 | print "<pre>\n"; |
4c02e3c5 | 506 | foreach my $line (@difftree) { |
c068cff1 | 507 | # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile' |
4c02e3c5 KS |
508 | $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/; |
509 | my $op = $1; | |
510 | my $mode = $2; | |
511 | my $type = $3; | |
512 | my $id = $4; | |
513 | my $file = $5; | |
514 | if ($type eq "blob") { | |
515 | if ($op eq "+") { | |
516 | git_diff("", $file, "", $id); | |
517 | } elsif ($op eq "-") { | |
518 | git_diff($file, "", $id, ""); | |
519 | } elsif ($op eq "*") { | |
520 | $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/; | |
521 | git_diff($file, $file, $1, $2); | |
522 | } | |
523 | } | |
161332a5 | 524 | } |
161332a5 | 525 | print "</pre>\n"; |
e334d18c | 526 | print "<br/>"; |
12a88f2f | 527 | git_footer_html(); |
161332a5 | 528 | } |