more tags
[git.git] / gitweb.cgi
index e81064f..1f5a409 100755 (executable)
@@ -17,7 +17,7 @@ use Fcntl ':mode';
 binmode STDOUT, ':utf8';
 
 my $cgi = new CGI;
-my $version =          "255";
+my $version =          "260";
 my $my_url =           $cgi->url();
 my $my_uri =           $cgi->url(-absolute => 1);
 my $rss_link =         "";
@@ -146,7 +146,7 @@ sub validate_input {
        if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
                return undef;
        }
-       if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \.\/\-\+\#\~\%]/) {
+       if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
                return undef;
        }
        return $input;
@@ -311,6 +311,10 @@ a.rss_logo {
        text-align:center; text-decoration:none;
 }
 a.rss_logo:hover { background-color:#ee5500; }
+span.tag {
+       padding:0px 4px; font-size:10px; font-weight:normal;
+       background-color:#ffffaa; border:1px solid; border-color:#ffffcc #ffee00 #ffee00 #ffffcc;
+}
 </style>
 </head>
 <body>
@@ -901,6 +905,25 @@ sub git_project_list {
        git_footer_html();
 }
 
+sub read_info_ref {
+       my $type = shift || "";
+       my %refs;
+       # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c      refs/tags/v2.6.11
+       # c39ae07f393806ccf406ef966e9a15afc43cc36a      refs/tags/v2.6.11^{}
+       open my $fd, "$projectroot/$project/info/refs" or return;
+       while (my $line = <$fd>) {
+               if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\^]+)/) {
+                       if (defined $refs{$1}) {
+                               $refs{$1} .= " / $2";
+                       } else {
+                               $refs{$1} = $2;
+                       }
+               }
+       }
+       close $fd or return;
+       return \%refs;
+}
+
 sub git_read_refs {
        my $ref_dir = shift;
        my @reflist;
@@ -989,6 +1012,7 @@ sub git_summary {
                $owner = get_file_owner("$projectroot/$project");
        }
 
+       my $refs = read_info_ref();
        git_header_html();
        print "<div class=\"page_nav\">\n" .
              "summary".
@@ -1024,15 +1048,19 @@ sub git_summary {
                }
                $alternate ^= 1;
                if ($i-- > 0) {
+                       my $ref = "";
+                       if (defined $refs->{$commit}) {
+                               $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
+                       }
                        print "<td><i>$co{'age_string'}</i></td>\n" .
                              "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
                              "<td>";
                        if (length($co{'title_short'}) < length($co{'title'})) {
                                print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
-                                     "<b>" . esc_html($co{'title_short'}) . "</b>");
+                                     "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
                        } else {
                                print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
-                                     "<b>" . esc_html($co{'title'}) . "</b>");
+                                     "<b>" . esc_html($co{'title'}) . "$ref</b>");
                        }
                        print "</td>\n" .
                              "<td class=\"link\">" .
@@ -1389,6 +1417,11 @@ sub git_tree {
        close $fd or die_error(undef, "Reading tree failed.");
        $/ = "\n";
 
+       my $refs = read_info_ref();
+       my $ref = "";
+       if (defined $refs->{$hash_base}) {
+               $ref = " <span class=\"tag\">" . esc_html($refs->{$hash_base}) . "</span>";
+       }
        git_header_html();
        my $base_key = "";
        my $base = "";
@@ -1404,7 +1437,7 @@ sub git_tree {
                      "<br/><br/>\n" .
                      "</div>\n";
                print "<div>\n" .
-                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
+                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
                      "</div>\n";
        } else {
                print "<div class=\"page_nav\">\n";
@@ -1556,6 +1589,7 @@ sub git_log {
        if (!defined $page) {
                $page = 0;
        }
+       my $refs = read_info_ref();
        git_header_html();
        print "<div class=\"page_nav\">\n";
        print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
@@ -1598,13 +1632,17 @@ sub git_log {
        }
        for (my $i = ($page * 100); $i <= $#revlist; $i++) {
                my $commit = $revlist[$i];
+               my $ref = "";
+               if (defined $refs->{$commit}) {
+                       $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
+               }
                my %co = git_read_commit($commit);
                next if !%co;
                my %ad = date_str($co{'author_epoch'});
                print "<div>\n" .
                      $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "title"},
-                     "<span class=\"age\">$co{'age_string'}</span>" . esc_html($co{'title'})) . "\n" .
-                     "</div>\n";
+                     "<span class=\"age\">$co{'age_string'}</span>" . esc_html($co{'title'}) . $ref) . "\n";
+               print "</div>\n";
                print "<div class=\"title_text\">\n" .
                      "<div class=\"log_link\">\n" .
                      $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
@@ -1662,6 +1700,11 @@ sub git_commit {
        if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
                $expires = "+1d";
        }
+       my $refs = read_info_ref();
+       my $ref = "";
+       if (defined $refs->{$hash}) {
+               $ref = " <span class=\"tag\">" . esc_html($refs->{$hash}) . "</span>";
+       }
        git_header_html(undef, $expires);
        print "<div class=\"page_nav\">\n" .
              $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
@@ -1675,7 +1718,7 @@ sub git_commit {
              "<br/><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'})) . "\n" .
+                     $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
                      "</div>\n";
        } else {
                print "<div>\n" .
@@ -1899,6 +1942,11 @@ sub git_commitdiff {
        if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
                $expires = "+1d";
        }
+       my $refs = read_info_ref();
+       my $ref = "";
+       if (defined $refs->{$hash}) {
+               $ref = " <span class=\"tag\">" . esc_html($refs->{$hash}) . "</span>";
+       }
        git_header_html(undef, $expires);
        print "<div class=\"page_nav\">\n" .
              $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
@@ -1910,7 +1958,7 @@ sub git_commitdiff {
        print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
              "</div>\n";
        print "<div>\n" .
-             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
+             $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
              "</div>\n";
        print "<div class=\"page_body\">\n";
        my $comment = $co{'comment'};
@@ -1981,23 +2029,18 @@ sub git_commitdiff_plain {
 
        # try to figure out the next tag after this commit
        my $tagname;
-       my %taghash;
-       my $tags = git_read_refs("refs/tags");
-       foreach my $entry (@$tags) {
-               my %tag = %$entry;
-               $taghash{$tag{'refid'}} = $tag{'name'};
-       }
+       my $refs = read_info_ref("tags");
        open $fd, "-|", "$gitbin/git-rev-list HEAD";
-       while (my $commit = <$fd>) {
-               chomp $commit;
-               if ($taghash{$commit}) {
-                       $tagname = $taghash{$commit};
+       chomp (my (@commits) = <$fd>);
+       close $fd;
+       foreach my $commit (@commits) {
+               if (defined $refs->{$commit}) {
+                       $tagname = $refs->{$commit}
                }
                if ($commit eq $hash) {
                        last;
                }
        }
-       close $fd;
 
        print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
        my %co = git_read_commit($hash);
@@ -2041,6 +2084,7 @@ sub git_history {
        if (!%co) {
                die_error(undef, "Unknown commit object.");
        }
+       my $refs = read_info_ref();
        git_header_html();
        print "<div class=\"page_nav\">\n" .
              $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
@@ -2070,6 +2114,10 @@ sub git_history {
                        if (!%co) {
                                next;
                        }
+                       my $ref = "";
+                       if (defined $refs->{$commit}) {
+                               $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
+                       }
                        if ($alternate) {
                                print "<tr class=\"dark\">\n";
                        } else {
@@ -2079,7 +2127,7 @@ sub git_history {
                        print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
                              "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
                              "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
-                             esc_html(chop_str($co{'title'}, 50)) . "</b>") . "</td>\n" .
+                             esc_html(chop_str($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
                              "<td class=\"link\">" .
                              $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
                              " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
@@ -2254,6 +2302,7 @@ sub git_shortlog {
        if (!defined $page) {
                $page = 0;
        }
+       my $refs = read_info_ref();
        git_header_html();
        print "<div class=\"page_nav\">\n" .
              $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
@@ -2294,6 +2343,10 @@ sub git_shortlog {
        my $alternate = 0;
        for (my $i = ($page * 100); $i <= $#revlist; $i++) {
                my $commit = $revlist[$i];
+               my $ref = "";
+               if (defined $refs->{$commit}) {
+                       $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
+               }
                my %co = git_read_commit($commit);
                my %ad = date_str($co{'author_epoch'});
                if ($alternate) {
@@ -2307,10 +2360,10 @@ sub git_shortlog {
                      "<td>";
                if (length($co{'title_short'}) < length($co{'title'})) {
                        print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
-                             "<b>" . esc_html($co{'title_short'}) . "</b>");
+                             "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
                } else {
                        print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
-                             "<b>" . esc_html($co{'title_short'}) . "</b>");
+                             "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
                }
                print "</td>\n" .
                      "<td class=\"link\">" .