v148
[gitweb.git] / gitweb.cgi
index 34dc9bc80d690581313938ad4904b6101ec12a14..e738ea2ba44518d346ffee94d23216324078e075 100755 (executable)
 use strict;
 use warnings;
 use CGI qw(:standard :escapeHTML);
+use CGI::Util qw(unescape);
 use CGI::Carp qw(fatalsToBrowser);
 use Fcntl ':mode';
 
 my $cgi = new CGI;
-my $version =          "142";
+my $version =          "148";
 my $my_url =           $cgi->url();
 my $my_uri =           $cgi->url(-absolute => 1);
 my $rss_link = "";
@@ -36,7 +37,7 @@ my $home_text =               "indextext.html";
 
 # source of projects list
 #my $projects_list = $projectroot;
-my $projects_list = "index/index.txt";
+my $projects_list = "index/index.aux";
 
 # input validation and dispatch
 my $action = $cgi->param('a');
@@ -563,7 +564,9 @@ sub git_project_list {
                open my $fd , $projects_list || return undef;
                while (my $line = <$fd>) {
                        chomp $line;
-                       my ($path, $owner) = split ':', $line;
+                       my ($path, $owner) = split ' ', $line;
+                       $path = unescape($path);
+                       $owner = unescape($owner);
                        if (!defined $path) {
                                next;
                        }
@@ -618,7 +621,7 @@ sub git_project_list {
                        $proj{'owner'} = get_file_owner("$projectroot/$proj{'path'}") || "";
                }
                print "<tr>\n" .
-                     "<td>" . $cgi->a({-href => "$my_uri?p=" . $proj{'path'} . ";a=summary"}, escapeHTML($proj{'path'})) . "</td>\n" .
+                     "<td>" . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary"}, escapeHTML($proj{'path'})) . "</td>\n" .
                      "<td>$descr</td>\n" .
                      "<td><i>$proj{'owner'}</i></td>\n";
                my $colored_age;
@@ -634,7 +637,8 @@ sub git_project_list {
                      $cgi->a({-href => "$my_uri?p=$proj{'path'};a=summary"}, "summary") .
                      " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=log"}, "log") .
                      " | " . $cgi->a({-href => "$my_uri?p=$proj{'path'};a=tree"}, "tree") .
-                     "</td>\n";
+                     "</td>\n" .
+                     "</tr>\n";
        }
        print "</table>\n" .
              "<br/>\n" .
@@ -690,7 +694,9 @@ sub git_summary {
                open (my $fd , $projects_list);
                while (my $line = <$fd>) {
                        chomp $line;
-                       my ($pr, $ow) = split ':', $line;
+                       my ($pr, $ow) = split ' ', $line;
+                       $pr = unescape($pr);
+                       $ow = unescape($ow);
                        if ($pr eq $project) {
                                $owner = $ow;
                                last;
@@ -705,7 +711,7 @@ sub git_summary {
        git_header_html();
        print "<div class=\"page_nav\">\n" .
              $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
-             " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;hb=$head"}, "latest tree") .
+             " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree"}, "tree") .
              "<br/><br/>\n" .
              "</div>\n";
        print "<div class=\"title\">project</div>\n";
@@ -715,7 +721,7 @@ sub git_summary {
              "<tr><td>owner</td><td>$owner</td></tr>\n" .
              "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
              "</table>\n" .
-             "</div><br/>\n";
+             "<br/></div>\n";
        open my $fd, "-|", "$gitbin/git-rev-list --max-count=11 " . git_read_hash("$project/HEAD") || die_error(undef, "Open failed.");
        my (@revlist) = map { chomp; $_ } <$fd>;
        close $fd;
@@ -728,14 +734,14 @@ sub git_summary {
                my %ad = date_str($co{'author_epoch'});
                print "<div class=\"list\">\n" .
                      $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"},
-                     "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
+                     "<span class=\"log_age\">$co{'age_string'}</span>" . escapeHTML($co{'title'})) . "\n" .
                      "</div>\n";
                if (--$i == 0) {
                        print "<div class=\"list\">" . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "...") . "</div>\n";
                        last;
                }
        }
-       print "<br/>\n";
+       print "<div class=\"list\"><br/></div>\n";
 
        my $taglist = git_read_tags();
        if (defined @$taglist) {
@@ -754,8 +760,8 @@ sub git_summary {
                                last;
                        }
                }
+               print "<div class=\"list\"><br/></div>\n";
        }
-       print "<br/>\n";
        git_footer_html();
 }
 
@@ -781,7 +787,7 @@ sub git_tags {
                              "</div>\n";
                }
        }
-       print "<br/>\n";
+       print "<div class=\"list\"><br/></div>\n";
        git_footer_html();
 }
 
@@ -827,7 +833,7 @@ sub git_blob {
                print "<div class=\"page_nav\">\n" .
                      $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
-                     " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash_base"}, "tree");
+                     " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree");
                if (defined $file_name) {
                        print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base;f=$file_name"}, "history");
                }
@@ -866,6 +872,9 @@ sub git_tree {
                        $hash = git_get_hash_by_path($base, $file_name, "tree");
                }
        }
+       if (!defined $hash_base) {
+               $hash_base = git_read_hash("$project/HEAD");
+       }
        open my $fd, "-|", "$gitbin/git-ls-tree $hash" || die_error(undef, "Open git-ls-tree failed.");
        my (@entries) = map { chomp; $_ } <$fd>;
        close $fd || die_error(undef, "Reading tree failed.");
@@ -937,7 +946,7 @@ sub git_rss {
              "<rss version=\"0.91\">\n";
        print "<channel>\n";
        print "<title>$project</title>\n".
-             "<link> " . $my_url . "/$project/log</link>\n".
+             "<link> $my_url/$project/log</link>\n".
              "<description>$project log</description>\n".
              "<language>en</language>\n";
 
@@ -946,7 +955,7 @@ sub git_rss {
                my %ad = date_str($co{'author_epoch'});
                print "<item>\n" .
                      "\t<title>" . sprintf("%d %s %02d:%02d", $ad{'mday'}, $ad{'month'}, $ad{'hour'}, $ad{'minute'}) . " - " . escapeHTML($co{'title'}) . "</title>\n" .
-                     "\t<link> " . $my_url . "?p=$project;a=commit;h=$commit</link>\n" .
+                     "\t<link> $my_url?p=$project;a=commit;h=$commit</link>\n" .
                      "\t<description>";
                my $comment = $co{'comment'};
                foreach my $line (@$comment) {
@@ -984,7 +993,7 @@ sub git_log {
 
        if (!@revlist) {
                my %co = git_read_commit($head);
-               print "<div class=\"page_body\"> Last change " . $co{'age_string'} . ".<br/><br/></div>\n";
+               print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
        }
 
        foreach my $commit (@revlist) {
@@ -993,7 +1002,7 @@ sub git_log {
                my %ad = date_str($co{'author_epoch'});
                print "<div>\n" .
                      $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
-                     "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
+                     "<span class=\"log_age\">$co{'age_string'}</span>" . escapeHTML($co{'title'})) . "\n" .
                      "</div>\n";
                print "<div class=\"title_text\">\n" .
                      "<div class=\"log_link\">\n" .
@@ -1001,13 +1010,13 @@ sub git_log {
                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
                      "<br/>\n" .
                      "</div>\n" .
-                     "<i>" . escapeHTML($co{'author_name'}) .  " [" . $ad{'rfc2822'} . "]</i><br/>\n" .
+                     "<i>" . escapeHTML($co{'author_name'}) .  " [$ad{'rfc2822'}]</i><br/>\n" .
                      "</div>\n" .
                      "<div class=\"log_body\">\n";
                my $comment = $co{'comment'};
                my $empty = 0;
                foreach my $line (@$comment) {
-                       if ($line =~ m/^(signed[ \-]off[\-]by[ :]|acked[\-]by[ \:]|cc[ :])/i) {
+                       if ($line =~ m/^(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
                                next;
                        }
                        if ($line eq "") {
@@ -1038,7 +1047,7 @@ sub git_commit {
 
        my @difftree;
        if (defined $co{'parent'}) {
-               open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash" || die_error(undef, "Open failed.");
+               open my $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $hash" || die_error(undef, "Open failed.");
                @difftree = map { chomp; $_ } <$fd>;
                close $fd || die_error(undef, "Reading diff-tree failed.");
        } else {
@@ -1054,7 +1063,7 @@ sub git_commit {
        if (defined $co{'parent'}) {
                print " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff");
        }
-       print " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash"}, "tree") . "\n" .
+       print " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "\n" .
              "<br/><br/></div>\n";
        if (defined $co{'parent'}) {
                print "<div>\n" .
@@ -1062,13 +1071,13 @@ sub git_commit {
                      "</div>\n";
        } else {
                print "<div>\n" .
-                     $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
+                     $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
                      "</div>\n";
        }
        print "<div class=\"title_text\">\n" .
              "<table cellspacing=\"0\">\n";
        print "<tr><td>author</td><td>" . escapeHTML($co{'author'}) . "</td></tr>\n".
-             "<tr><td></td><td> " . $ad{'rfc2822'};
+             "<tr><td></td><td> $ad{'rfc2822'}";
        if ($ad{'hour_local'} < 6) {
                printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
        } else {
@@ -1076,10 +1085,10 @@ sub git_commit {
        }
        print "</td></tr>\n";
        print "<tr><td>committer</td><td>" . escapeHTML($co{'committer'}) . "</td></tr>\n";
-       print "<tr><td></td><td> " . $cd{'rfc2822'} . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
+       print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
        print "<tr><td>commit</td><td style=\"font-family: monospace;\">$hash</td></tr>\n";
        print "<tr><td>tree</td><td style=\"font-family: monospace;\">" .
-             $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=" . $hash}, $co{'tree'}) . "</td></tr>\n";
+             $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, $co{'tree'}) . "</td></tr>\n";
        my $parents  = $co{'parents'};
        foreach my $par (@$parents) {
                print "<tr><td>parent</td><td style=\"font-family: monospace;\">" .
@@ -1101,7 +1110,7 @@ sub git_commit {
                } else {
                        $empty = 0;
                }
-               if ($line =~ m/^(signed[ \-]off[\-]by[ :]|acked[\-]by[ \:]|cc[ :])/i) {
+               if ($line =~ m/^(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
                        $signed = 1;
                        print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
                } else {
@@ -1134,7 +1143,7 @@ sub git_commit {
                                }
                                print "<div class=\"list\">\n" .
                                      $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"},
-                                     escapeHTML($file) . " <span style=\"color: #008000;\">[new " . file_type($mode) . $mode_chng . "]</span>") . "\n" .
+                                     escapeHTML($file) . " <span style=\"color: #008000;\">[new " . file_type($mode) . "$mode_chng]</span>") . "\n" .
                                      "</div>\n";
                                print "<div class=\"list_link\">\n" .
                                      $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$id;hb=$hash;f=$file"}, "blob") . "\n" .
@@ -1201,7 +1210,7 @@ sub git_blobdiff {
                      $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
                      " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
-                     " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash_base"}, "tree");
+                     " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree");
                        if (defined $file_name) {
                                print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash_base;f=$file_name"}, "history");
                        }
@@ -1237,7 +1246,7 @@ sub git_commitdiff {
        if (!%co) {
                die_error(undef, "Unknown commit object.");
        }
-       open my $fd, "-|", "$gitbin/git-diff-tree -r " . $co{'parent'} . " $hash" || die_error(undef, "Open failed.");
+       open my $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $hash" || die_error(undef, "Open failed.");
        my (@difftree) = map { chomp; $_ } <$fd>;
        close $fd || die_error(undef, "Reading diff-tree failed.");
 
@@ -1306,7 +1315,7 @@ sub git_history {
        print "<div class=\"page_nav\">\n" .
              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") . " | " .
              $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") . " | " .
-             $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" . $co{'tree'} . ";hb=$hash"}, "tree") .
+             $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
              "<br/><br/>\n" .
              "</div>\n";
        print "<div>\n" .
@@ -1334,16 +1343,16 @@ sub git_history {
                        }
                        print "<div class=\"list\">\n" .
                              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"},
-                             "<span class=\"log_age\">" . $co{'age_string'} . "</span>" . escapeHTML($co{'title'})) . "\n" .
+                             "<span class=\"log_age\">$co{'age_string'}</span>" . escapeHTML($co{'title'})) . "\n" .
                              "</div>\n";
                        print "<div class=\"list_link\">\n" .
                              $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
                              " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=" .  $co{'tree'} . ";hb=$commit"}, "tree") .
-                             " | " . $cgi->a({-href => "$my_uri?p=$project;a=blob;hb=$commit;f=" . $file}, "blob");
+                             " | " . $cgi->a({-href => "$my_uri?p=$project;a=blob;hb=$commit;f=$file"}, "blob");
                        my $blob = git_get_hash_by_path($hash, $file_name);
                        my $blob_parent = git_get_hash_by_path($commit, $file_name);
                        if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
-                               print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=" . $file}, "diff");
+                               print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file"}, "diff");
                        }
                        print "<br/>\n" .
                              "</div>\n";