v232
[git.git] / gitweb.cgi
blob87088f9a28b33c3bc3ace7b9b865808c2d0dbb44
1 #!/usr/bin/perl
3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke <ch@gierke.de>
8 # This program is licensed under the GPL v2, or a later version
10 use strict;
11 use warnings;
12 use CGI qw(:standard :escapeHTML -nosticky);
13 use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
15 use Fcntl ':mode';
17 my $cgi = new CGI;
18 my $version = "232";
19 my $my_url = $cgi->url();
20 my $my_uri = $cgi->url(-absolute => 1);
21 my $rss_link = "";
23 # absolute fs-path which will be prepended to the project path
24 my $projectroot = "/pub/scm";
26 # location of the git-core binaries
27 my $gitbin = "/usr/bin";
29 # location for temporary files needed for diffs
30 my $git_temp = "/tmp/gitweb";
32 # target of the home link on top of all pages
33 my $home_link = $my_uri;
35 # html text to include at home page
36 my $home_text = "indextext.html";
38 # source of projects list
39 #my $projects_list = $projectroot;
40 my $projects_list = "index/index.aux";
42 # input validation and dispatch
43 my $action = $cgi->param('a');
44 if (defined $action) {
45 if ($action =~ m/[^0-9a-zA-Z\.\-_]+/) {
46 undef $action;
47 die_error(undef, "Invalid action parameter.");
49 if ($action eq "git-logo.png") {
50 git_logo();
51 exit;
52 } elsif ($action eq "opml") {
53 git_opml();
54 exit;
58 my $project = $cgi->param('p');
59 if (defined $project) {
60 if ($project =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
61 undef $project;
62 die_error(undef, "Non-canonical project parameter.");
64 if ($project =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~]/) {
65 undef $project;
66 die_error(undef, "Invalid character in project parameter.");
68 if (!(-d "$projectroot/$project")) {
69 undef $project;
70 die_error(undef, "No such directory.");
72 if (!(-e "$projectroot/$project/HEAD")) {
73 undef $project;
74 die_error(undef, "No such project.");
76 $rss_link = "<link rel=\"alternate\" title=\"$project log\" href=\"$my_uri?p=$project;a=rss\" type=\"application/rss+xml\"/>";
77 $ENV{'GIT_DIR'} = "$projectroot/$project";
78 } else {
79 git_project_list();
80 exit;
83 my $file_name = $cgi->param('f');
84 if (defined $file_name) {
85 if ($file_name =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
86 undef $file_name;
87 die_error(undef, "Non-canonical file parameter.");
89 if ($file_name =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~\:\!]/) {
90 undef $file_name;
91 die_error(undef, "Invalid character in file parameter.");
95 my $hash = $cgi->param('h');
96 if (defined $hash) {
97 if (!($hash =~ m/^[0-9a-fA-F]{40}$/)) {
98 if ($hash =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
99 undef $hash;
100 die_error(undef, "Non-canonical hash parameter.");
102 if ($hash =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~\:\!]/) {
103 undef $hash;
104 die_error(undef, "Invalid character in hash parameter.");
106 # replace branch-name with hash
107 my $branchlist = git_read_refs("refs/heads");
108 foreach my $entry (@$branchlist) {
109 my %branch = %$entry;
110 if ($branch{'name'} eq $hash) {
111 $hash = $branch{'id'};
112 last;
118 my $hash_parent = $cgi->param('hp');
119 if (defined $hash_parent && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
120 undef $hash_parent;
121 die_error(undef, "Invalid hash_parent parameter.");
124 my $hash_base = $cgi->param('hb');
125 if (defined $hash_base && !($hash_base =~ m/^[0-9a-fA-F]{40}$/)) {
126 undef $hash_base;
127 die_error(undef, "Invalid parent hash parameter.");
130 my $page = $cgi->param('pg');
131 if (defined $page) {
132 if ($page =~ m/^[^0-9]+$/) {
133 undef $page;
134 die_error(undef, "Invalid page parameter.");
138 my $searchtext = $cgi->param('s');
139 if (defined $searchtext) {
140 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
141 undef $searchtext;
142 die_error(undef, "Invalid search parameter.");
144 $searchtext = quotemeta $searchtext;
147 if (!defined $action || $action eq "summary") {
148 git_summary();
149 exit;
150 } elsif ($action eq "branches") {
151 git_branches();
152 exit;
153 } elsif ($action eq "tags") {
154 git_tags();
155 exit;
156 } elsif ($action eq "blob") {
157 git_blob();
158 exit;
159 } elsif ($action eq "blob_plain") {
160 git_blob_plain();
161 exit;
162 } elsif ($action eq "tree") {
163 git_tree();
164 exit;
165 } elsif ($action eq "rss") {
166 git_rss();
167 exit;
168 } elsif ($action eq "commit") {
169 git_commit();
170 exit;
171 } elsif ($action eq "log") {
172 git_log();
173 exit;
174 } elsif ($action eq "blobdiff") {
175 git_blobdiff();
176 exit;
177 } elsif ($action eq "blobdiff_plain") {
178 git_blobdiff_plain();
179 exit;
180 } elsif ($action eq "commitdiff") {
181 git_commitdiff();
182 exit;
183 } elsif ($action eq "commitdiff_plain") {
184 git_commitdiff_plain();
185 exit;
186 } elsif ($action eq "history") {
187 git_history();
188 exit;
189 } elsif ($action eq "search") {
190 git_search();
191 exit;
192 } elsif ($action eq "shortlog") {
193 git_shortlog();
194 exit;
195 } else {
196 undef $action;
197 die_error(undef, "Unknown action.");
198 exit;
201 sub git_header_html {
202 my $status = shift || "200 OK";
204 my $title = "git";
205 if (defined $project) {
206 $title .= " - $project";
207 if (defined $action) {
208 $title .= "/$action";
211 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status);
212 print <<EOF;
213 <?xml version="1.0" encoding="utf-8"?>
214 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
215 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
216 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
217 <head>
218 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
219 <meta name="robots" content="index, nofollow"/>
220 <title>$title</title>
221 $rss_link
222 <style type="text/css">
223 body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
224 a { color:#0000cc; }
225 a:hover, a:visited, a:active { color:#880000; }
226 div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; }
227 div.page_header a:visited { color:#0000cc; }
228 div.page_header a:hover { color:#880000; }
229 div.page_nav { padding:8px; }
230 div.page_nav a:visited { color:#0000cc; }
231 div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
232 div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
233 div.page_footer_text { float:left; color:#555555; font-style:italic; }
234 div.page_body { padding:8px; }
235 div.title, a.title {
236 display:block; padding:6px 8px;
237 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
239 a.title:hover { background-color: #d9d8d1; }
240 div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; }
241 div.log_body { padding:8px 8px 8px 150px; }
242 span.age { position:relative; float:left; width:142px; font-style:italic; }
243 div.log_link {
244 padding:0px 8px;
245 font-size:10px; font-family:sans-serif; font-style:normal;
246 position:relative; float:left; width:136px;
248 div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; }
249 a.list { text-decoration:none; color:#000000; }
250 a.list:hover { text-decoration:underline; color:#880000; }
251 table { padding:8px 4px; }
252 th { padding:2px 5px; font-size:12px; text-align:left; }
253 tr.light:hover { background-color:#edece6; }
254 tr.dark { background-color:#f6f6f0; }
255 tr.dark:hover { background-color:#edece6; }
256 td { padding:2px 5px; font-size:12px; vertical-align:top; }
257 td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; }
258 div.pre { font-family:monospace; font-size:12px; white-space:pre; }
259 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
260 div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
261 div.search { margin:4px 8px; position:absolute; top:56px; right:12px }
262 a.linenr { color:#999999; text-decoration:none }
263 a.rss_logo {
264 float:right; padding:3px 0px; width:35px; line-height:10px;
265 border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
266 color:#ffffff; background-color:#ff6600;
267 font-weight:bold; font-family:sans-serif; font-size:10px;
268 text-align:center; text-decoration:none;
270 a.rss_logo:hover { background-color:#ee5500; }
271 </style>
272 </head>
273 <body>
275 print "<div class=\"page_header\">\n" .
276 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
277 "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
278 "</a>\n";
279 print $cgi->a({-href => $home_link}, "projects") . " / ";
280 if (defined $project) {
281 print $cgi->a({-href => "$my_uri?p=$project;a=summary"}, escapeHTML($project));
282 if (defined $action) {
283 print " / $action";
285 print "\n";
286 if (!defined $searchtext) {
287 $searchtext = "";
289 $cgi->param("a", "search");
290 print $cgi->startform(-method => "get", -action => "$my_uri") .
291 "<div class=\"search\">\n" .
292 $cgi->hidden(-name => "p") . "\n" .
293 $cgi->hidden(-name => "a") . "\n" .
294 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
295 "</div>" .
296 $cgi->end_form() . "\n";
298 print "</div>\n";
301 sub git_footer_html {
302 print "<div class=\"page_footer\">\n";
303 if (defined $project) {
304 my $descr = git_read_description($project);
305 if (defined $descr) {
306 print "<div class=\"page_footer_text\">" . escapeHTML($descr) . "</div>\n";
308 print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
309 } else {
310 print $cgi->a({-href => "$my_uri?a=opml", -class => "rss_logo"}, "RSS") . "\n";
312 print "</div>\n" .
313 "</body>\n" .
314 "</html>";
317 sub die_error {
318 my $status = shift || "403 Forbidden";
319 my $error = shift || "Malformed query, file missing or permission denied";
321 git_header_html($status);
322 print "<div class=\"page_body\">\n" .
323 "<br/><br/>\n" .
324 "$status - $error\n" .
325 "<br/>\n" .
326 "</div>\n";
327 git_footer_html();
328 exit;
331 sub git_get_type {
332 my $hash = shift;
334 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
335 my $type = <$fd>;
336 close $fd;
337 chomp $type;
338 return $type;
341 sub git_read_hash {
342 my $path = shift;
344 open my $fd, "$projectroot/$path" or return undef;
345 my $head = <$fd>;
346 close $fd;
347 chomp $head;
348 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
349 return $head;
353 sub git_read_description {
354 my $path = shift;
356 open my $fd, "$projectroot/$path/description" or return undef;
357 my $descr = <$fd>;
358 close $fd;
359 chomp $descr;
360 return $descr;
363 sub git_read_tag {
364 my $tag_id = shift;
365 my %tag;
367 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
368 while (my $line = <$fd>) {
369 chomp $line;
370 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
371 $tag{'object'} = $1;
372 } elsif ($line =~ m/^type (.+)$/) {
373 $tag{'type'} = $1;
374 } elsif ($line =~ m/^tag (.+)$/) {
375 $tag{'name'} = $1;
378 close $fd or return;
379 if (!defined $tag{'name'}) {
380 return
382 return %tag
385 sub git_read_commit {
386 my $commit_id = shift;
387 my $commit_text = shift;
389 my @commit_lines;
390 my %co;
391 my @parents;
393 if (defined $commit_text) {
394 @commit_lines = @$commit_text;
395 } else {
396 open my $fd, "-|", "$gitbin/git-cat-file commit $commit_id" or return;
397 @commit_lines = map { chomp; $_ } <$fd>;
398 close $fd or return;
400 while (my $line = shift @commit_lines) {
401 last if $line eq "\n";
402 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
403 $co{'tree'} = $1;
404 } elsif ($line =~ m/^parent ([0-9a-fA-F]{40})$/) {
405 push @parents, $1;
406 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
407 $co{'author'} = $1;
408 $co{'author_epoch'} = $2;
409 $co{'author_tz'} = $3;
410 if ($co{'author'} =~ m/^([^<]+) </) {
411 $co{'author_name'} = $1;
412 } else {
413 $co{'author_name'} = $co{'author'};
415 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
416 $co{'committer'} = $1;
417 $co{'committer_epoch'} = $2;
418 $co{'committer_tz'} = $3;
419 $co{'committer_name'} = $co{'committer'};
420 $co{'committer_name'} =~ s/ <.*//;
423 if (!defined $co{'tree'}) {
424 return undef
426 $co{'id'} = $commit_id;
427 $co{'parents'} = \@parents;
428 $co{'parent'} = $parents[0];
429 $co{'comment'} = \@commit_lines;
430 foreach my $title (@commit_lines) {
431 if ($title ne "") {
432 $co{'title'} = chop_str($title, 80);
433 # remove leading stuff of merges to make the interesting part visible
434 if (length($title) > 50) {
435 $title =~ s/^Automatic //;
436 $title =~ s/^merge (of|with) /Merge ... /i;
437 if (length($title) > 50) {
438 $title =~ s/(http|rsync):\/\///;
440 if (length($title) > 50) {
441 $title =~ s/(master|www|rsync)\.//;
443 if (length($title) > 50) {
444 $title =~ s/kernel.org:?//;
446 if (length($title) > 50) {
447 $title =~ s/\/pub\/scm//;
450 $co{'title_short'} = chop_str($title, 50);
451 last;
455 my $age = time - $co{'committer_epoch'};
456 $co{'age'} = $age;
457 if ($age > 60*60*24*365*2) {
458 $co{'age_string'} = (int $age/60/60/24/365);
459 $co{'age_string'} .= " years ago";
460 } elsif ($age > 60*60*24*(365/12)*2) {
461 $co{'age_string'} = int $age/60/60/24/(365/12);
462 $co{'age_string'} .= " months ago";
463 } elsif ($age > 60*60*24*7*2) {
464 $co{'age_string'} = int $age/60/60/24/7;
465 $co{'age_string'} .= " weeks ago";
466 } elsif ($age > 60*60*24*2) {
467 $co{'age_string'} = int $age/60/60/24;
468 $co{'age_string'} .= " days ago";
469 } elsif ($age > 60*60*2) {
470 $co{'age_string'} = int $age/60/60;
471 $co{'age_string'} .= " hours ago";
472 } elsif ($age > 60*2) {
473 $co{'age_string'} = int $age/60;
474 $co{'age_string'} .= " min ago";
475 } elsif ($age > 2) {
476 $co{'age_string'} = int $age;
477 $co{'age_string'} .= " sec ago";
478 } else {
479 $co{'age_string'} .= " right now";
481 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
482 if ($age > 60*60*24*7*2) {
483 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
484 $co{'age_string_age'} = $co{'age_string'};
485 } else {
486 $co{'age_string_date'} = $co{'age_string'};
487 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
489 return %co;
492 sub git_diff_print {
493 my $from = shift;
494 my $from_name = shift;
495 my $to = shift;
496 my $to_name = shift;
497 my $format = shift || "html";
499 my $from_tmp = "/dev/null";
500 my $to_tmp = "/dev/null";
501 my $pid = $$;
503 # create tmp from-file
504 if (defined $from) {
505 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
506 open my $fd2, "> $from_tmp";
507 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
508 my @file = <$fd>;
509 print $fd2 @file;
510 close $fd2;
511 close $fd;
514 # create tmp to-file
515 if (defined $to) {
516 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
517 open my $fd2, "> $to_tmp";
518 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
519 my @file = <$fd>;
520 print $fd2 @file;
521 close $fd2;
522 close $fd;
525 open my $fd, "-|", "/usr/bin/diff -u -p -L $from_name -L $to_name $from_tmp $to_tmp";
526 if ($format eq "plain") {
527 undef $/;
528 print <$fd>;
529 $/ = "\n";
530 } else {
531 while (my $line = <$fd>) {
532 chomp($line);
533 my $char = substr($line, 0, 1);
534 my $color = "";
535 if ($char eq '+') {
536 $color = " style=\"color:#008800;\"";
537 } elsif ($char eq "-") {
538 $color = " style=\"color:#cc0000;\"";
539 } elsif ($char eq "@") {
540 $color = " style=\"color:#990099;\"";
541 } elsif ($char eq "\\") {
542 # skip errors
543 next;
545 while ((my $pos = index($line, "\t")) != -1) {
546 if (my $count = (8 - (($pos-1) % 8))) {
547 my $spaces = ' ' x $count;
548 $line =~ s/\t/$spaces/;
551 print "<div class=\"pre\"$color>" . escapeHTML($line) . "</div>\n";
554 close $fd;
556 if (defined $from) {
557 unlink($from_tmp);
559 if (defined $to) {
560 unlink($to_tmp);
564 sub mode_str {
565 my $mode = oct shift;
567 if (S_ISDIR($mode & S_IFMT)) {
568 return 'drwxr-xr-x';
569 } elsif (S_ISLNK($mode)) {
570 return 'lrwxrwxrwx';
571 } elsif (S_ISREG($mode)) {
572 # git cares only about the executable bit
573 if ($mode & S_IXUSR) {
574 return '-rwxr-xr-x';
575 } else {
576 return '-rw-r--r--';
578 } else {
579 return '----------';
583 sub chop_str {
584 my $str = shift;
585 my $len = shift;
586 my $add_len = shift || 10;
588 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})/;
589 my $chopped = $1;
590 if ($chopped ne $str) {
591 $chopped .= " ...";
593 return $chopped;
596 sub file_type {
597 my $mode = oct shift;
599 if (S_ISDIR($mode & S_IFMT)) {
600 return "directory";
601 } elsif (S_ISLNK($mode)) {
602 return "symlink";
603 } elsif (S_ISREG($mode)) {
604 return "file";
605 } else {
606 return "unknown";
610 sub date_str {
611 my $epoch = shift;
612 my $tz = shift || "-0000";
614 my %date;
615 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
616 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
617 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
618 $date{'hour'} = $hour;
619 $date{'minute'} = $min;
620 $date{'mday'} = $mday;
621 $date{'day'} = $days[$wday];
622 $date{'month'} = $months[$mon];
623 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
624 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
626 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
627 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
628 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
629 $date{'hour_local'} = $hour;
630 $date{'minute_local'} = $min;
631 $date{'tz_local'} = $tz;
632 return %date;
635 # git-logo (cached in browser for one day)
636 sub git_logo {
637 print $cgi->header(-type => 'image/png', -expires => '+1d');
638 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
639 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
640 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
641 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
642 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
643 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
644 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
645 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
646 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
647 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
648 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
649 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
650 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
651 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
654 sub get_file_owner {
655 my $path = shift;
657 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
658 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
659 if (!defined $gcos) {
660 return undef;
662 my $owner = $gcos;
663 $owner =~ s/[,;].*$//;
664 return $owner;
667 sub git_read_projects {
668 my @list;
670 if (-d $projects_list) {
671 # search in directory
672 my $dir = $projects_list;
673 opendir my $dh, $dir or return undef;
674 while (my $dir = readdir($dh)) {
675 if (-e "$projectroot/$dir/HEAD") {
676 my $pr = {
677 path => $dir,
679 push @list, $pr
682 closedir($dh);
683 } elsif (-f $projects_list) {
684 # read from file(url-encoded):
685 # 'git%2Fgit.git Linus+Torvalds'
686 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
687 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
688 open my $fd , $projects_list or return undef;
689 while (my $line = <$fd>) {
690 chomp $line;
691 my ($path, $owner) = split ' ', $line;
692 $path = unescape($path);
693 $owner = unescape($owner);
694 if (!defined $path) {
695 next;
697 if (-e "$projectroot/$path/HEAD") {
698 my $pr = {
699 path => $path,
700 owner => $owner,
702 push @list, $pr
705 close $fd;
707 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
708 return @list;
711 sub git_project_list {
712 my @list = git_read_projects();
713 if (!@list) {
714 die_error(undef, "No project found.");
716 git_header_html();
717 if (-f $home_text) {
718 print "<div class=\"index_include\">\n";
719 open (my $fd, $home_text);
720 print <$fd>;
721 close $fd;
722 print "</div>\n";
724 print "<table cellspacing=\"0\">\n" .
725 "<tr>\n" .
726 "<th>Project</th>\n" .
727 "<th>Description</th>\n" .
728 "<th>Owner</th>\n" .
729 "<th>last change</th>\n" .
730 "<th></th>\n" .
731 "</tr>\n";
732 my $alternate = 0;
733 foreach my $pr (@list) {
734 my %proj = %$pr;
735 my $head = git_read_hash("$proj{'path'}/HEAD");
736 if (!defined $head) {
737 next;
739 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
740 my %co = git_read_commit($head);
741 if (!%co) {
742 next;
744 my $descr = git_read_description($proj{'path'}) || "";
745 $descr = chop_str($descr, 25, 5);
746 # get directory owner if not already specified
747 if (!defined $proj{'owner'}) {
748 $proj{'owner'} = get_file_owner("$projectroot/$proj{'path'}") || "";
750 if ($alternate) {
751 print "<tr class=\"dark\">\n";
752 } else {
753 print "<tr class=\"light\">\n";
755 $alternate ^= 1;
756 print "<td>" . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary", -class => "list"}, escapeHTML($proj{'path'})) . "</td>\n" .
757 "<td>$descr</td>\n" .
758 "<td><i>" . chop_str($proj{'owner'}, 15) . "</i></td>\n";
759 my $colored_age;
760 if ($co{'age'} < 60*60*2) {
761 $colored_age = "<span style =\"color: #009900;\"><b><i>$co{'age_string'}</i></b></span>";
762 } elsif ($co{'age'} < 60*60*24*2) {
763 $colored_age = "<span style =\"color: #009900;\"><i>$co{'age_string'}</i></span>";
764 } else {
765 $colored_age = "<i>$co{'age_string'}</i>";
767 print "<td>$colored_age</td>\n" .
768 "<td class=\"link\">" .
769 $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary"}, "summary") .
770 " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=shortlog"}, "shortlog") .
771 " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=log"}, "log") .
772 "</td>\n" .
773 "</tr>\n";
775 print "</table>\n";
776 git_footer_html();
779 sub git_read_refs {
780 my $ref_dir = shift;
781 my @reflist;
783 my @refs;
784 opendir my $dh, "$projectroot/$project/$ref_dir";
785 while (my $dir = readdir($dh)) {
786 if ($dir =~ m/^\./) {
787 next;
789 if (-d "$projectroot/$project/$ref_dir/$dir") {
790 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
791 my @subdirs = grep !m/^\./, readdir $dh2;
792 closedir($dh2);
793 foreach my $subdir (@subdirs) {
794 push @refs, "$dir/$subdir"
796 next;
798 push @refs, $dir;
800 closedir($dh);
801 foreach my $ref_file (@refs) {
802 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
803 my $type = git_get_type($ref_id) || next;
804 my %ref_item;
805 my %co;
806 if ($type eq "tag") {
807 my %tag = git_read_tag($ref_id);
808 if ($tag{'type'} eq "commit") {
809 %co = git_read_commit($tag{'object'});
811 $ref_item{'type'} = $tag{'type'};
812 $ref_item{'name'} = $tag{'name'};
813 $ref_item{'id'} = $tag{'object'};
814 } elsif ($type eq "commit"){
815 %co = git_read_commit($ref_id);
816 $ref_item{'type'} = "commit";
817 $ref_item{'name'} = $ref_file;
818 $ref_item{'title'} = $co{'title'};
819 $ref_item{'id'} = $ref_id;
821 $ref_item{'epoch'} = $co{'committer_epoch'} || 0;
822 $ref_item{'age'} = $co{'age_string'} || "unknown";
824 push @reflist, \%ref_item;
826 # sort tags by age
827 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
828 return \@reflist;
831 sub git_summary {
832 my $descr = git_read_description($project) || "none";
833 my $head = git_read_hash("$project/HEAD");
834 my %co = git_read_commit($head);
835 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
837 my $owner;
838 if (-f $projects_list) {
839 open (my $fd , $projects_list);
840 while (my $line = <$fd>) {
841 chomp $line;
842 my ($pr, $ow) = split ' ', $line;
843 $pr = unescape($pr);
844 $ow = unescape($ow);
845 if ($pr eq $project) {
846 $owner = $ow;
847 last;
850 close $fd;
852 if (!defined $owner) {
853 $owner = get_file_owner("$projectroot/$project");
856 git_header_html();
857 print "<div class=\"page_nav\">\n" .
858 "summary".
859 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
860 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
861 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
862 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
863 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree"}, "tree") .
864 "<br/><br/>\n" .
865 "</div>\n";
866 print "<div class=\"title\">&nbsp;</div>\n";
867 print "<table cellspacing=\"0\">\n" .
868 "<tr><td>description</td><td>" . escapeHTML($descr) . "</td></tr>\n" .
869 "<tr><td>owner</td><td>$owner</td></tr>\n" .
870 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
871 "</table>\n";
872 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
873 my (@revlist) = map { chomp; $_ } <$fd>;
874 close $fd;
875 print "<div>\n" .
876 $cgi->a({-href => "$my_uri?p=$project;a=shortlog", -class => "title"}, "shortlog") .
877 "</div>\n";
878 my $i = 16;
879 print "<table cellspacing=\"0\">\n";
880 my $alternate = 0;
881 foreach my $commit (@revlist) {
882 my %co = git_read_commit($commit);
883 my %ad = date_str($co{'author_epoch'});
884 if ($alternate) {
885 print "<tr class=\"dark\">\n";
886 } else {
887 print "<tr class=\"light\">\n";
889 $alternate ^= 1;
890 if ($i-- > 0) {
891 print "<td><i>$co{'age_string'}</i></td>\n" .
892 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
893 "<td>" .
894 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"},
895 "<b>" . escapeHTML($co{'title_short'}) . "</b>") .
896 "</td>\n" .
897 "<td class=\"link\">" .
898 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
899 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
900 "</td>\n" .
901 "</tr>";
902 } else {
903 print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "...") . "</td>\n" .
904 "</tr>";
905 last;
908 print "</table\n>";
910 my $taglist = git_read_refs("refs/tags");
911 if (defined @$taglist) {
912 print "<div>\n" .
913 $cgi->a({-href => "$my_uri?p=$project;a=tags", -class => "title"}, "tags") .
914 "</div>\n";
915 my $i = 16;
916 print "<table cellspacing=\"0\">\n";
917 my $alternate = 0;
918 foreach my $entry (@$taglist) {
919 my %tag = %$entry;
920 if ($alternate) {
921 print "<tr class=\"dark\">\n";
922 } else {
923 print "<tr class=\"light\">\n";
925 $alternate ^= 1;
926 if ($i-- > 0) {
927 print "<td><i>$tag{'age'}</i></td>\n" .
928 "<td>" .
929 $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}", -class => "list"}, "<b>" .
930 escapeHTML($tag{'name'}) . "</b>") .
931 "</td>\n" .
932 "<td class=\"link\">" .
933 $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, $tag{'type'});
934 if ($tag{'type'} eq "commit") {
935 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}"}, "shortlog") .
936 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log");
938 print "</td>\n" .
939 "</tr>";
940 } else {
941 print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=tags"}, "...") . "</td>\n" .
942 "</tr>";
943 last;
946 print "</table\n>";
949 my $branchlist = git_read_refs("refs/heads");
950 if (defined @$branchlist) {
951 print "<div>\n" .
952 $cgi->a({-href => "$my_uri?p=$project;a=branches", -class => "title"}, "branches") .
953 "</div>\n";
954 my $i = 16;
955 print "<table cellspacing=\"0\">\n";
956 my $alternate = 0;
957 foreach my $entry (@$branchlist) {
958 my %tag = %$entry;
959 if ($alternate) {
960 print "<tr class=\"dark\">\n";
961 } else {
962 print "<tr class=\"light\">\n";
964 $alternate ^= 1;
965 if ($i-- > 0) {
966 print "<td><i>$tag{'age'}</i></td>\n" .
967 "<td>" .
968 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}", -class => "list"},
969 "<b>" . escapeHTML($tag{'name'}) . "</b>") .
970 "</td>\n" .
971 "<td class=\"link\">" .
972 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
973 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'name'}"}, "log") .
974 "</td>\n" .
975 "</tr>";
976 } else {
977 print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=branches"}, "...") . "</td>\n" .
978 "</tr>";
979 last;
982 print "</table\n>";
984 git_footer_html();
987 sub git_tags {
988 my $head = git_read_hash("$project/HEAD");
989 git_header_html();
990 print "<div class=\"page_nav\">\n" .
991 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
992 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
993 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
994 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
995 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
996 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;hb=$head"}, "tree") . "<br/>\n" .
997 "<br/>\n" .
998 "</div>\n";
999 my $taglist = git_read_refs("refs/tags");
1000 print "<div>\n" .
1001 $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "&nbsp;") .
1002 "</div>\n";
1003 print "<table cellspacing=\"0\">\n";
1004 my $alternate = 0;
1005 if (defined @$taglist) {
1006 foreach my $entry (@$taglist) {
1007 my %tag = %$entry;
1008 if ($alternate) {
1009 print "<tr class=\"dark\">\n";
1010 } else {
1011 print "<tr class=\"light\">\n";
1013 $alternate ^= 1;
1014 print "<td><i>$tag{'age'}</i></td>\n" .
1015 "<td>" .
1016 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}", -class => "list"},
1017 "<b>" . escapeHTML($tag{'name'}) . "</b>") .
1018 "</td>\n" .
1019 "<td class=\"link\">" .
1020 $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, $tag{'type'});
1021 if ($tag{'type'} eq "commit") {
1022 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
1023 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log");
1025 print "</td>\n" .
1026 "</tr>";
1029 print "</table\n>";
1030 git_footer_html();
1033 sub git_branches {
1034 my $head = git_read_hash("$project/HEAD");
1035 git_header_html();
1036 print "<div class=\"page_nav\">\n" .
1037 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1038 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1039 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1040 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
1041 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
1042 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;hb=$head"}, "tree") . "<br/>\n" .
1043 "<br/>\n" .
1044 "</div>\n";
1045 my $taglist = git_read_refs("refs/heads");
1046 print "<div>\n" .
1047 $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "&nbsp;") .
1048 "</div>\n";
1049 print "<table cellspacing=\"0\">\n";
1050 my $alternate = 0;
1051 if (defined @$taglist) {
1052 foreach my $entry (@$taglist) {
1053 my %tag = %$entry;
1054 if ($alternate) {
1055 print "<tr class=\"dark\">\n";
1056 } else {
1057 print "<tr class=\"light\">\n";
1059 $alternate ^= 1;
1060 print "<td><i>$tag{'age'}</i></td>\n" .
1061 "<td>" .
1062 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}", -class => "list"}, "<b>" . escapeHTML($tag{'name'}) . "</b>") .
1063 "</td>\n" .
1064 "<td class=\"link\">" .
1065 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'name'}"}, "shortlog") .
1066 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'name'}"}, "log") .
1067 "</td>\n" .
1068 "</tr>";
1071 print "</table\n>";
1072 git_footer_html();
1075 sub git_get_hash_by_path {
1076 my $base = shift;
1077 my $path = shift || return undef;
1079 my $tree = $base;
1080 my @parts = split '/', $path;
1081 while (my $part = shift @parts) {
1082 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1083 my (@entries) = map { chomp; $_ } <$fd>;
1084 close $fd or return undef;
1085 foreach my $line (@entries) {
1086 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1087 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1088 my $t_mode = $1;
1089 my $t_type = $2;
1090 my $t_hash = $3;
1091 my $t_name = $4;
1092 if ($t_name eq $part) {
1093 if (!(@parts)) {
1094 return $t_hash;
1096 if ($t_type eq "tree") {
1097 $tree = $t_hash;
1099 last;
1105 sub git_blob {
1106 if (!defined $hash && defined $file_name) {
1107 my $base = $hash_base || git_read_hash("$project/HEAD");
1108 $hash = git_get_hash_by_path($base, $file_name, "blob");
1110 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1111 my $base = $file_name || "";
1112 git_header_html();
1113 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1114 print "<div class=\"page_nav\">\n" .
1115 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1116 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1117 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1118 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1119 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1120 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") . "<br/>\n";
1121 print $cgi->a({-href => "$my_uri?p=$project;a=blob_plain;h=$hash"}, "plain") . "<br/>\n" .
1122 "</div>\n";
1123 print "<div>" .
1124 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) .
1125 "</div>\n";
1126 } else {
1127 print "<div class=\"page_nav\">\n" .
1128 "<br/><br/></div>\n" .
1129 "<div class=\"title\">$hash</div>\n";
1131 if (defined $file_name) {
1132 print "<div class=\"page_path\"><b>$file_name</b></div>\n";
1134 print "<div class=\"page_body\">\n";
1135 my $nr;
1136 while (my $line = <$fd>) {
1137 chomp $line;
1138 $nr++;
1139 while ((my $pos = index($line, "\t")) != -1) {
1140 if (my $count = (8 - ($pos % 8))) {
1141 my $spaces = ' ' x $count;
1142 $line =~ s/\t/$spaces/;
1145 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, escapeHTML($line);
1147 close $fd or print "Reading blob failed.\n";
1148 print "</div>";
1149 git_footer_html();
1152 sub git_blob_plain {
1153 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1154 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1155 undef $/;
1156 print <$fd>;
1157 $/ = "\n";
1158 close $fd;
1161 sub git_tree {
1162 if (!defined $hash) {
1163 $hash = git_read_hash("$project/HEAD");
1164 if (defined $file_name) {
1165 my $base = $hash_base || git_read_hash("$project/HEAD");
1166 $hash = git_get_hash_by_path($base, $file_name, "tree");
1168 if (!defined $hash_base) {
1169 $hash_base = git_read_hash("$project/HEAD");
1172 open my $fd, "-|", "$gitbin/git-ls-tree $hash" or die_error(undef, "Open git-ls-tree failed.");
1173 my (@entries) = map { chomp; $_ } <$fd>;
1174 close $fd or die_error(undef, "Reading tree failed.");
1176 git_header_html();
1177 my $base_key = "";
1178 my $file_key = "";
1179 my $base = "";
1180 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1181 $base_key = ";hb=$hash_base";
1182 print "<div class=\"page_nav\">\n" .
1183 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1184 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash_base"}, "shortlog") .
1185 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash_base"}, "log") .
1186 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1187 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1188 " | tree" .
1189 "<br/><br/>\n" .
1190 "</div>\n";
1191 print "<div>\n" .
1192 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1193 "</div>\n";
1194 } else {
1195 print "<div class=\"page_nav\">\n";
1196 print "<br/><br/></div>\n";
1197 print "<div class=\"title\">$hash</div>\n";
1199 if (defined $file_name) {
1200 $base = "$file_name/";
1201 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1202 } else {
1203 print "<div class=\"page_path\"><b>/</b></div>\n";
1205 print "<div class=\"page_body\">\n";
1206 print "<table cellspacing=\"0\">\n";
1207 my $alternate = 0;
1208 foreach my $line (@entries) {
1209 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1210 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1211 my $t_mode = $1;
1212 my $t_type = $2;
1213 my $t_hash = $3;
1214 my $t_name = $4;
1215 $file_key = ";f=$base$t_name";
1216 if ($alternate) {
1217 print "<tr class=\"dark\">\n";
1218 } else {
1219 print "<tr class=\"light\">\n";
1221 $alternate ^= 1;
1222 print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n";
1223 if ($t_type eq "blob") {
1224 print "<td class=\"list\">" .
1225 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key, -class => "list"}, $t_name) .
1226 "</td>\n" .
1227 "<td class=\"link\">" .
1228 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key}, "blob") .
1229 " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base" . $file_key}, "history") .
1230 "</td>\n";
1231 } elsif ($t_type eq "tree") {
1232 print "<td class=\"list\">" .
1233 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key}, $t_name) .
1234 "</td>\n" .
1235 "<td class=\"link\">" .
1236 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key}, "tree") .
1237 "</td>\n";
1239 print "</tr>\n";
1241 print "</table>\n" .
1242 "</div>";
1243 git_footer_html();
1246 sub git_rss {
1247 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1248 open my $fd, "-|", "$gitbin/git-rev-list --max-count=20 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
1249 my (@revlist) = map { chomp; $_ } <$fd>;
1250 close $fd or die_error(undef, "Reading rev-list failed.");
1252 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1253 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1254 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1255 print "<channel>\n";
1256 print "<title>$project</title>\n".
1257 "<link>" . escapeHTML("$my_url?p=$project;a=summary") . "</link>\n".
1258 "<description>$project log</description>\n".
1259 "<language>en</language>\n";
1261 foreach my $commit (@revlist) {
1262 my %co = git_read_commit($commit);
1263 my %cd = date_str($co{'committer_epoch'});
1264 print "<item>\n" .
1265 "<title>" .
1266 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . escapeHTML($co{'title'}) .
1267 "</title>\n" .
1268 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1269 "<link>" . escapeHTML("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1270 "<description>" . escapeHTML($co{'title'}) . "</description>\n" .
1271 "<content:encoded>" .
1272 "<![CDATA[\n";
1273 my $comment = $co{'comment'};
1274 foreach my $line (@$comment) {
1275 print "$line<br/>\n";
1277 print "]]>\n" .
1278 "</content:encoded>\n" .
1279 "</item>\n";
1281 print "</channel></rss>";
1284 sub git_opml {
1285 my @list = git_read_projects();
1287 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1288 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1289 "<opml version=\"1.0\">\n".
1290 "<head>".
1291 " <title>Git OPML Export</title>\n".
1292 "</head>\n".
1293 "<body>\n".
1294 "<outline text=\"git RSS feeds\">\n";
1296 foreach my $pr (@list) {
1297 my %proj = %$pr;
1298 my $head = git_read_hash("$proj{'path'}/HEAD");
1299 if (!defined $head) {
1300 next;
1302 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1303 my %co = git_read_commit($head);
1304 if (!%co) {
1305 next;
1308 my $path = escapeHTML(chop_str($proj{'path'}, 25, 5));
1309 my $rss = "$my_url?p=$proj{'path'};a=rss";
1310 my $html = "$my_url?p=$proj{'path'};a=summary";
1311 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1313 print "</outline>\n".
1314 "</body>\n".
1315 "</opml>\n";
1318 sub git_log {
1319 my $head = git_read_hash("$project/HEAD");
1320 if (!defined $hash) {
1321 $hash = $head;
1323 if (!defined $page) {
1324 $page = 0;
1326 git_header_html();
1327 print "<div class=\"page_nav\">\n";
1328 print $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1329 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1330 " | log" .
1331 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1332 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1333 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
1335 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1336 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1337 my (@revlist) = map { chomp; $_ } <$fd>;
1338 close $fd;
1340 if ($hash ne $head || $page) {
1341 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, "HEAD");
1342 } else {
1343 print "HEAD";
1345 if ($page > 0) {
1346 print " &sdot; " .
1347 $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash;pg=" . ($page-1), -accesskey => "p", -title => "Alt-p"}, "prev");
1348 } else {
1349 print " &sdot; prev";
1351 if ($#revlist >= (100 * ($page+1)-1)) {
1352 print " &sdot; " .
1353 $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash;pg=" . ($page+1), -accesskey => "n", -title => "Alt-n"}, "next");
1354 } else {
1355 print " &sdot; next";
1357 print "<br/>\n" .
1358 "</div>\n";
1359 if (!@revlist) {
1360 print "<div>\n" .
1361 $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "&nbsp;") .
1362 "</div>\n";
1363 my %co = git_read_commit($hash);
1364 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1366 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1367 my $commit = $revlist[$i];
1368 my %co = git_read_commit($commit);
1369 next if !%co;
1370 my %ad = date_str($co{'author_epoch'});
1371 print "<div>\n" .
1372 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
1373 "<span class=\"age\">$co{'age_string'}</span>" . escapeHTML($co{'title'})) . "\n" .
1374 "</div>\n";
1375 print "<div class=\"title_text\">\n" .
1376 "<div class=\"log_link\">\n" .
1377 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1378 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
1379 "<br/>\n" .
1380 "</div>\n" .
1381 "<i>" . escapeHTML($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1382 "</div>\n" .
1383 "<div class=\"log_body\">\n";
1384 my $comment = $co{'comment'};
1385 my $empty = 0;
1386 foreach my $line (@$comment) {
1387 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1388 next;
1390 if ($line eq "") {
1391 if ($empty) {
1392 next;
1394 $empty = 1;
1395 } else {
1396 $empty = 0;
1398 print escapeHTML($line) . "<br/>\n";
1400 if (!$empty) {
1401 print "<br/>\n";
1403 print "</div>\n";
1405 git_footer_html();
1408 sub git_commit {
1409 my %co = git_read_commit($hash);
1410 if (!%co) {
1411 die_error(undef, "Unknown commit object.");
1413 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1414 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1416 my @difftree;
1417 my $root = "";
1418 if (!defined $co{'parent'}) {
1419 $root = " --root";
1421 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $co{'parent'} $hash" or die_error(undef, "Open failed.");
1422 @difftree = map { chomp; $_ } <$fd>;
1423 close $fd or die_error(undef, "Reading diff-tree failed.");
1424 git_header_html();
1425 print "<div class=\"page_nav\">\n" .
1426 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1427 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1428 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1429 " | commit";
1430 if (defined $co{'parent'}) {
1431 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff");
1433 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "\n" .
1434 "<br/><br/></div>\n";
1435 if (defined $co{'parent'}) {
1436 print "<div>\n" .
1437 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1438 "</div>\n";
1439 } else {
1440 print "<div>\n" .
1441 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1442 "</div>\n";
1444 print "<div class=\"title_text\">\n" .
1445 "<table cellspacing=\"0\">\n";
1446 print "<tr><td>author</td><td>" . escapeHTML($co{'author'}) . "</td></tr>\n".
1447 "<tr>" .
1448 "<td></td><td> $ad{'rfc2822'}";
1449 if ($ad{'hour_local'} < 6) {
1450 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1451 } else {
1452 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1454 print "</td>" .
1455 "</tr>\n";
1456 print "<tr><td>committer</td><td>" . escapeHTML($co{'committer'}) . "</td></tr>\n";
1457 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1458 print "<tr><td>commit</td><td style=\"font-family:monospace\">$hash</td></tr>\n";
1459 print "<tr>" .
1460 "<td>tree</td>" .
1461 "<td style=\"font-family:monospace\">" .
1462 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", class => "list"}, $co{'tree'}) .
1463 "</td>" .
1464 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1465 "</td>" .
1466 "</tr>\n";
1467 my $parents = $co{'parents'};
1468 foreach my $par (@$parents) {
1469 print "<tr>" .
1470 "<td>parent</td>" .
1471 "<td style=\"font-family:monospace\">" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par", class => "list"}, $par) . "</td>" .
1472 "<td class=\"link\">" .
1473 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, "commit") .
1474 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash;hp=$par"}, "commitdiff") .
1475 "</td>" .
1476 "</tr>\n";
1478 print "</table>".
1479 "</div>\n";
1480 print "<div class=\"page_body\">\n";
1481 my $comment = $co{'comment'};
1482 my $empty = 0;
1483 my $signed = 0;
1484 foreach my $line (@$comment) {
1485 # print only one empty line
1486 if ($line eq "") {
1487 if ($empty || $signed) {
1488 next;
1490 $empty = 1;
1491 } else {
1492 $empty = 0;
1494 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1495 $signed = 1;
1496 print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
1497 } else {
1498 $signed = 0;
1499 print escapeHTML($line) . "<br/>\n";
1502 print "</div>\n";
1503 print "<div class=\"list_head\">\n";
1504 if ($#difftree > 10) {
1505 print(($#difftree + 1) . " files changed:\n");
1507 print "</div>\n";
1508 print "<table cellspacing=\"0\">\n";
1509 my $alternate = 0;
1510 foreach my $line (@difftree) {
1511 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1512 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1513 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/;
1514 my $from_mode = $1;
1515 my $to_mode = $2;
1516 my $from_id = $3;
1517 my $to_id = $4;
1518 my $status = $5;
1519 my $similarity = $6;
1520 my $file = $7;
1521 #print "$line ($status)<br/>\n";
1522 if ($alternate) {
1523 print "<tr class=\"dark\">\n";
1524 } else {
1525 print "<tr class=\"light\">\n";
1527 $alternate ^= 1;
1528 if ($status eq "N") {
1529 my $mode_chng = "";
1530 if (S_ISREG(oct $to_mode)) {
1531 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1533 print "<td>" .
1534 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hp=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "</td>\n" .
1535 "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1536 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob") . "</td>\n";
1537 } elsif ($status eq "D") {
1538 print "<td>" .
1539 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "</td>\n" .
1540 "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1541 "<td class=\"link\">" .
1542 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, "blob") .
1543 " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") .
1544 "</td>\n"
1545 } elsif ($status eq "M" || $status eq "T") {
1546 my $mode_chnge = "";
1547 if ($from_mode != $to_mode) {
1548 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1549 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1550 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1552 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1553 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1554 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1555 } elsif (S_ISREG($to_mode)) {
1556 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1559 $mode_chnge .= "]</span>\n";
1561 print "<td>";
1562 if ($to_id ne $from_id) {
1563 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file));
1564 } else {
1565 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file));
1567 print "</td>\n" .
1568 "<td>$mode_chnge</td>\n" .
1569 "<td class=\"link\">";
1570 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob");
1571 if ($to_id ne $from_id) {
1572 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"}, "diff");
1574 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "\n";
1575 print "</td>\n";
1576 } elsif ($status eq "R") {
1577 my ($from_file, $to_file) = split "\t", $file;
1578 my $mode_chng = "";
1579 if ($from_mode != $to_mode) {
1580 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1582 print "<td>" .
1583 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file", -class => "list"}, escapeHTML($to_file)) . "</td>\n" .
1584 "<td><span style=\"color: #777777;\">[moved from " .
1585 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file", -class => "list"}, escapeHTML($from_file)) .
1586 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1587 "<td class=\"link\">" .
1588 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"}, "blob");
1589 if ($to_id ne $from_id) {
1590 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file"}, "diff");
1592 print "</td>\n";
1594 print "</tr>\n";
1596 print "</table>\n";
1597 git_footer_html();
1600 sub git_blobdiff {
1601 mkdir($git_temp, 0700);
1602 git_header_html();
1603 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1604 print "<div class=\"page_nav\">\n" .
1605 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1606 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1607 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1608 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1609 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1610 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") .
1611 "<br/>\n";
1612 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent"}, "plain") .
1613 "</div>\n";
1614 print "<div>\n" .
1615 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1616 "</div>\n";
1617 } else {
1618 print "<div class=\"page_nav\">\n" .
1619 "<br/><br/></div>\n" .
1620 "<div class=\"title\">$hash vs $hash_parent</div>\n";
1622 if (defined $file_name) {
1623 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1625 print "<div class=\"page_body\">\n" .
1626 "<div class=\"diff_info\">blob:" .
1627 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name"}, $hash_parent) .
1628 " -> blob:" .
1629 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name"}, $hash) .
1630 "</div>\n";
1631 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
1632 print "</div>";
1633 git_footer_html();
1636 sub git_blobdiff_plain {
1637 mkdir($git_temp, 0700);
1638 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1639 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
1642 sub git_commitdiff {
1643 mkdir($git_temp, 0700);
1644 my %co = git_read_commit($hash);
1645 if (!%co) {
1646 die_error(undef, "Unknown commit object.");
1648 if (!defined $hash_parent) {
1649 $hash_parent = $co{'parent'};
1651 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1652 my (@difftree) = map { chomp; $_ } <$fd>;
1653 close $fd or die_error(undef, "Reading diff-tree failed.");
1655 git_header_html();
1656 print "<div class=\"page_nav\">\n" .
1657 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1658 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1659 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1660 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1661 " | commitdiff" .
1662 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "<br/>\n";
1663 print $cgi->a({-href => "$my_uri?p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent"}, "plain") . "\n" .
1664 "</div>\n";
1665 print "<div>\n" .
1666 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1667 "</div>\n";
1668 print "<div class=\"page_body\">\n";
1669 my $comment = $co{'comment'};
1670 my $empty = 0;
1671 my $signed = 0;
1672 my @log = @$comment;
1673 # remove first and empty lines after that
1674 shift @log;
1675 while (defined $log[0] && $log[0] eq "") {
1676 shift @log;
1678 foreach my $line (@log) {
1679 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1680 next;
1682 if ($line eq "") {
1683 if ($empty) {
1684 next;
1686 $empty = 1;
1687 } else {
1688 $empty = 0;
1690 print escapeHTML($line) . "<br/>\n";
1692 print "<br/>\n";
1693 foreach my $line (@difftree) {
1694 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1695 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1696 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1697 my $from_mode = $1;
1698 my $to_mode = $2;
1699 my $from_id = $3;
1700 my $to_id = $4;
1701 my $status = $5;
1702 my $file = $6;
1703 if ($status eq "N") {
1704 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
1705 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id) . "(new)" .
1706 "</div>\n";
1707 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
1708 } elsif ($status eq "D") {
1709 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
1710 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) . "(deleted)" .
1711 "</div>\n";
1712 git_diff_print($from_id, "a/$file", undef, "/dev/null");
1713 } elsif ($status eq "M") {
1714 if ($from_id ne $to_id) {
1715 print "<div class=\"diff_info\">" .
1716 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) .
1717 " -> " .
1718 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id);
1719 print "</div>\n";
1720 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
1724 print "<br/>\n" .
1725 "</div>";
1726 git_footer_html();
1729 sub git_commitdiff_plain {
1730 mkdir($git_temp, 0700);
1731 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1732 my (@difftree) = map { chomp; $_ } <$fd>;
1733 close $fd or die_error(undef, "Reading diff-tree failed.");
1735 # try to figure out the next tag after this commit
1736 my $tagname;
1737 my %taghash;
1738 my $tags = git_read_refs("refs/tags");
1739 foreach my $entry (@$tags) {
1740 my %tag = %$entry;
1741 $taghash{$tag{'id'}} = $tag{'name'};
1743 open $fd, "-|", "$gitbin/git-rev-list HEAD";
1744 while (my $commit = <$fd>) {
1745 chomp $commit;
1746 if ($taghash{$commit}) {
1747 $tagname = $taghash{$commit};
1749 if ($commit eq $hash) {
1750 last;
1753 close $fd;
1755 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1756 my %co = git_read_commit($hash);
1757 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1758 my $comment = $co{'comment'};
1759 print "From: $co{'author'}\n" .
1760 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
1761 "Subject: $co{'title'}\n";
1762 if (defined $tagname) {
1763 print "X-Git-Tag: $tagname\n";
1765 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
1766 "\n";
1768 foreach my $line (@$comment) {;
1769 print " $line\n";
1771 print "---\n\n";
1773 foreach my $line (@difftree) {
1774 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1775 my $from_id = $3;
1776 my $to_id = $4;
1777 my $status = $5;
1778 my $file = $6;
1779 if ($status eq "N") {
1780 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
1781 } elsif ($status eq "D") {
1782 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
1783 } elsif ($status eq "M") {
1784 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
1789 sub git_history {
1790 if (!defined $hash) {
1791 $hash = git_read_hash("$project/HEAD");
1793 my %co = git_read_commit($hash);
1794 if (!%co) {
1795 die_error(undef, "Unknown commit object.");
1797 git_header_html();
1798 print "<div class=\"page_nav\">\n" .
1799 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1800 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1801 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1802 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1803 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1804 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1805 "<br/><br/>\n" .
1806 "</div>\n";
1807 print "<div>\n" .
1808 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1809 "</div>\n";
1810 print "<div class=\"page_path\"><b>/$file_name</b><br/></div>\n";
1812 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin $file_name";
1813 my $commit;
1814 print "<table cellspacing=\"0\">\n";
1815 my $alternate = 0;
1816 while (my $line = <$fd>) {
1817 if ($line =~ m/^([0-9a-fA-F]{40})/){
1818 $commit = $1;
1819 next;
1821 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
1822 my %co = git_read_commit($commit);
1823 if (!%co) {
1824 next;
1826 if ($alternate) {
1827 print "<tr class=\"dark\">\n";
1828 } else {
1829 print "<tr class=\"light\">\n";
1831 $alternate ^= 1;
1832 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1833 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1834 "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
1835 escapeHTML(chop_str($co{'title'}, 50)) . "</b>") . "</td>\n" .
1836 "<td class=\"link\">" .
1837 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1838 " | " . $cgi->a({-href => "$my_uri?p=$project;a=blob;hb=$commit;f=$file_name"}, "blob");
1839 my $blob = git_get_hash_by_path($hash, $file_name);
1840 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1841 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
1842 print " | " .
1843 $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name"},
1844 "diff to current");
1846 print "</td>\n" .
1847 "</tr>\n";
1848 undef $commit;
1851 print "</table>\n";
1852 close $fd;
1853 git_footer_html();
1856 sub git_search {
1857 if (!defined $searchtext) {
1858 die_error("", "Text field empty.");
1860 if (!defined $hash) {
1861 $hash = git_read_hash("$project/HEAD");
1863 my %co = git_read_commit($hash);
1864 if (!%co) {
1865 die_error(undef, "Unknown commit object.");
1867 # pickaxe may take all resources of your box and run for several minutes
1868 # with every query - so decide by yourself how public you make this feature :)
1869 my $commit_search = 1;
1870 my $author_search = 0;
1871 my $committer_search = 0;
1872 my $pickaxe_search = 0;
1873 if ($searchtext =~ s/^author\\://i) {
1874 $author_search = 1;
1875 } elsif ($searchtext =~ s/^committer\\://i) {
1876 $committer_search = 1;
1877 } elsif ($searchtext =~ s/^pickaxe\\://i) {
1878 $commit_search = 0;
1879 $pickaxe_search = 1;
1881 git_header_html();
1882 print "<div class=\"page_nav\">\n" .
1883 $cgi->a({-href => "$my_uri?p=$project;a=summary;h=$hash"}, "summary") .
1884 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1885 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1886 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1887 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1888 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1889 "<br/><br/>\n" .
1890 "</div>\n";
1892 print "<div>\n" .
1893 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1894 "</div>\n";
1895 print "<table cellspacing=\"0\">\n";
1896 my $alternate = 0;
1897 if ($commit_search) {
1898 $/ = "\0";
1899 open my $fd, "-|", "$gitbin/git-rev-list --header $hash";
1900 while (my $commit_text = <$fd>) {
1901 if (!grep m/$searchtext/i, $commit_text) {
1902 next;
1904 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
1905 next;
1907 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
1908 next;
1910 my @commit_lines = split "\n", $commit_text;
1911 my $commit = shift @commit_lines;
1912 my %co = git_read_commit($commit, \@commit_lines);
1913 if (!%co) {
1914 next;
1916 if ($alternate) {
1917 print "<tr class=\"dark\">\n";
1918 } else {
1919 print "<tr class=\"light\">\n";
1921 $alternate ^= 1;
1922 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1923 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
1924 "<td>" .
1925 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" . escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
1926 my $comment = $co{'comment'};
1927 foreach my $line (@$comment) {
1928 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
1929 my $lead = escapeHTML($1) || "";
1930 $lead = chop_str($lead, 30, 10);
1931 my $match = escapeHTML($2) || "";
1932 my $trail = escapeHTML($3) || "";
1933 $trail = chop_str($trail, 30, 10);
1934 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
1935 print chop_str($text, 80, 5) . "<br/>\n";
1938 print "</td>\n" .
1939 "<td class=\"link\">" .
1940 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1941 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$commit"}, "tree");
1942 print "</td>\n" .
1943 "</tr>\n";
1945 close $fd;
1948 if ($pickaxe_search) {
1949 $/ = "\n";
1950 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S$searchtext";
1951 undef %co;
1952 my @files;
1953 while (my $line = <$fd>) {
1954 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
1955 my %set;
1956 $set{'file'} = $6;
1957 $set{'from_id'} = $3;
1958 $set{'to_id'} = $4;
1959 $set{'id'} = $set{'to_id'};
1960 if ($set{'id'} =~ m/0{40}/) {
1961 $set{'id'} = $set{'from_id'};
1963 if ($set{'id'} =~ m/0{40}/) {
1964 next;
1966 push @files, \%set;
1967 } elsif ($line =~ m/^([0-9a-fA-F]{40}) /){
1968 if (%co) {
1969 if ($alternate) {
1970 print "<tr class=\"dark\">\n";
1971 } else {
1972 print "<tr class=\"light\">\n";
1974 $alternate ^= 1;
1975 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1976 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
1977 "<td>" .
1978 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}", -class => "list"}, "<b>" .
1979 escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
1980 while (my $setref = shift @files) {
1981 my %set = %$setref;
1982 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}", class => "list"},
1983 "<span style=\"color:#e00000\">" . escapeHTML($set{'file'}) . "</span>") .
1984 "<br/>\n";
1986 print "</td>\n" .
1987 "<td class=\"link\">" .
1988 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}"}, "commit") .
1989 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}"}, "tree");
1990 print "</td>\n" .
1991 "</tr>\n";
1993 %co = git_read_commit($1);
1996 close $fd;
1998 print "</table>\n";
1999 git_footer_html();
2002 sub git_shortlog {
2003 my $head = git_read_hash("$project/HEAD");
2004 if (!defined $hash) {
2005 $hash = $head;
2007 if (!defined $page) {
2008 $page = 0;
2010 git_header_html();
2011 print "<div class=\"page_nav\">\n" .
2012 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
2013 " | shortlog" .
2014 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
2015 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
2016 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
2017 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
2019 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2020 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
2021 my (@revlist) = map { chomp; $_ } <$fd>;
2022 close $fd;
2024 if ($hash ne $head || $page) {
2025 print $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "HEAD");
2026 } else {
2027 print "HEAD";
2029 if ($page > 0) {
2030 print " &sdot; " .
2031 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page-1), -accesskey => "p", -title => "Alt-p"}, "prev");
2032 } else {
2033 print " &sdot; prev";
2035 if ($#revlist >= (100 * ($page+1)-1)) {
2036 print " &sdot; " .
2037 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1), -accesskey => "n", -title => "Alt-n"}, "next");
2038 } else {
2039 print " &sdot; next";
2041 print "<br/>\n" .
2042 "</div>\n";
2043 print "<div>\n" .
2044 $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, "&nbsp;") .
2045 "</div>\n";
2046 print "<table cellspacing=\"0\">\n";
2047 my $alternate = 0;
2048 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2049 my $commit = $revlist[$i];
2050 my %co = git_read_commit($commit);
2051 my %ad = date_str($co{'author_epoch'});
2052 if ($alternate) {
2053 print "<tr class=\"dark\">\n";
2054 } else {
2055 print "<tr class=\"light\">\n";
2057 $alternate ^= 1;
2058 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2059 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2060 "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
2061 escapeHTML($co{'title_short'}) . "</b>") . "</td>\n" .
2062 "<td class=\"link\">" .
2063 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
2064 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
2065 "</td>\n" .
2066 "</tr>";
2068 if ($#revlist >= (100 * ($page+1)-1)) {
2069 print "<tr>\n" .
2070 "<td>" .
2071 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1), -title => "Alt-n"}, "next") .
2072 "</td>\n" .
2073 "</tr>\n";
2075 print "</table\n>";
2076 git_footer_html();