git.c: Rename NEEDS_PREFIX to RUN_SETUP
[gitweb.git] / gitweb / gitweb.cgi
index 57f4a2e263d24748fd447138d3d08100267c8805..e5fca63b9c5ba8b525f4f7791e14a49d1f51399f 100755 (executable)
@@ -795,7 +795,7 @@ sub git_read_projects {
        if (-d $projects_list) {
                # search in directory
                my $dir = $projects_list;
-               opendir my $dh, $dir or return undef;
+               opendir my ($dh), $dir or return undef;
                while (my $dir = readdir($dh)) {
                        if (-e "$projectroot/$dir/HEAD") {
                                my $pr = {
@@ -810,7 +810,7 @@ sub git_read_projects {
                # 'git%2Fgit.git Linus+Torvalds'
                # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
                # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
-               open my $fd , $projects_list or return undef;
+               open my ($fd), $projects_list or return undef;
                while (my $line = <$fd>) {
                        chomp $line;
                        my ($path, $owner) = split ' ', $line;
@@ -1138,7 +1138,7 @@ sub git_summary {
                                      "</td>\n" .
                                      "<td>";
                                if (defined($comment)) {
-                                     print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
+                                     print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, esc_html($comment));
                                }
                                print "</td>\n" .
                                      "<td class=\"link\">";
@@ -1252,15 +1252,6 @@ sub git_tag {
        git_footer_html();
 }
 
-sub git_read_blame_line {
-       my %bl;
-       $_ = shift;
-
-       ($bl{'hash'}, $bl{'lineno'}, $bl{'data'}) = /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
-
-       return %bl;
-}
-
 sub git_blame2 {
        my $fd;
        my $ftype;
@@ -1295,19 +1286,27 @@ sub git_blame2 {
                $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
                "</div>\n";
        git_print_page_path($file_name, $ftype);
-
+       my @rev_color = (qw(light dark));
+       my $num_colors = scalar(@rev_color);
+       my $current_color = 0;
+       my $last_rev;
        print "<div class=\"page_body\">\n";
-
        print "<table class=\"blame\">\n";
        print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
-       while (my $line = <$fd>) {
-               my %blame_line = git_read_blame_line($line);
-               my $full_rev = $blame_line{'hash'};
+       while (<$fd>) {
+               /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
+               my $full_rev = $1;
                my $rev = substr($full_rev, 0, 8);
-               my $lineno = $blame_line{'lineno'};
-               my $data = $blame_line{'data'};
+               my $lineno = $2;
+               my $data = $3;
 
-               print "<tr>\n";
+               if (!defined $last_rev) {
+                       $last_rev = $full_rev;
+               } elsif ($last_rev ne $full_rev) {
+                       $last_rev = $full_rev;
+                       $current_color = ++$current_color % $num_colors;
+               }
+               print "<tr class=\"$rev_color[$current_color]\">\n";
                print "<td class=\"sha1\">" .
                        $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html($rev)) . "</td>\n";
                print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html($lineno) . "</a></td>\n";
@@ -1316,7 +1315,6 @@ sub git_blame2 {
        }
        print "</table>\n";
        print "</div>";
-
        close $fd or print "Reading blob failed\n";
        git_footer_html();
 }
@@ -2022,7 +2020,13 @@ sub git_commit {
                print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
        }
        print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
-             "<br/><br/></div>\n";
+               "<br/>\n";
+       if (defined $file_name && defined $co{'parent'}) {
+               my $parent = $co{'parent'};
+               print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame") . "\n";
+       }
+       print "<br/></div>\n";
+
        if (defined $co{'parent'}) {
                print "<div>\n" .
                      $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .