]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.perl
gitweb: Use git_get_name_rev_tags for commitdiff_plain X-Git-Tag: header
[Gitweb] / gitweb.perl
index d227f81d3818a82b08bb2a80310261c8416f4f0e679217d265a1169c65a7e740..b063714c3bb2ae27019187708040f7592d1eb335b6bd0da015bd208b2a364eeb 100755 (executable)
@@ -789,16 +789,31 @@ sub git_get_preceding_references {
                or return undef;
 
        my @reflist;
-       my $firstref;
 
        foreach my $commit (@commits) {
                foreach my $ref (@{$refs->{$commit}}) {
-                       $firstref = $ref unless $firstref;
+                       return $ref unless wantarray;
                        push @reflist, $ref;
                }
        }
 
-       return wantarray ? @reflist : $firstref;
+       return @reflist;
+}
+
+sub git_get_rev_name_tags {
+       my $hash = shift || return undef;
+
+       open my $fd, "-|", $GIT, "name-rev", "--tags", $hash
+               or return;
+       my $name_rev = <$fd>;
+       close $fd;
+
+       if ($name_rev =~ m|^$hash tags/(.*)$|) {
+               return $1;
+       } else {
+               # catches also '$hash undefined' output
+               return undef;
+       }
 }
 
 ## ----------------------------------------------------------------------
@@ -2825,10 +2840,7 @@ sub git_commitdiff {
 
        } elsif ($format eq 'plain') {
                my $refs = git_get_references("tags");
-               my @tagnames;
-               if (exists $refs->{$hash}) {
-                       @tagnames = map { s|^tags/|| } $refs->{$hash};
-               }
+               my $tagname = git_get_rev_name_tags($hash);
                my $filename = basename($project) . "-$hash.patch";
 
                print $cgi->header(
@@ -2842,10 +2854,9 @@ From: $co{'author'}
 Date: $ad{'rfc2822'} ($ad{'tz_local'})
 Subject: $co{'title'}
 TEXT
-               foreach my $tag (@tagnames) {
-                       print "X-Git-Tag: $tag\n";
-               }
+               print "X-Git-Tag: $tagname\n" if $tagname;
                print "X-Git-Url: " . $cgi->self_url() . "\n\n";
+
                foreach my $line (@{$co{'comment'}}) {
                        print "$line\n";
                }
This page took 0.255143 seconds and 4 git commands to generate.