]> git.ipfire.org Git - thirdparty/git.git/blame - gitweb.cgi
v107
[thirdparty/git.git] / gitweb.cgi
CommitLineData
161332a5
KS
1#!/usr/bin/perl
2
22fafb99
KS
3# gitweb.pl - simple web interface to track changes in git repositories
4#
161332a5
KS
5# (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
6# (C) 2005, Christian Gierke <ch@gierke.de>
823d5dc8 7#
b87d78d6 8# This program is licensed under the GPL v2, or a later version
161332a5
KS
9
10use strict;
11use warnings;
12use CGI qw(:standard :escapeHTML);
13use CGI::Carp qw(fatalsToBrowser);
b87d78d6 14use Fcntl ':mode';
161332a5 15
3e029299 16my $cgi = new CGI;
b87d78d6
KS
17my $version = "107";
18my $my_url = $cgi->url();
19my $my_uri = $cgi->url(-absolute => 1);
20my $rss_link = "";
3e029299 21
b87d78d6 22# absolute fs-path which will be prepended to the project path
b51103f3 23my $projectroot = "/pub/scm";
b87d78d6
KS
24
25# location of the git-core binaries
b51103f3 26my $gitbin = "/usr/bin";
b87d78d6
KS
27
28# location for temporary files needed for diffs
b51103f3 29my $gittmp = "/tmp/gitweb";
034df39e 30
b87d78d6
KS
31# target of the home link on top of all pages
32my $home_link = $my_uri;
33$home_link = "/git";
34
35# handler to return the list of projects
36sub get_projects_list {
37 my @list;
38
39 # search in directory
40# my $dir = $projectroot;
41# opendir my $dh, $dir || return undef;
42# while (my $dir = readdir($dh)) {
43# if (-e "$projectroot/$dir/HEAD") {
44# push @list, $dir;
45# }
46# }
47# closedir($dh);
48
49 # read from file
50 my $file = "index/index.txt";
51 open my $fd , $file || return undef;
52 while (my $line = <$fd>) {
53 chomp $line;
54 if (-e "$projectroot/$line/HEAD") {
55 push @list, $line;
56 }
57 }
58 close $fd;
59
60 @list = sort @list;
61 return \@list;
62}
44ad2978 63
b87d78d6 64# input validation
022be3d0 65my $project = $cgi->param('p');
b87d78d6
KS
66if (defined $project) {
67 if ($project =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
68 undef $project;
69 die_error("", "Non-canonical project parameter.");
70 }
71 if ($project =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~]/) {
72 undef $project;
73 die_error("", "Invalid character in project parameter.");
9cd3d988
KS
74 }
75 if (!(-d "$projectroot/$project")) {
b87d78d6
KS
76 undef $project;
77 die_error("", "No such directory.");
78 }
79 if (!(-e "$projectroot/$project/HEAD")) {
80 undef $project;
9cd3d988
KS
81 die_error("", "No such project.");
82 }
6191f8e1 83 $rss_link = "<link rel=\"alternate\" title=\"$project log\" href=\"$my_uri?p=$project;a=rss\" type=\"application/rss+xml\"/>";
034df39e 84 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$project/objects";
a59d4afd 85}
6191f8e1
KS
86
87my $file_name = $cgi->param('f');
b87d78d6
KS
88if (defined $file_name) {
89 if ($file_name =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
90 undef $file_name;
91 die_error("", "Non-canonical file parameter.");
92 }
93 if ($file_name =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~]/) {
94 undef $file_name;
95 die_error("", "Invalid character in file parameter.");
96 }
d51e902a 97}
6191f8e1
KS
98
99my $action = $cgi->param('a');
b87d78d6
KS
100if (defined $action) {
101 if ($action =~ m/[^0-9a-zA-Z\.\-]+/) {
102 undef $action;
103 die_error("", "Invalid action parameter.");
104 }
105} else {
106 $action = "log";
a59d4afd 107}
6191f8e1
KS
108
109my $hash = $cgi->param('h');
b87d78d6
KS
110if (defined $hash && !($hash =~ m/^[0-9a-fA-F]{40}$/)) {
111 undef $hash;
061cc7cd 112 die_error("", "Invalid hash parameter.");
a59d4afd 113}
6191f8e1
KS
114
115my $hash_parent = $cgi->param('hp');
b87d78d6
KS
116if (defined $hash_parent && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
117 undef $hash_parent;
061cc7cd 118 die_error("", "Invalid parent hash parameter.");
a59d4afd 119}
6191f8e1
KS
120
121my $time_back = $cgi->param('t');
b87d78d6
KS
122if (defined $time_back) {
123 if ($time_back =~ m/^[^0-9]+$/) {
124 undef $time_back;
125 die_error("", "Invalid time parameter.");
126 }
2ad9331e 127}
823d5dc8 128
12a88f2f 129sub git_header_html {
a59d4afd
KS
130 my $status = shift || "200 OK";
131
b87d78d6
KS
132 my $title = "git";
133 if (defined $project) {
134 $title .= " - $project";
135 if (defined $action) {
136 $title .= "/$action";
137 }
138 }
a59d4afd
KS
139 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status);
140 print <<EOF;
6191f8e1 141<?xml version="1.0" encoding="utf-8"?>
161332a5 142<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
034df39e 143<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
6191f8e1 144<!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
161332a5 145<head>
b87d78d6 146<title>$title</title>
6191f8e1
KS
147$rss_link
148<style type="text/css">
149body { font-family: sans-serif; font-size: 12px; margin:0px; }
150a { color:#0000cc; }
151a:hover { color:#880000; }
152a:visited { color:#880000; }
153a:active { color:#880000; }
b87d78d6
KS
154div.page_header {
155 margin:15px 15px 0px; height:25px; padding:8px;
6191f8e1
KS
156 font-size:18px; font-weight:bold; background-color:#d9d8d1;
157}
158div.page_header a:visited { color:#0000cc; }
159div.page_header a:hover { color:#880000; }
b87d78d6 160div.page_nav { margin:0px 15px; padding:8px; border:solid #d9d8d1; border-width:0px 1px; }
6191f8e1 161div.page_nav a:visited { color:#0000cc; }
b87d78d6 162div.page_footer { margin:0px 15px 15px; height:17px; padding:4px; padding-left:8px; background-color: #d9d8d1; }
6191f8e1 163div.page_footer_text { float:left; color:#555555; font-style:italic; }
b87d78d6 164div.page_body { margin:0px 15px; padding:8px; border:solid #d9d8d1; border-width:0px 1px; }
6191f8e1 165div.title, a.title {
b87d78d6 166 display:block; margin:0px 15px; padding:6px 8px;
6191f8e1
KS
167 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
168}
169a.title:hover { background-color: #d9d8d1; }
b87d78d6
KS
170div.title_text { margin:0px 15px; padding:6px 8px; border: solid #d9d8d1; border-width:0px 1px 1px; }
171div.log_body { margin:0px 15px; padding:8px; padding-left:150px; border:solid #d9d8d1; border-width:0px 1px; }
6191f8e1
KS
172span.log_age { position:relative; float:left; width:142px; font-style:italic; }
173div.log_link { font-size:10px; font-family:sans-serif; font-style:normal; position:relative; float:left; width:142px; }
174div.list {
b87d78d6 175 display:block; margin:0px 15px; padding:4px 6px 2px; border:solid #d9d8d1; border-width:1px 1px 0px;
6191f8e1
KS
176 font-weight:bold;
177}
178div.list_head {
b87d78d6 179 display:block; margin:0px 15px; padding:4px 6px 4px; border:solid #d9d8d1; border-width:1px 1px 0px;
6191f8e1
KS
180 font-style:italic;
181}
182div.list a { text-decoration:none; color:#000000; }
183div.list a:hover { color:#880000; }
184div.link {
b87d78d6 185 margin:0px 15px; padding:0px 6px 8px; border:solid #d9d8d1; border-width:0px 1px;
6191f8e1
KS
186 font-family:sans-serif; font-size:10px;
187}
b87d78d6
KS
188td { padding:5px 15px 0px 0px; font-size:12px; }
189th { padding-right:10px; font-size:12px; text-align:left; }
190span.diff_info { color:#000099; background-color:#edece6; font-style:italic; }
191a.rss_logo { float:right; border:1px solid; line-height:15px;
6191f8e1
KS
192 border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e; width:35px;
193 color:#ffffff; background-color:#ff6600;
b87d78d6 194 font-weight:bold; font-family:sans-serif; text-align:center; vertical-align:middle;
6191f8e1
KS
195 font-size:10px; display:block; text-decoration:none;
196}
2735983d 197a.rss_logo:hover { background-color:#ee5500; }
6191f8e1 198</style>
161332a5
KS
199</head>
200<body>
201EOF
ff7669a5 202 print "<div class=\"page_header\">\n" .
b87d78d6 203 "<a href=\"http://kernel.org/pub/software/scm/cogito\">" .
022be3d0 204 "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/></a>";
b87d78d6
KS
205 print $cgi->a({-href => $home_link}, "projects") . " / ";
206 if (defined $project) {
d63577da 207 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, escapeHTML($project));
b87d78d6
KS
208 if (defined $action) {
209 print " / $action";
210 }
4c02e3c5
KS
211 }
212 print "</div>\n";
161332a5
KS
213}
214
12a88f2f 215sub git_footer_html {
6191f8e1 216 print "<div class=\"page_footer\">\n";
b87d78d6
KS
217 if (defined $project) {
218 my $descr = git_description($project);
219 if (defined $descr) {
6191f8e1 220 print "<div class=\"page_footer_text\">" . escapeHTML($descr) . "</div>\n";
6191f8e1 221 }
2735983d 222 print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
ff7669a5 223 }
6191f8e1
KS
224 print "</div>\n" .
225 "</body>\n" .
9cd3d988 226 "</html>";
161332a5
KS
227}
228
061cc7cd
KS
229sub die_error {
230 my $status = shift || "403 Forbidden";
a59d4afd 231 my $error = shift || "Malformed query, file missing or permission denied";
664f4cc5 232
a59d4afd
KS
233 git_header_html($status);
234 print "<div class=\"page_body\">\n" .
235 "<br/><br/>\n";
6191f8e1 236 print "$status - $error\n";
a59d4afd
KS
237 print "<br/></div>\n";
238 git_footer_html();
239 exit 0;
240}
241
12a88f2f 242sub git_head {
54b0a43c 243 my $path = shift;
b87d78d6 244 open my $fd, "$projectroot/$path/HEAD" || return undef;
12a88f2f
KS
245 my $head = <$fd>;
246 close $fd;
247 chomp $head;
b87d78d6
KS
248 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
249 return $head;
250 } else {
251 return undef;
252 }
253}
254
255sub git_description {
256 my $path = shift;
257 open my $fd, "$projectroot/$path/description" || return undef;
258 my $descr = <$fd>;
259 close $fd;
260 chomp $descr;
261 return $descr;
12a88f2f
KS
262}
263
703ac710
KS
264sub git_commit {
265 my $commit = shift;
266 my %co;
267 my @parents;
268
b87d78d6 269 open my $fd, "-|", "$gitbin/git-cat-file commit $commit" || return;
703ac710 270 while (my $line = <$fd>) {
b87d78d6
KS
271 last if $line eq "\n";
272 chomp $line;
703ac710
KS
273 if ($line =~ m/^tree (.*)$/) {
274 $co{'tree'} = $1;
275 } elsif ($line =~ m/^parent (.*)$/) {
276 push @parents, $1;
022be3d0 277 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
3f714537 278 $co{'author'} = $1;
185f09e5
KS
279 $co{'author_epoch'} = $2;
280 $co{'author_tz'} = $3;
991910a9
KS
281 $co{'author_name'} = $co{'author'};
282 $co{'author_name'} =~ s/ <.*//;
86eed32d
KS
283 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
284 $co{'committer'} = $1;
185f09e5
KS
285 $co{'committer_epoch'} = $2;
286 $co{'committer_tz'} = $3;
991910a9
KS
287 $co{'committer_name'} = $co{'committer'};
288 $co{'committer_name'} =~ s/ <.*//;
703ac710
KS
289 }
290 }
3f714537 291 $co{'parents'} = \@parents;
3e029299 292 $co{'parent'} = $parents[0];
3f714537
KS
293 my (@comment) = map { chomp; $_ } <$fd>;
294 $co{'comment'} = \@comment;
295 $co{'title'} = $comment[0];
b87d78d6
KS
296 close $fd || return;
297 if (!defined $co{'tree'}) {
298 return undef
299 };
2ae100df
KS
300
301 my $age = time - $co{'committer_epoch'};
302 $co{'age'} = $age;
303 if ($age > 60*60*24*365*2) {
304 $co{'age_string'} = (int $age/60/60/24/365);
305 $co{'age_string'} .= " years ago";
306 } elsif ($age > 60*60*24*365/12*2) {
307 $co{'age_string'} = int $age/60/60/24/365/12;
308 $co{'age_string'} .= " months ago";
309 } elsif ($age > 60*60*24*7*2) {
310 $co{'age_string'} = int $age/60/60/24/7;
311 $co{'age_string'} .= " weeks ago";
312 } elsif ($age > 60*60*24*2) {
313 $co{'age_string'} = int $age/60/60/24;
314 $co{'age_string'} .= " days ago";
315 } elsif ($age > 60*60*2) {
316 $co{'age_string'} = int $age/60/60;
317 $co{'age_string'} .= " hours ago";
318 } elsif ($age > 60*2) {
319 $co{'age_string'} = int $age/60;
320 $co{'age_string'} .= " minutes ago";
b87d78d6
KS
321 } elsif ($age > 2) {
322 $co{'age_string'} = int $age;
323 $co{'age_string'} .= " seconds ago";
324 } else {
325 $co{'age_string'} .= " right now";
2ae100df 326 }
703ac710
KS
327 return %co;
328}
329
8ed23e1b 330sub git_diff_html {
8ed23e1b 331 my $from = shift;
2735983d 332 my $from_name = shift;
8ed23e1b 333 my $to = shift;
2735983d 334 my $to_name = shift;
4c02e3c5 335
8ed23e1b
KS
336 my $from_tmp = "/dev/null";
337 my $to_tmp = "/dev/null";
8ed23e1b 338 my $pid = $$;
4c02e3c5 339
ff7669a5 340 # create tmp from-file
b87d78d6 341 if (defined $from) {
8ed23e1b 342 $from_tmp = "$gittmp/gitweb_" . $$ . "_from";
b87d78d6 343 open my $fd2, "> $from_tmp";
034df39e 344 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
8ed23e1b
KS
345 my @file = <$fd>;
346 print $fd2 @file;
4c02e3c5
KS
347 close $fd2;
348 close $fd;
4c02e3c5
KS
349 }
350
b531daf3 351 # create tmp to-file
b87d78d6 352 if (defined $to) {
8ed23e1b
KS
353 $to_tmp = "$gittmp/gitweb_" . $$ . "_to";
354 open my $fd2, "> $to_tmp";
034df39e 355 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
8ed23e1b
KS
356 my @file = <$fd>;
357 print $fd2 @file;
4c02e3c5
KS
358 close $fd2;
359 close $fd;
4c02e3c5
KS
360 }
361
2735983d 362 open my $fd, "-|", "/usr/bin/diff -u -p -L $from_name -L $to_name $from_tmp $to_tmp";
4c02e3c5
KS
363 while (my $line = <$fd>) {
364 my $char = substr($line,0,1);
2735983d
KS
365 # skip errors
366 next if $char eq '\\';
367 # color the diff
54b0a43c
KS
368 print '<span style="color: #008800;">' if $char eq '+';
369 print '<span style="color: #CC0000;">' if $char eq '-';
370 print '<span style="color: #990099;">' if $char eq '@';
4c02e3c5 371 print escapeHTML($line);
1b143380 372 print '</span>' if $char eq '+' or $char eq '-' or $char eq '@';
4c02e3c5
KS
373 }
374 close $fd;
8ed23e1b 375
b87d78d6 376 if (defined $from) {
2735983d 377 unlink($from_tmp);
8ed23e1b 378 }
b87d78d6 379 if (defined $to) {
2735983d 380 unlink($to_tmp);
8ed23e1b 381 }
4c02e3c5
KS
382}
383
d767d59c 384sub mode_str {
2735983d
KS
385 my $mode = oct shift;
386
b87d78d6
KS
387 if (S_ISDIR($mode & S_IFMT)) {
388 return 'drwxr-xr-x';
389 } elsif (S_ISLNK($mode)) {
390 return 'lrwxrwxrwx';
391 } elsif (S_ISREG($mode)) {
991910a9 392 # git cares only about the executable bit
b87d78d6
KS
393 if ($mode & S_IXUSR) {
394 return '-rwxr-xr-x';
54b0a43c 395 } else {
b87d78d6 396 return '-rw-r--r--';
54b0a43c 397 };
b87d78d6
KS
398 } else {
399 return '----------';
d767d59c 400 }
d767d59c
KS
401}
402
2735983d
KS
403sub file_type {
404 my $mode = oct shift;
405
b87d78d6 406 if (S_ISDIR($mode & S_IFMT)) {
2735983d 407 return "directory";
b87d78d6 408 } elsif (S_ISLNK($mode)) {
2735983d 409 return "symlink";
b87d78d6
KS
410 } elsif (S_ISREG($mode)) {
411 return "file";
2735983d
KS
412 } else {
413 return "unknown";
414 }
415}
416
86eed32d 417sub date_str {
991910a9
KS
418 my $epoch = shift;
419 my $tz = shift || "-0000";
86eed32d 420
991910a9 421 my %date;
86eed32d
KS
422 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
423 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
991910a9
KS
424 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
425 $date{'hour'} = $hour;
ff7669a5
KS
426 $date{'minute'} = $min;
427 $date{'mday'} = $mday;
428 $date{'day'} = $days[$wday];
429 $date{'month'} = $months[$mon];
991910a9
KS
430 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
431 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
432
034df39e
KS
433 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
434 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
991910a9 435 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
185f09e5
KS
436 $date{'hour_local'} = $hour;
437 $date{'minute_local'} = $min;
438 $date{'tz_local'} = $tz;
991910a9 439 return %date;
86eed32d
KS
440}
441
b87d78d6
KS
442# git-logo (cached in browser for one day)
443if (defined $action && $action eq "git-logo.png") {
022be3d0 444 print $cgi->header(-type => 'image/png', -expires => '+1d');
b87d78d6
KS
445 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
446 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
447 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
448 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
449 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
450 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
451 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
452 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
453 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
454 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
455 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
456 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
457 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
458 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
022be3d0
KS
459 exit;
460}
461
b87d78d6
KS
462# project browser
463if (!defined $project) {
464 my $projects = get_projects_list();
465 git_header_html();
466 print "<div class=\"page_body\">\n";
467 print "<table cellspacing=\"0\">\n";
468 print "<tr>\n" .
469 "<th>Project</th>\n" .
470 "<th>Description</th>\n" .
471 "<th>Owner</th>\n" .
472 "<th>last change</th>\n" .
473 "</tr>\n" .
474 "<br/>";
475 foreach my $proj (@$projects) {
476 my $head = git_head($proj);
477 if (!defined $head) {
478 next;
479 }
480 $ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/$proj/objects";
481 my %co = git_commit($head);
482 if (!%co) {
483 next;
484 }
485 my $descr = git_description($proj) || "";
486 my $owner = "";
487 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat("$projectroot/$proj");
488 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
489 if (defined $gcos) {
490 $owner = $gcos;
491 $owner =~ s/[,;].*$//;
492 }
493 print "<tr>\n" .
494 "<td>" . $cgi->a({-href => "$my_uri?p=$proj;a=log"}, escapeHTML($proj)) . "</td>\n" .
495 "<td>$descr</td>\n" .
496 "<td><i>$owner</i></td>\n";
497 if ($co{'age'} < 60*60*2) {
498 print "<td><span style =\"color: #009900;\"><b><i>" . $co{'age_string'} . "</i></b></span></td>\n";
499 } elsif ($co{'age'} < 60*60*24*2) {
500 print "<td><span style =\"color: #009900;\"><i>" . $co{'age_string'} . "</i></span></td>\n";
501 } else {
502 print "<td><i>" . $co{'age_string'} . "</i></td>\n";
503 }
504 print "</tr>\n";
505 undef %co;
506 }
507 print "</table>\n" .
508 "<br/>\n" .
509 "</div>\n";
510 git_footer_html();
161332a5
KS
511 exit;
512}
513
b87d78d6 514# action dispatch
ecb378f5 515if ($action eq "blob") {
b87d78d6 516 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" || die_error("", "Open failed.");
12a88f2f 517 git_header_html();
2ae100df
KS
518 print "<div class=\"page_nav\">\n";
519 print "<br/><br/></div>\n";
520 print "<div class=\"title\">$hash</div>\n";
9cd3d988 521 print "<div class=\"page_body\"><pre>\n";
161332a5
KS
522 my $nr;
523 while (my $line = <$fd>) {
524 $nr++;
fbb592a9 525 printf "<span style =\"color: #999999;\">%4i\t</span>%s", $nr, escapeHTML($line);;
161332a5 526 }
b87d78d6
KS
527 close $fd || print "Reading blob failed.\n";
528 print "</pre><br/>\n";
fbb592a9 529 print "</div>";
12a88f2f 530 git_footer_html();
4c02e3c5 531} elsif ($action eq "tree") {
b87d78d6 532 if (!defined $hash) {
54b0a43c 533 $hash = git_head($project);
161332a5 534 }
b87d78d6 535 open my $fd, "-|", "$gitbin/git-ls-tree $hash" || die_error("", "Open failed.");
161332a5 536 my (@entries) = map { chomp; $_ } <$fd>;
b87d78d6 537 close $fd || die_error("", "Reading tree failed.");
d63577da 538
12a88f2f 539 git_header_html();
d63577da 540 my %co = git_commit($hash);
034df39e 541 if (%co) {
d63577da 542 print "<div class=\"page_nav\"> view\n" .
6191f8e1
KS
543 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | " .
544 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . " | " .
545 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash"}, "tree") .
546 "<br/><br/>\n" .
547 "</div>\n";
d63577da 548 print "<div>\n" .
927dcec4 549 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
d63577da
KS
550 "</div>\n";
551 } else {
552 print "<div class=\"page_nav\">\n";
553 print "<br/><br/></div>\n";
554 print "<div class=\"title\">$hash</div>\n";
555 }
fbb592a9
KS
556 print "<div class=\"page_body\">\n";
557 print "<br/><pre>\n";
161332a5 558 foreach my $line (@entries) {
c068cff1 559 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
161332a5 560 $line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
d767d59c 561 my $t_mode = $1;
161332a5
KS
562 my $t_type = $2;
563 my $t_hash = $3;
564 my $t_name = $4;
565 if ($t_type eq "blob") {
2735983d 566 print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash"}, $t_name);
b87d78d6 567 if (S_ISLNK(oct $t_mode)) {
2735983d
KS
568 open my $fd, "-|", "$gitbin/git-cat-file blob $t_hash";
569 my $target = <$fd>;
570 close $fd;
571 print "\t -> $target";
572 }
573 print "\n";
161332a5 574 } elsif ($t_type eq "tree") {
1207151d 575 print mode_str($t_mode). " " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash"}, $t_name) . "\n";
161332a5
KS
576 }
577 }
578 print "</pre>\n";
fbb592a9 579 print "<br/></div>";
12a88f2f 580 git_footer_html();
034df39e 581} elsif ($action eq "rss") {
b87d78d6 582 open my $fd, "-|", "$gitbin/git-rev-list --max-count=20 " . git_head($project) || die_error("", "Open failed.");
d51e902a 583 my (@revlist) = map { chomp; $_ } <$fd>;
b87d78d6 584 close $fd || die_error("", "Reading rev-list failed.");
e334d18c 585
034df39e
KS
586 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
587 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
588 "<rss version=\"0.91\">\n";
589 print "<channel>\n";
590 print "<title>$project</title>\n".
591 "<link> " . $my_url . "/$project/log</link>\n".
592 "<description>$project log</description>\n".
593 "<language>en</language>\n";
594
595 foreach my $commit (@revlist) {
3f714537 596 my %co = git_commit($commit);
185f09e5 597 my %ad = date_str($co{'author_epoch'});
034df39e
KS
598 print "<item>\n" .
599 "\t<title>" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'min'}) . " - " . escapeHTML($co{'title'}) . "</title>\n" .
600 "\t<link> " . $my_url . "?p=$project;a=commit;h=$commit</link>\n" .
601 "\t<description>";
602 my $comment = $co{'comment'};
603 foreach my $line (@$comment) {
604 print escapeHTML($line) . "<br/>\n";
161332a5 605 }
034df39e
KS
606 print "\t</description>\n" .
607 "</item>\n";
b87d78d6
KS
608 undef %ad;
609 undef %co;
034df39e
KS
610 }
611 print "</channel></rss>";
612} elsif ($action eq "log") {
034df39e 613 my $head = git_head($project);
b87d78d6
KS
614 my $limit_option = "";
615 if (!defined $time_back) {
616 $limit_option = "--max-count=10";
617 } elsif ($time_back > 0) {
618 my $date = time - $time_back*24*60*60;
619 $limit_option = "--max-age=$date";
620 }
621 open my $fd, "-|", "$gitbin/git-rev-list $limit_option $head" || die_error("", "Open failed.");
034df39e 622 my (@revlist) = map { chomp; $_ } <$fd>;
b87d78d6 623 close $fd || die_error("", "Reading rev-list failed.");
034df39e
KS
624
625 git_header_html();
626 print "<div class=\"page_nav\">\n";
627 print "view ";
b87d78d6
KS
628 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, "last 10") . " | " .
629 $cgi->a({-href => "$my_uri?p=$project;a=log;t=1"}, "day") . " | " .
034df39e
KS
630 $cgi->a({-href => "$my_uri?p=$project;a=log;t=7"}, "week") . " | " .
631 $cgi->a({-href => "$my_uri?p=$project;a=log;t=31"}, "month") . " | " .
632 $cgi->a({-href => "$my_uri?p=$project;a=log;t=365"}, "year") . " | " .
633 $cgi->a({-href => "$my_uri?p=$project;a=log;t=0"}, "all") . "<br/>\n";
634 print "<br/><br/>\n" .
635 "</div>\n";
636
b87d78d6 637 if (!@revlist) {
034df39e
KS
638 my %co = git_commit($head);
639 print "<div class=\"page_body\"> Last change " . $co{'age_string'} . ".<br/><br/></div>\n";
161332a5 640 }
034df39e
KS
641
642 foreach my $commit (@revlist) {
643 my %co = git_commit($commit);
b87d78d6 644 next if !%co;
034df39e
KS
645 my %ad = date_str($co{'author_epoch'});
646 print "<div>\n" .
647 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
648 "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
649 "</div>\n";
650 print "<div class=\"title_text\">\n" .
651 "<div class=\"log_link\">\n" .
652 "view " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") . " | " .
653 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "diff") . "<br/>\n" .
654 "</div>\n" .
655 "<i>" . escapeHTML($co{'author_name'}) . " [" . $ad{'rfc2822'} . "]</i><br/>\n" .
656 "</div>\n" .
657 "<div class=\"log_body\">\n";
658 my $comment = $co{'comment'};
659 foreach my $line (@$comment) {
660 last if ($line =~ m/^(signed-off|acked)-by:/i);
661 print escapeHTML($line) . "<br/>\n";
662 }
663 print "<br/>\n" .
664 "</div>\n";
b87d78d6
KS
665 undef %ad;
666 undef %co;
e334d18c 667 }
034df39e 668 git_footer_html();
4c02e3c5 669} elsif ($action eq "commit") {
3e029299 670 my %co = git_commit($hash);
034df39e 671 if (!%co) {
d63577da
KS
672 die_error("", "Unknown commit object.");
673 }
185f09e5
KS
674 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
675 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
161332a5 676
6191f8e1 677 my @difftree;
b87d78d6
KS
678 if (defined $co{'parent'}) {
679 open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash" || die_error("", "Open failed.");
6191f8e1 680 @difftree = map { chomp; $_ } <$fd>;
b87d78d6 681 close $fd || die_error("", "Reading diff-tree failed.");
6191f8e1
KS
682 } else {
683 # fake git-diff-tree output for initial revision
b87d78d6 684 open my $fd, "-|", "$gitbin/git-ls-tree -r $hash" || die_error("", "Open failed.");
6191f8e1 685 @difftree = map { chomp; "+" . $_ } <$fd>;
b87d78d6 686 close $fd || die_error("", "Reading ls-tree failed.");
6191f8e1 687 }
12a88f2f 688 git_header_html();
ff7669a5
KS
689 print "<div class=\"page_nav\"> view\n" .
690 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
1207151d
KS
691 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . " | \n" .
692 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash"}, "tree") . "\n" .
ff7669a5 693 "<br/><br/></div>\n";
b87d78d6
KS
694 if (defined $co{'parent'}) {
695 print "<div>\n" .
696 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
697 "</div>\n";
698 } else {
699 print "<div>\n" .
700 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
701 "</div>\n";
702 }
6191f8e1 703 print "<div class=\"title_text\">\n" .
b87d78d6
KS
704 "<table cellspacing=\"0\">\n";
705 print "<tr><td>author</td><td>" . escapeHTML($co{'author'}) . "</td></tr>\n".
706 "<tr><td></td><td> " . $ad{'rfc2822'};
927dcec4 707 if ($ad{'hour_local'} < 6) {
b87d78d6
KS
708 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
709 } else {
710 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
711 }
712 print "</td></tr>\n";
713 print "<tr><td>committer</td><td>" . escapeHTML($co{'committer'}) . "</td></tr>\n";
714 print "<tr><td></td><td> " . $cd{'rfc2822'} .
715 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
716 print "<tr><td>commit</td><td style=\"font-family: monospace;\">$hash</td></tr>\n";
717 print "<tr><td>tree</td><td style=\"font-family: monospace;\">" .
718 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash"}, $co{'tree'}) . "</td></tr>\n";
3e029299
KS
719 my $parents = $co{'parents'};
720 foreach my $par (@$parents) {
b87d78d6
KS
721 print "<tr><td>parent</td><td style=\"font-family: monospace;\">" .
722 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, $par) . "</td></tr>\n";
3e029299 723 }
b87d78d6
KS
724 print "</table>".
725 "</div>\n";
fbb592a9 726 print "<div class=\"page_body\">\n";
3e029299
KS
727 my $comment = $co{'comment'};
728 foreach my $line (@$comment) {
d767d59c 729 if ($line =~ m/(signed-off|acked)-by:/i) {
927dcec4 730 print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
3e029299
KS
731 } else {
732 print escapeHTML($line) . "<br/>\n";
733 }
734 }
927dcec4 735 print "</div>\n";
6191f8e1
KS
736 if ($#difftree > 10) {
737 print "<div class=\"list_head\">" . ($#difftree + 1) . " files changed:<br/></div>\n";
738 }
161332a5 739 foreach my $line (@difftree) {
c068cff1
KS
740 # '*100644->100644 blob 9f91a116d91926df3ba936a80f020a6ab1084d2b->bb90a0c3a91eb52020d0db0e8b4f94d30e02d596 net/ipv4/route.c'
741 # '+100644 blob 4a83ab6cd565d21ab0385bac6643826b83c2fcd4 arch/arm/lib/bitops.h'
9cd3d988
KS
742 # '*100664->100644 blob b1a8e3dd5556b61dd771d32307c6ee5d7150fa43->b1a8e3dd5556b61dd771d32307c6ee5d7150fa43 show-files.c'
743 # '*100664->100644 blob d08e895238bac36d8220586fdc28c27e1a7a76d3->d08e895238bac36d8220586fdc28c27e1a7a76d3 update-cache.c'
161332a5
KS
744 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
745 my $op = $1;
746 my $mode = $2;
747 my $type = $3;
748 my $id = $4;
749 my $file = $5;
750 if ($type eq "blob") {
751 if ($op eq "+") {
b87d78d6
KS
752 my $mode_chng = "";
753 if (S_ISREG(oct $mode)) {
754 $mode_chng = sprintf(" with mode: %04o", (oct $mode) & 0777);
755 }
927dcec4
KS
756 print "<div class=\"list\">\n" .
757 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"},
b87d78d6 758 escapeHTML($file) . " <span style=\"color: #008000;\">[new " . file_type($mode) . $mode_chng . "]</span>") . "\n" .
9cd3d988
KS
759 "</div>";
760 print "<div class=\"link\">\n" .
1207151d 761 "view " .
6191f8e1 762 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, "file") . "<br/>\n" .
9cd3d988 763 "</div>\n";
161332a5 764 } elsif ($op eq "-") {
927dcec4
KS
765 print "<div class=\"list\">\n" .
766 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"},
2735983d 767 escapeHTML($file) . " <span style=\"color: #c00000;\">[deleted " . file_type($mode) . "]</span>") . "\n" .
9cd3d988
KS
768 "</div>";
769 print "<div class=\"link\">\n" .
1207151d
KS
770 "view " .
771 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, "file") . " | " .
6191f8e1 772 $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "<br/>\n" .
9cd3d988 773 "</div>\n";
161332a5
KS
774 } elsif ($op eq "*") {
775 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
9cd3d988
KS
776 my $from_id = $1;
777 my $to_id = $2;
778 $mode =~ m/^([0-7]{6})->([0-7]{6})$/;
779 my $from_mode = $1;
780 my $to_mode = $2;
d63577da 781 my $mode_chnge = "";
b87d78d6
KS
782 if ($from_mode != $to_mode) {
783 $mode_chnge = " <span style=\"color: #888888;\">[changed";
784 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
785 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
786 }
787 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
788 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
789 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
790 } elsif (S_ISREG($to_mode)) {
791 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
792 }
793 }
794 $mode_chnge .= "]</span>\n";
9cd3d988 795 }
2bb7c6d4
KS
796 print "<div class=\"list\">\n";
797 if ($to_id ne $from_id) {
798 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id"},
799 escapeHTML($file) . $mode_chnge) . "\n" .
800 "</div>\n";
801 } else {
802 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id"},
803 escapeHTML($file) . $mode_chnge) . "\n" .
804 "</div>\n";
805 }
9cd3d988 806 print "<div class=\"link\">\n" .
1207151d 807 "view ";
9cd3d988
KS
808 if ($to_id ne $from_id) {
809 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id"}, "diff") . " | ";
810 }
1207151d 811 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id"}, "file") . " | " .
6191f8e1 812 $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "<br/>\n" .
9cd3d988 813 "</div>\n";
161332a5
KS
814 }
815 }
816 }
12a88f2f 817 git_footer_html();
e334d18c 818} elsif ($action eq "blobdiff") {
b87d78d6 819 mkdir($gittmp, 0700);
12a88f2f 820 git_header_html();
2ae100df
KS
821 print "<div class=\"page_nav\">\n";
822 print "<br/><br/></div>\n";
823 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
9cd3d988 824 print "<div class=\"page_body\">\n" .
ff7669a5 825 "<pre>\n";
2735983d
KS
826 print "<span class=\"diff_info\">blob:" .
827 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash_parent"}, $hash_parent) .
828 " -> blob:" .
829 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash"}, $hash) .
830 "</span>\n";
831 git_diff_html($hash_parent, $hash_parent, $hash, $hash);
ff7669a5
KS
832 print "</pre>\n" .
833 "<br/></div>";
12a88f2f 834 git_footer_html();
e334d18c 835} elsif ($action eq "commitdiff") {
b87d78d6 836 mkdir($gittmp, 0700);
3e029299 837 my %co = git_commit($hash);
034df39e 838 if (!%co) {
d63577da
KS
839 die_error("", "Unknown commit object.");
840 }
b87d78d6 841 open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash" || die_error("", "Open failed.");
4c02e3c5 842 my (@difftree) = map { chomp; $_ } <$fd>;
b87d78d6 843 close $fd || die_error("", "Reading diff-tree failed.");
161332a5 844
12a88f2f 845 git_header_html();
ff7669a5
KS
846 print "<div class=\"page_nav\"> view\n" .
847 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | \n" .
1207151d
KS
848 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "diffs") . " | \n" .
849 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash"}, "tree") . "\n" .
ff7669a5 850 "<br/><br/></div>\n";
9cd3d988 851 print "<div>\n" .
927dcec4 852 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
9cd3d988 853 "</div>\n";
ff7669a5
KS
854 print "<div class=\"page_body\">\n" .
855 "<pre>\n";
4c02e3c5 856 foreach my $line (@difftree) {
c068cff1 857 # '*100644->100644 blob 8e5f9bbdf4de94a1bc4b4da8cb06677ce0a57716->8da3a306d0c0c070d87048d14a033df02f40a154 Makefile'
4c02e3c5
KS
858 $line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/;
859 my $op = $1;
860 my $mode = $2;
861 my $type = $3;
862 my $id = $4;
863 my $file = $5;
864 if ($type eq "blob") {
865 if ($op eq "+") {
b87d78d6
KS
866 print "<span class=\"diff_info\">" . file_type($mode) . ":" .
867 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, $id) . "(new)" .
2735983d 868 "</span>\n";
b87d78d6 869 git_diff_html(undef, "/dev/null", $id, "b/$file");
4c02e3c5 870 } elsif ($op eq "-") {
b87d78d6
KS
871 print "<span class=\"diff_info\">" . file_type($mode) . ":" .
872 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id"}, $id) . "(deleted)" .
2735983d 873 "</span>\n";
b87d78d6 874 git_diff_html($id, "a/$file", undef, "/dev/null");
4c02e3c5
KS
875 } elsif ($op eq "*") {
876 $id =~ m/([0-9a-fA-F]+)->([0-9a-fA-F]+)/;
2735983d
KS
877 my $from_id = $1;
878 my $to_id = $2;
879 $mode =~ m/([0-7]+)->([0-7]+)/;
880 my $from_mode = $1;
881 my $to_mode = $2;
882 if ($from_id ne $to_id) {
883 print "<span class=\"diff_info\">" .
884 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id"}, $from_id) .
885 " -> " .
886 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id"}, $to_id);
887 print "</span>\n";
888 git_diff_html($from_id, "a/$file", $to_id, "b/$file");
9cd3d988 889 }
4c02e3c5
KS
890 }
891 }
161332a5 892 }
b87d78d6 893 print "</pre><br/>\n";
fbb592a9 894 print "</div>";
12a88f2f 895 git_footer_html();
2ae100df 896} elsif ($action eq "history") {
b87d78d6 897 if (!defined $hash) {
2ae100df
KS
898 $hash = git_head($project);
899 }
d51e902a 900 git_header_html();
2ae100df
KS
901 print "<div class=\"page_nav\">\n";
902 print "<br/><br/></div>\n";
d63577da 903 print "<div>\n" .
927dcec4 904 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($file_name)) . "\n" .
820e4f6b 905 "</div>\n";
b87d78d6
KS
906 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin $file_name";
907 my $commit;
908 while (my $line = <$fd>) {
909 if ($line =~ m/^([0-9a-fA-F]{40}) /){
910 $commit = $1;
911 next;
d51e902a 912 }
b87d78d6
KS
913 if ($line =~ m/^(.)(.*)\t(.*)\t(.*)\t(.*)$/ && (defined $commit)) {
914 my $type = $3;
915 my $file = $5;
916 if ($file ne $file_name || $type ne "blob") {
917 next;
918 }
919 my %co = git_commit($commit);
920 if (!%co) {
921 next;
922 }
927dcec4 923 print "<div class=\"list\">\n" .
b87d78d6 924 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"},
1207151d 925 "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
334538f1
KS
926 "</div>\n";
927 print "<div class=\"link\">\n" .
820e4f6b 928 "view " .
b87d78d6
KS
929 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") . " | " .
930 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$commit"}, "tree") . "<br/><br/>\n" .
820e4f6b 931 "</div>\n";
b87d78d6
KS
932 undef %co;
933 undef $commit;
2ae100df 934 }
d51e902a 935 }
b87d78d6 936 close $fd;
d51e902a 937 git_footer_html();
022be3d0 938} else {
b87d78d6 939 undef $action;
2bb7c6d4 940 die_error("", "Unknown action.");
161332a5 941}