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
12 use CGI qw(:standard :escapeHTML -nosticky);
13 use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
19 my $my_url = $cgi->url();
20 my $my_uri = $cgi->url(-absolute => 1);
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\.\-_]+/) {
47 die_error(undef, "Invalid action parameter.");
49 if ($action eq "git-logo.png") {
52 } elsif ($action eq "opml") {
60 my $project = $cgi->param('p');
61 if (defined $project) {
62 if ($project =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
64 die_error(undef, "Non-canonical project parameter.");
66 if ($project =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~]/) {
68 die_error(undef, "Invalid character in project parameter.");
70 if (!(-d "$projectroot/$project")) {
72 die_error(undef, "No such directory.");
74 if (!(-e "$projectroot/$project/HEAD")) {
76 die_error(undef, "No such project.");
78 $rss_link = "<link rel=\"alternate\" title=\"$project log\" href=\"$my_uri?p=$project;a=rss\" type=\"application/rss+xml\"/>";
79 $ENV{'GIT_OBJECT_DIRECTORY'} = "$projectroot/$project/objects";
85 my $file_name = $cgi->param('f');
86 if (defined $file_name) {
87 if ($file_name =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
89 die_error(undef, "Non-canonical file parameter.");
91 if ($file_name =~ m/[^a-zA-Z0-9_\.\/\-\+\#\~\:\!]/) {
93 die_error(undef, "Invalid character in file parameter.");
97 my $hash = $cgi->param('h');
98 if (defined $hash && !($hash =~ m/^[0-9a-fA-F]{40}$/)) {
100 die_error(undef, "Invalid hash parameter.");
103 my $hash_parent = $cgi->param('hp');
104 if (defined $hash_parent && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
106 die_error(undef, "Invalid hash_parent parameter.");
109 my $hash_base = $cgi->param('hb');
110 if (defined $hash_base && !($hash_base =~ m/^[0-9a-fA-F]{40}$/)) {
112 die_error(undef, "Invalid parent hash parameter.");
115 my $page = $cgi->param('pg');
117 if ($page =~ m/^[^0-9]+$/) {
119 die_error(undef, "Invalid page parameter.");
124 my $searchtext = $cgi->param('s');
125 if (defined $searchtext) {
126 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
128 die_error(undef, "Invalid search parameter.");
130 $searchtext = quotemeta $searchtext;
133 if ($action eq "summary") {
136 } elsif ($action eq "branches") {
139 } elsif ($action eq "tags") {
142 } elsif ($action eq "blob") {
145 } elsif ($action eq "blob_plain") {
148 } elsif ($action eq "tree") {
151 } elsif ($action eq "rss") {
154 } elsif ($action eq "commit") {
157 } elsif ($action eq "log") {
160 } elsif ($action eq "blobdiff") {
163 } elsif ($action eq "blobdiff_plain") {
164 git_blobdiff_plain();
166 } elsif ($action eq "commitdiff") {
169 } elsif ($action eq "commitdiff_plain") {
170 git_commitdiff_plain();
172 } elsif ($action eq "history") {
175 } elsif ($action eq "search") {
178 } elsif ($action eq "shortlog") {
183 die_error(undef, "Unknown action.");
187 sub git_header_html {
188 my $status = shift || "200 OK";
191 if (defined $project) {
192 $title .= " - $project";
193 if (defined $action) {
194 $title .= "/$action";
197 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status);
199 <?xml version="1.0" encoding="utf-8"?>
200 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
201 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
202 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
204 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
205 <meta name="robots" content="index, nofollow"/>
206 <title>$title</title>
208 <style type="text/css">
209 body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
211 a:hover, a:visited, a:active { color:#880000; }
212 div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; }
213 div.page_header a:visited { color:#0000cc; }
214 div.page_header a:hover { color:#880000; }
215 div.page_nav { padding:8px; }
216 div.page_nav a:visited { color:#0000cc; }
217 div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
218 div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
219 div.page_footer_text { float:left; color:#555555; font-style:italic; }
220 div.page_body { padding:8px; }
222 display:block; padding:6px 8px;
223 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
225 a.title:hover { background-color: #d9d8d1; }
226 div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; }
227 div.log_body { padding:8px 8px 8px 150px; }
228 span.age { position:relative; float:left; width:142px; font-style:italic; }
231 font-size:10px; font-family:sans-serif; font-style:normal;
232 position:relative; float:left; width:136px;
234 div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; }
235 a.list { text-decoration:none; color:#000000; }
236 a.list:hover { text-decoration:underline; color:#880000; }
237 table { padding:8px 4px; }
238 th { padding:2px 5px; font-size:12px; text-align:left; }
239 tr.light:hover { background-color:#edece6; }
240 tr.dark { background-color:#f6f6f0; }
241 tr.dark:hover { background-color:#edece6; }
242 td { padding:2px 5px; font-size:12px; vertical-align:top; }
243 td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; }
244 div.pre { font-family:monospace; font-size:12px; white-space:pre; }
245 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
246 div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
247 div.search { margin:4px 8px; position:absolute; top:56px; right:12px }
249 float:right; padding:3px 0px; width:35px; line-height:10px;
250 border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
251 color:#ffffff; background-color:#ff6600;
252 font-weight:bold; font-family:sans-serif; font-size:10px;
253 text-align:center; text-decoration:none;
255 a.rss_logo:hover { background-color:#ee5500; }
260 print "<div class=\"page_header\">\n" .
261 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
262 "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
264 print $cgi->a({-href => $home_link}, "projects") . " / ";
265 if (defined $project) {
266 print $cgi->a({-href => "$my_uri?p=$project;a=summary"}, escapeHTML($project));
267 if (defined $action) {
271 if (!defined $searchtext) {
274 $cgi->param("a", "search");
275 print $cgi->startform(-method => "get", -action => "$my_uri") .
276 "<div class=\"search\">\n" .
277 $cgi->hidden(-name => "p") . "\n" .
278 $cgi->hidden(-name => "a") . "\n" .
279 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
281 $cgi->end_form() . "\n";
286 sub git_footer_html {
287 print "<div class=\"page_footer\">\n";
288 if (defined $project) {
289 my $descr = git_read_description($project);
290 if (defined $descr) {
291 print "<div class=\"page_footer_text\">" . escapeHTML($descr) . "</div>\n";
293 print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
295 print $cgi->a({-href => "$my_uri?a=opml", -class => "rss_logo"}, "RSS") . "\n";
303 my $status = shift || "403 Forbidden";
304 my $error = shift || "Malformed query, file missing or permission denied";
306 git_header_html($status);
307 print "<div class=\"page_body\">\n" .
309 "$status - $error\n" .
319 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
329 open my $fd, "$projectroot/$path" or return undef;
333 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
338 sub git_read_description {
341 open my $fd, "$projectroot/$path/description" or return undef;
352 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
353 while (my $line = <$fd>) {
355 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
357 } elsif ($line =~ m/^type (.+)$/) {
359 } elsif ($line =~ m/^tag (.+)$/) {
364 if (!defined $tag{'name'}) {
370 sub git_read_commit {
371 my $commit_id = shift;
372 my $commit_text = shift;
378 if (defined $commit_text) {
379 @commit_lines = @$commit_text;
381 open my $fd, "-|", "$gitbin/git-cat-file commit $commit_id" or return;
382 @commit_lines = map { chomp; $_ } <$fd>;
385 while (my $line = shift @commit_lines) {
386 last if $line eq "\n";
387 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
389 } elsif ($line =~ m/^parent ([0-9a-fA-F]{40})$/) {
391 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
393 $co{'author_epoch'} = $2;
394 $co{'author_tz'} = $3;
395 if ($co{'author'} =~ m/^([^<]+) </) {
396 $co{'author_name'} = $1;
398 $co{'author_name'} = $co{'author'};
400 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
401 $co{'committer'} = $1;
402 $co{'committer_epoch'} = $2;
403 $co{'committer_tz'} = $3;
404 $co{'committer_name'} = $co{'committer'};
405 $co{'committer_name'} =~ s/ <.*//;
408 if (!defined $co{'tree'}) {
411 $co{'id'} = $commit_id;
412 $co{'parents'} = \@parents;
413 $co{'parent'} = $parents[0];
414 $co{'comment'} = \@commit_lines;
415 foreach my $title (@commit_lines) {
417 $co{'title'} = chop_str($title, 80);
418 # remove leading stuff of merges to make the interesting part visible
419 if (length($title) > 50) {
420 $title =~ s/^Automatic //;
421 $title =~ s/^merge (of|with) /Merge ... /i;
422 if (length($title) > 50) {
423 $title =~ s/(http|rsync):\/\///;
425 if (length($title) > 50) {
426 $title =~ s/(master|www|rsync)\.//;
428 if (length($title) > 50) {
429 $title =~ s/kernel.org:?//;
431 if (length($title) > 50) {
432 $title =~ s/\/pub\/scm//;
435 $co{'title_short'} = chop_str($title, 50);
440 my $age = time - $co{'committer_epoch'};
442 if ($age > 60*60*24*365*2) {
443 $co{'age_string'} = (int $age/60/60/24/365);
444 $co{'age_string'} .= " years ago";
445 } elsif ($age > 60*60*24*(365/12)*2) {
446 $co{'age_string'} = int $age/60/60/24/(365/12);
447 $co{'age_string'} .= " months ago";
448 } elsif ($age > 60*60*24*7*2) {
449 $co{'age_string'} = int $age/60/60/24/7;
450 $co{'age_string'} .= " weeks ago";
451 } elsif ($age > 60*60*24*2) {
452 $co{'age_string'} = int $age/60/60/24;
453 $co{'age_string'} .= " days ago";
454 } elsif ($age > 60*60*2) {
455 $co{'age_string'} = int $age/60/60;
456 $co{'age_string'} .= " hours ago";
457 } elsif ($age > 60*2) {
458 $co{'age_string'} = int $age/60;
459 $co{'age_string'} .= " min ago";
461 $co{'age_string'} = int $age;
462 $co{'age_string'} .= " sec ago";
464 $co{'age_string'} .= " right now";
471 my $from_name = shift;
474 my $format = shift || "html";
476 my $from_tmp = "/dev/null";
477 my $to_tmp = "/dev/null";
480 # create tmp from-file
482 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
483 open my $fd2, "> $from_tmp";
484 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
493 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
494 open my $fd2, "> $to_tmp";
495 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
502 open my $fd, "-|", "/usr/bin/diff -u -p -L $from_name -L $to_name $from_tmp $to_tmp";
503 if ($format eq "plain") {
508 while (my $line = <$fd>) {
510 my $char = substr($line, 0, 1);
513 $color = " style=\"color:#008800;\"";
514 } elsif ($char eq "-") {
515 $color = " style=\"color:#cc0000;\"";
516 } elsif ($char eq "@") {
517 $color = " style=\"color:#990099;\"";
518 } elsif ($char eq "\\") {
522 while ((my $pos = index($line, "\t")) != -1) {
523 if (my $count = (8 - (($pos-1) % 8))) {
524 my $spaces = ' ' x $count;
525 $line =~ s/\t/$spaces/;
528 print "<div class=\"pre\"$color>" . escapeHTML($line) . "</div>\n";
542 my $mode = oct shift;
544 if (S_ISDIR($mode & S_IFMT)) {
546 } elsif (S_ISLNK($mode)) {
548 } elsif (S_ISREG($mode)) {
549 # git cares only about the executable bit
550 if ($mode & S_IXUSR) {
563 my $add_len = shift || 10;
565 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})/;
567 if ($chopped ne $str) {
574 my $mode = oct shift;
576 if (S_ISDIR($mode & S_IFMT)) {
578 } elsif (S_ISLNK($mode)) {
580 } elsif (S_ISREG($mode)) {
589 my $tz = shift || "-0000";
592 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
593 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
594 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
595 $date{'hour'} = $hour;
596 $date{'minute'} = $min;
597 $date{'mday'} = $mday;
598 $date{'day'} = $days[$wday];
599 $date{'month'} = $months[$mon];
600 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
601 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
603 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
604 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
605 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
606 $date{'hour_local'} = $hour;
607 $date{'minute_local'} = $min;
608 $date{'tz_local'} = $tz;
612 # git-logo (cached in browser for one day)
614 print $cgi->header(-type => 'image/png', -expires => '+1d');
615 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
616 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
617 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
618 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
619 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
620 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
621 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
622 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
623 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
624 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
625 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
626 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
627 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
628 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
634 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
635 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
636 if (!defined $gcos) {
640 $owner =~ s/[,;].*$//;
644 sub git_read_projects {
647 if (-d $projects_list) {
648 # search in directory
649 my $dir = $projects_list;
650 opendir my $dh, $dir or return undef;
651 while (my $dir = readdir($dh)) {
652 if (-e "$projectroot/$dir/HEAD") {
660 } elsif (-f $projects_list) {
661 # read from file(url-encoded):
662 # 'git%2Fgit.git Linus+Torvalds'
663 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
664 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
665 open my $fd , $projects_list or return undef;
666 while (my $line = <$fd>) {
668 my ($path, $owner) = split ' ', $line;
669 $path = unescape($path);
670 $owner = unescape($owner);
671 if (!defined $path) {
674 if (-e "$projectroot/$path/HEAD") {
684 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
688 sub git_project_list {
689 my @list = git_read_projects();
691 die_error(undef, "No project found.");
695 print "<div class=\"index_include\">\n";
696 open (my $fd, $home_text);
701 print "<table cellspacing=\"0\">\n" .
703 "<th>Project</th>\n" .
704 "<th>Description</th>\n" .
706 "<th>last change</th>\n" .
710 foreach my $pr (@list) {
712 my $head = git_read_hash("$proj{'path'}/HEAD");
713 if (!defined $head) {
716 $ENV{'GIT_OBJECT_DIRECTORY'} = "$projectroot/$proj{'path'}/objects";
717 my %co = git_read_commit($head);
721 my $descr = git_read_description($proj{'path'}) || "";
722 $descr = chop_str($descr, 25, 5);
723 # get directory owner if not already specified
724 if (!defined $proj{'owner'}) {
725 $proj{'owner'} = get_file_owner("$projectroot/$proj{'path'}") || "";
728 print "<tr class=\"dark\">\n";
730 print "<tr class=\"light\">\n";
733 print "<td>" . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary", -class => "list"}, escapeHTML($proj{'path'})) . "</td>\n" .
734 "<td>$descr</td>\n" .
735 "<td><i>" . chop_str($proj{'owner'}, 15) . "</i></td>\n";
737 if ($co{'age'} < 60*60*2) {
738 $colored_age = "<span style =\"color: #009900;\"><b><i>$co{'age_string'}</i></b></span>";
739 } elsif ($co{'age'} < 60*60*24*2) {
740 $colored_age = "<span style =\"color: #009900;\"><i>$co{'age_string'}</i></span>";
742 $colored_age = "<i>$co{'age_string'}</i>";
744 print "<td>$colored_age</td>\n" .
745 "<td class=\"link\">" .
746 $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary"}, "summary") .
747 " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=shortlog"}, "shortlog") .
748 " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=log"}, "log") .
760 opendir my $dh, "$projectroot/$project/$ref_dir";
761 my @refs = grep !m/^\./, readdir $dh;
763 foreach my $ref_file (@refs) {
764 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
765 my $type = git_get_type($ref_id) || next;
768 if ($type eq "tag") {
769 my %tag = git_read_tag($ref_id);
770 if ($tag{'type'} eq "commit") {
771 %co = git_read_commit($tag{'object'});
773 $ref_item{'type'} = $tag{'type'};
774 $ref_item{'name'} = $tag{'name'};
775 $ref_item{'id'} = $tag{'object'};
776 } elsif ($type eq "commit"){
777 %co = git_read_commit($ref_id);
778 $ref_item{'type'} = "commit";
779 $ref_item{'name'} = $ref_file;
780 $ref_item{'title'} = $co{'title'};
781 $ref_item{'id'} = $ref_id;
783 $ref_item{'epoch'} = $co{'committer_epoch'} || 0;
784 $ref_item{'age'} = $co{'age_string'} || "unknown";
786 push @reflist, \%ref_item;
789 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
794 my $descr = git_read_description($project) || "none";
795 my $head = git_read_hash("$project/HEAD");
796 my %co = git_read_commit($head);
797 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
800 if (-f $projects_list) {
801 open (my $fd , $projects_list);
802 while (my $line = <$fd>) {
804 my ($pr, $ow) = split ' ', $line;
807 if ($pr eq $project) {
814 if (!defined $owner) {
815 $owner = get_file_owner("$projectroot/$project");
819 print "<div class=\"page_nav\">\n" .
821 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
822 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
823 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
824 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
825 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree"}, "tree") .
828 print "<div class=\"title\"> </div>\n";
829 print "<table cellspacing=\"0\">\n" .
830 "<tr><td>description</td><td>" . escapeHTML($descr) . "</td></tr>\n" .
831 "<tr><td>owner</td><td>$owner</td></tr>\n" .
832 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
834 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
835 my (@revlist) = map { chomp; $_ } <$fd>;
838 $cgi->a({-href => "$my_uri?p=$project;a=shortlog", -class => "title"}, "shortlog") .
841 print "<table cellspacing=\"0\">\n";
843 foreach my $commit (@revlist) {
844 my %co = git_read_commit($commit);
845 my %ad = date_str($co{'author_epoch'});
847 print "<tr class=\"dark\">\n";
849 print "<tr class=\"light\">\n";
853 print "<td><i>$co{'age_string'}</i></td>\n" .
854 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
856 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"},
857 "<b>" . escapeHTML($co{'title_short'}) . "</b>") .
859 "<td class=\"link\">" .
860 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
861 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
865 print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "...") . "</td>\n" .
872 my $taglist = git_read_refs("refs/tags");
873 if (defined @$taglist) {
875 $cgi->a({-href => "$my_uri?p=$project;a=tags", -class => "title"}, "tags") .
878 print "<table cellspacing=\"0\">\n";
880 foreach my $entry (@$taglist) {
883 print "<tr class=\"dark\">\n";
885 print "<tr class=\"light\">\n";
889 print "<td><i>$tag{'age'}</i></td>\n" .
891 $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}", -class => "list"}, "<b>" .
892 escapeHTML($tag{'name'}) . "</b>") .
894 "<td class=\"link\">" .
895 $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, $tag{'type'});
896 if ($tag{'type'} eq "commit") {
897 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}"}, "shortlog") .
898 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log");
903 print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=tags"}, "...") . "</td>\n" .
911 my $branchlist = git_read_refs("refs/heads");
912 if (defined @$branchlist) {
914 $cgi->a({-href => "$my_uri?p=$project;a=branches", -class => "title"}, "branches") .
917 print "<table cellspacing=\"0\">\n";
919 foreach my $entry (@$branchlist) {
922 print "<tr class=\"dark\">\n";
924 print "<tr class=\"light\">\n";
928 print "<td><i>$tag{'age'}</i></td>\n" .
930 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}", -class => "list"},
931 "<b>" . escapeHTML($tag{'name'}) . "</b>") .
933 "<td class=\"link\">" .
934 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}"}, "shortlog") .
935 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log") .
939 print "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=branches"}, "...") . "</td>\n" .
950 my $head = git_read_hash("$project/HEAD");
952 print "<div class=\"page_nav\">\n" .
953 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
954 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
955 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
956 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
957 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
958 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;hb=$head"}, "tree") . "<br/>\n" .
961 my $taglist = git_read_refs("refs/tags");
963 $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, " ") .
965 print "<table cellspacing=\"0\">\n";
967 if (defined @$taglist) {
968 foreach my $entry (@$taglist) {
971 print "<tr class=\"dark\">\n";
973 print "<tr class=\"light\">\n";
976 print "<td><i>$tag{'age'}</i></td>\n" .
978 $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}", -class => "list"},
979 "<b>" . escapeHTML($tag{'name'}) . "</b>") .
981 "<td class=\"link\">" .
982 $cgi->a({-href => "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, $tag{'type'});
983 if ($tag{'type'} eq "commit") {
984 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}"}, "shortlog") .
985 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log");
996 my $head = git_read_hash("$project/HEAD");
998 print "<div class=\"page_nav\">\n" .
999 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1000 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1001 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1002 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
1003 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
1004 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;hb=$head"}, "tree") . "<br/>\n" .
1007 my $taglist = git_read_refs("refs/heads");
1009 $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, " ") .
1011 print "<table cellspacing=\"0\">\n";
1013 if (defined @$taglist) {
1014 foreach my $entry (@$taglist) {
1017 print "<tr class=\"dark\">\n";
1019 print "<tr class=\"light\">\n";
1022 print "<td><i>$tag{'age'}</i></td>\n" .
1024 $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}", -class => "list"}, "<b>" . escapeHTML($tag{'name'}) . "</b>") .
1026 "<td class=\"link\">" .
1027 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$tag{'id'}"}, "shortog") .
1028 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log") .
1037 sub git_get_hash_by_path {
1039 my $path = shift || return undef;
1042 my @parts = split '/', $path;
1043 while (my $part = shift @parts) {
1044 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1045 my (@entries) = map { chomp; $_ } <$fd>;
1046 close $fd or return undef;
1047 foreach my $line (@entries) {
1048 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1049 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1054 if ($t_name eq $part) {
1058 if ($t_type eq "tree") {
1068 if (!defined $hash && defined $file_name) {
1069 my $base = $hash_base || git_read_hash("$project/HEAD");
1070 $hash = git_get_hash_by_path($base, $file_name, "blob");
1072 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1073 my $base = $file_name || "";
1075 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1076 print "<div class=\"page_nav\">\n" .
1077 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1078 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1079 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1080 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1081 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1082 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") . "<br/>\n";
1083 print $cgi->a({-href => "$my_uri?p=$project;a=blob_plain;h=$hash"}, "plain") . "<br/>\n" .
1086 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) .
1089 print "<div class=\"page_nav\">\n" .
1090 "<br/><br/></div>\n" .
1091 "<div class=\"title\">$hash</div>\n";
1093 if (defined $file_name) {
1094 print "<div class=\"page_path\"><b>$file_name</b></div>\n";
1096 print "<div class=\"page_body\">\n";
1098 while (my $line = <$fd>) {
1101 while ((my $pos = index($line, "\t")) != -1) {
1102 if (my $count = (8 - ($pos % 8))) {
1103 my $spaces = ' ' x $count;
1104 $line =~ s/\t/$spaces/;
1107 printf "<div class=\"pre\"><span style=\"color:#999999;\">%4i</span> %s</div>\n", $nr, escapeHTML($line);
1109 close $fd or print "Reading blob failed.\n";
1114 sub git_blob_plain {
1115 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1116 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1124 if (!defined $hash) {
1125 $hash = git_read_hash("$project/HEAD");
1126 if (defined $file_name) {
1127 my $base = $hash_base || git_read_hash("$project/HEAD");
1128 $hash = git_get_hash_by_path($base, $file_name, "tree");
1130 if (!defined $hash_base) {
1131 $hash_base = git_read_hash("$project/HEAD");
1134 open my $fd, "-|", "$gitbin/git-ls-tree $hash" or die_error(undef, "Open git-ls-tree failed.");
1135 my (@entries) = map { chomp; $_ } <$fd>;
1136 close $fd or die_error(undef, "Reading tree failed.");
1142 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1143 $base_key = ";hb=$hash_base";
1144 print "<div class=\"page_nav\">\n" .
1145 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1146 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash_base"}, "shortlog") .
1147 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash_base"}, "log") .
1148 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1149 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1154 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1157 print "<div class=\"page_nav\">\n";
1158 print "<br/><br/></div>\n";
1159 print "<div class=\"title\">$hash</div>\n";
1161 if (defined $file_name) {
1162 $base = "$file_name/";
1163 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1165 print "<div class=\"page_path\"><b>/</b></div>\n";
1167 print "<div class=\"page_body\">\n";
1168 print "<table cellspacing=\"0\">\n";
1170 foreach my $line (@entries) {
1171 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1172 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1177 $file_key = ";f=$base$t_name";
1179 print "<tr class=\"dark\">\n";
1181 print "<tr class=\"light\">\n";
1184 print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n";
1185 if ($t_type eq "blob") {
1186 print "<td class=\"list\">" .
1187 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key, -class => "list"}, $t_name) .
1189 "<td class=\"link\">" .
1190 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key}, "blob") .
1191 " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base" . $file_key}, "history") .
1193 } elsif ($t_type eq "tree") {
1194 print "<td class=\"list\">" .
1195 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key}, $t_name) .
1197 "<td class=\"link\">" .
1198 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key}, "tree") .
1203 print "</table>\n" .
1209 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1210 open my $fd, "-|", "$gitbin/git-rev-list --max-count=20 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");
1211 my (@revlist) = map { chomp; $_ } <$fd>;
1212 close $fd or die_error(undef, "Reading rev-list failed.");
1214 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1215 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1216 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1217 print "<channel>\n";
1218 print "<title>$project</title>\n".
1219 "<link>" . escapeHTML("$my_url/$project/log") . "</link>\n".
1220 "<description>$project log</description>\n".
1221 "<language>en</language>\n";
1223 foreach my $commit (@revlist) {
1224 my %co = git_read_commit($commit);
1225 my %cd = date_str($co{'committer_epoch'});
1228 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . escapeHTML($co{'title'}) .
1230 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1231 "<link>" . escapeHTML("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1232 "<description>" . escapeHTML($co{'title'}) . "</description>\n" .
1233 "<content:encoded>" .
1235 my $comment = $co{'comment'};
1236 foreach my $line (@$comment) {
1237 print "$line<br/>\n";
1240 "</content:encoded>\n" .
1243 print "</channel></rss>";
1247 my @list = git_read_projects();
1249 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1250 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1251 "<opml version=\"1.0\">\n".
1253 " <title>Git OPML Export</title>\n".
1256 "<outline text=\"git RSS feeds\">\n";
1258 foreach my $pr (@list) {
1260 my $head = git_read_hash("$proj{'path'}/HEAD");
1261 if (!defined $head) {
1264 $ENV{'GIT_OBJECT_DIRECTORY'} = "$projectroot/$proj{'path'}/objects";
1265 my %co = git_read_commit($head);
1270 my $path = escapeHTML(chop_str($proj{'path'}, 25, 5));
1271 my $rss = "$my_url?p=$proj{'path'};a=rss";
1272 my $html = "$my_url?p=$proj{'path'};a=log";
1273 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1275 print "</outline>\n".
1281 my $head = git_read_hash("$project/HEAD");
1282 if (!defined $hash) {
1285 if (!defined $page) {
1289 print "<div class=\"page_nav\">\n";
1290 print $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1291 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1293 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1294 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1295 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
1297 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1298 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1299 my (@revlist) = map { chomp; $_ } <$fd>;
1302 if ($hash ne $head || $page) {
1303 print $cgi->a({-href => "$my_uri?p=$project;a=log"}, "HEAD");
1309 $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash;pg=" . ($page-1), -accesskey => "p", -title => "Alt-p"}, "prev");
1311 print " ⋅ prev";
1313 if ($#revlist >= (100 * ($page+1)-1)) {
1315 $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash;pg=" . ($page+1), -accesskey => "n", -title => "Alt-n"}, "next");
1317 print " ⋅ next";
1323 $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, " ") .
1325 my %co = git_read_commit($hash);
1326 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1328 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1329 my $commit = $revlist[$i];
1330 my %co = git_read_commit($commit);
1332 my %ad = date_str($co{'author_epoch'});
1334 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
1335 "<span class=\"age\">$co{'age_string'}</span>" . escapeHTML($co{'title'})) . "\n" .
1337 print "<div class=\"title_text\">\n" .
1338 "<div class=\"log_link\">\n" .
1339 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1340 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
1343 "<i>" . escapeHTML($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1345 "<div class=\"log_body\">\n";
1346 my $comment = $co{'comment'};
1348 foreach my $line (@$comment) {
1349 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1360 print escapeHTML($line) . "<br/>\n";
1371 my %co = git_read_commit($hash);
1373 die_error(undef, "Unknown commit object.");
1375 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1376 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1380 if (!defined $co{'parent'}) {
1383 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $co{'parent'} $hash" or die_error(undef, "Open failed.");
1384 @difftree = map { chomp; $_ } <$fd>;
1385 close $fd or die_error(undef, "Reading diff-tree failed.");
1387 print "<div class=\"page_nav\">\n" .
1388 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1389 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1390 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1392 if (defined $co{'parent'}) {
1393 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff");
1395 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "\n" .
1396 "<br/><br/></div>\n";
1397 if (defined $co{'parent'}) {
1399 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1403 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1406 print "<div class=\"title_text\">\n" .
1407 "<table cellspacing=\"0\">\n";
1408 print "<tr><td>author</td><td>" . escapeHTML($co{'author'}) . "</td></tr>\n".
1410 "<td></td><td> $ad{'rfc2822'}";
1411 if ($ad{'hour_local'} < 6) {
1412 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1414 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1418 print "<tr><td>committer</td><td>" . escapeHTML($co{'committer'}) . "</td></tr>\n";
1419 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1420 print "<tr><td>commit</td><td style=\"font-family:monospace\">$hash</td></tr>\n";
1423 "<td style=\"font-family:monospace\">" .
1424 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", class => "list"}, $co{'tree'}) .
1426 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1429 my $parents = $co{'parents'};
1430 foreach my $par (@$parents) {
1433 "<td style=\"font-family:monospace\">" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par", class => "list"}, $par) . "</td>" .
1434 "<td class=\"link\">" .
1435 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, "commit") .
1436 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash;hp=$par"}, "commitdiff") .
1442 print "<div class=\"page_body\">\n";
1443 my $comment = $co{'comment'};
1446 foreach my $line (@$comment) {
1447 # print only one empty line
1449 if ($empty || $signed) {
1456 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1458 print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
1461 print escapeHTML($line) . "<br/>\n";
1465 print "<div class=\"list_head\">\n";
1466 if ($#difftree > 10) {
1467 print(($#difftree + 1) . " files changed:\n");
1470 print "<table cellspacing=\"0\">\n";
1472 foreach my $line (@difftree) {
1473 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1474 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1475 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/;
1481 my $similarity = $6;
1483 #print "$line ($status)<br/>\n";
1485 print "<tr class=\"dark\">\n";
1487 print "<tr class=\"light\">\n";
1490 if ($status eq "N") {
1492 if (S_ISREG(oct $to_mode)) {
1493 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1496 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hp=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "</td>\n" .
1497 "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1498 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob") . "</td>\n";
1499 } elsif ($status eq "D") {
1501 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "</td>\n" .
1502 "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1503 "<td class=\"link\">" .
1504 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, "blob") .
1505 " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") .
1507 } elsif ($status eq "M" || $status eq "T") {
1508 my $mode_chnge = "";
1509 if ($from_mode != $to_mode) {
1510 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1511 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1512 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1514 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1515 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1516 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1517 } elsif (S_ISREG($to_mode)) {
1518 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1521 $mode_chnge .= "]</span>\n";
1524 if ($to_id ne $from_id) {
1525 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file));
1527 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file));
1530 "<td>$mode_chnge</td>\n" .
1531 "<td class=\"link\">";
1532 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob");
1533 if ($to_id ne $from_id) {
1534 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"}, "diff");
1536 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "\n";
1538 } elsif ($status eq "R") {
1539 my ($from_file, $to_file) = split "\t", $file;
1541 if ($from_mode != $to_mode) {
1542 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1545 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file", -class => "list"}, escapeHTML($to_file)) . "</td>\n" .
1546 "<td><span style=\"color: #777777;\">[moved from " .
1547 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file", -class => "list"}, escapeHTML($from_file)) .
1548 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1549 "<td class=\"link\">" .
1550 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"}, "blob");
1551 if ($to_id ne $from_id) {
1552 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file"}, "diff");
1563 mkdir($git_temp, 0700);
1565 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1566 print "<div class=\"page_nav\">\n" .
1567 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1568 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1569 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1570 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1571 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1572 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") .
1574 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent"}, "plain") .
1577 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1580 print "<div class=\"page_nav\">\n" .
1581 "<br/><br/></div>\n" .
1582 "<div class=\"title\">$hash vs $hash_parent</div>\n";
1584 if (defined $file_name) {
1585 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1587 print "<div class=\"page_body\">\n" .
1588 "<div class=\"diff_info\">blob:" .
1589 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name"}, $hash_parent) .
1591 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name"}, $hash) .
1593 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
1598 sub git_blobdiff_plain {
1599 mkdir($git_temp, 0700);
1600 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1601 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
1604 sub git_commitdiff {
1605 mkdir($git_temp, 0700);
1606 my %co = git_read_commit($hash);
1608 die_error(undef, "Unknown commit object.");
1610 if (!defined $hash_parent) {
1611 $hash_parent = $co{'parent'};
1613 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1614 my (@difftree) = map { chomp; $_ } <$fd>;
1615 close $fd or die_error(undef, "Reading diff-tree failed.");
1618 print "<div class=\"page_nav\">\n" .
1619 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1620 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1621 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1622 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1624 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "<br/>\n";
1625 print $cgi->a({-href => "$my_uri?p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent"}, "plain") . "\n" .
1628 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1630 print "<div class=\"page_body\">\n";
1631 my $comment = $co{'comment'};
1634 my @log = @$comment;
1635 # remove first and empty lines after that
1637 while (defined $log[0] && $log[0] eq "") {
1640 foreach my $line (@log) {
1641 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1652 print escapeHTML($line) . "<br/>\n";
1655 foreach my $line (@difftree) {
1656 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1657 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1658 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1665 if ($status eq "N") {
1666 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
1667 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id) . "(new)" .
1669 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
1670 } elsif ($status eq "D") {
1671 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
1672 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) . "(deleted)" .
1674 git_diff_print($from_id, "a/$file", undef, "/dev/null");
1675 } elsif ($status eq "M") {
1676 if ($from_id ne $to_id) {
1677 print "<div class=\"diff_info\">" .
1678 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) .
1680 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id);
1682 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
1691 sub git_commitdiff_plain {
1692 mkdir($git_temp, 0700);
1693 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1694 my (@difftree) = map { chomp; $_ } <$fd>;
1695 close $fd or die_error(undef, "Reading diff-tree failed.");
1697 my %co = git_read_commit($hash);
1698 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1699 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1700 my $comment = $co{'comment'};
1701 print "Author: $co{'author'}\n" .
1702 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
1703 "Source: $my_url?p=$project;a=commitdiff;h=$hash\n" .
1705 foreach my $line (@$comment) {;
1709 foreach my $line (@difftree) {
1710 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1715 if ($status eq "N") {
1716 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
1717 } elsif ($status eq "D") {
1718 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
1719 } elsif ($status eq "M") {
1720 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
1726 if (!defined $hash) {
1727 $hash = git_read_hash("$project/HEAD");
1729 my %co = git_read_commit($hash);
1731 die_error(undef, "Unknown commit object.");
1734 print "<div class=\"page_nav\">\n" .
1735 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1736 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1737 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1738 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1739 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1740 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1744 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1746 print "<div class=\"page_path\"><b>/$file_name</b><br/></div>\n";
1748 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin $file_name";
1750 print "<table cellspacing=\"0\">\n";
1752 while (my $line = <$fd>) {
1753 if ($line =~ m/^([0-9a-fA-F]{40}) /){
1757 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
1758 my %co = git_read_commit($commit);
1763 print "<tr class=\"dark\">\n";
1765 print "<tr class=\"light\">\n";
1768 print "<td><i>$co{'age_string'}</i></td>\n" .
1769 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1770 "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
1771 escapeHTML(chop_str($co{'title'}, 50)) . "</b>") . "</td>\n" .
1772 "<td class=\"link\">" .
1773 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1774 " | " . $cgi->a({-href => "$my_uri?p=$project;a=blob;hb=$commit;f=$file_name"}, "blob");
1775 my $blob = git_get_hash_by_path($hash, $file_name);
1776 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1777 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
1779 $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name"},
1793 if (!defined $searchtext) {
1794 die_error("", "Text field empty.");
1796 if (!defined $hash) {
1797 $hash = git_read_hash("$project/HEAD");
1799 my %co = git_read_commit($hash);
1801 die_error(undef, "Unknown commit object.");
1803 # pickaxe may take all resources of your box and run for several minutes
1804 # with every query - so decide by yourself how public you make this feature :)
1805 my $commit_search = 1;
1806 my $author_search = 0;
1807 my $committer_search = 0;
1808 my $pickaxe_search = 0;
1809 if ($searchtext =~ s/^author\\://i) {
1811 } elsif ($searchtext =~ s/^committer\\://i) {
1812 $committer_search = 1;
1813 } elsif ($searchtext =~ s/^pickaxe\\://i) {
1815 $pickaxe_search = 1;
1818 print "<div class=\"page_nav\">\n" .
1819 $cgi->a({-href => "$my_uri?p=$project;a=summary;h=$hash"}, "summary") .
1820 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1821 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1822 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1823 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1824 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1829 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1831 print "<table cellspacing=\"0\">\n";
1833 if ($commit_search) {
1835 open my $fd, "-|", "$gitbin/git-rev-list --header $hash";
1836 while (my $commit_text = <$fd>) {
1837 if (!grep m/$searchtext/i, $commit_text) {
1840 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
1843 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
1846 my @commit_lines = split "\n", $commit_text;
1847 my $commit = shift @commit_lines;
1848 my %co = git_read_commit($commit, \@commit_lines);
1853 print "<tr class=\"dark\">\n";
1855 print "<tr class=\"light\">\n";
1858 print "<td><i>$co{'age_string'}</i></td>\n" .
1859 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
1861 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" . escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
1862 my $comment = $co{'comment'};
1863 foreach my $line (@$comment) {
1864 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
1865 my $lead = escapeHTML($1) || "";
1866 $lead = chop_str($lead, 30, 10);
1867 my $match = escapeHTML($2) || "";
1868 my $trail = escapeHTML($3) || "";
1869 $trail = chop_str($trail, 30, 10);
1870 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
1871 print chop_str($text, 80, 5) . "<br/>\n";
1875 "<td class=\"link\">" .
1876 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1877 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$commit"}, "tree");
1884 if ($pickaxe_search) {
1886 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S$searchtext";
1889 while (my $line = <$fd>) {
1890 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
1893 $set{'from_id'} = $3;
1895 $set{'id'} = $set{'to_id'};
1896 if ($set{'id'} =~ m/0{40}/) {
1897 $set{'id'} = $set{'from_id'};
1899 if ($set{'id'} =~ m/0{40}/) {
1903 } elsif ($line =~ m/^([0-9a-fA-F]{40}) /){
1906 print "<tr class=\"dark\">\n";
1908 print "<tr class=\"light\">\n";
1911 print "<td><i>$co{'age_string'}</i></td>\n" .
1912 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
1914 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}", -class => "list"}, "<b>" .
1915 escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
1916 while (my $setref = shift @files) {
1918 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}", class => "list"},
1919 "<span style=\"color:#e00000\">" . escapeHTML($set{'file'}) . "</span>") .
1923 "<td class=\"link\">" .
1924 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}"}, "commit") .
1925 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}"}, "tree");
1929 %co = git_read_commit($1);
1939 my $head = git_read_hash("$project/HEAD");
1940 if (!defined $hash) {
1943 if (!defined $page) {
1947 print "<div class=\"page_nav\">\n" .
1948 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1950 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1951 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1952 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1953 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
1955 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1956 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1957 my (@revlist) = map { chomp; $_ } <$fd>;
1960 if ($hash ne $head || $page) {
1961 print $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "HEAD");
1967 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page-1), -accesskey => "p", -title => "Alt-p"}, "prev");
1969 print " ⋅ prev";
1971 if ($#revlist >= (100 * ($page+1)-1)) {
1973 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1), -accesskey => "n", -title => "Alt-n"}, "next");
1975 print " ⋅ next";
1980 $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, " ") .
1982 print "<table cellspacing=\"0\">\n";
1984 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1985 my $commit = $revlist[$i];
1986 my %co = git_read_commit($commit);
1987 my %ad = date_str($co{'author_epoch'});
1989 print "<tr class=\"dark\">\n";
1991 print "<tr class=\"light\">\n";
1994 print "<td><i>$co{'age_string'}</i></td>\n" .
1995 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1996 "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
1997 escapeHTML($co{'title_short'}) . "</b>") . "</td>\n" .
1998 "<td class=\"link\">" .
1999 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
2000 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
2004 if ($#revlist >= (100 * ($page+1)-1)) {
2007 $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1), -title => "Alt-n"}, "next") .