Subject: [PATCH 8] gitweb: Add git_get_rev_name_tags function

From: Jakub Narebski <[email-masked]>
Date: Thu, 24 Aug 2006 19:41:23 +0200

Add git_get_rev_name_tags function, for later use in
git_commitdiff('plain') for X-Git-Tag: header.

This function, contrary to the call to
  git_get_following_references($hash, "tags");
_does_ strip "tags/" and returns bare tag name.

Signed-off-by: Jakub Narebski <[email-masked]>
---
Junio C Hamano wrote:
>>  * "commitdiff_plain" now only generates X-Git-Tag: line only if
>> there is tag pointing to the current commit.
>
> Hmph...
>
>>    ...; besides we are
>>    interested rather in tags _preceding_ the commit, and _heads_
>>    following the commit.
>
> Interesting observation.  When somebody says "feature X was
> introduced in such and such commit", people would want to know (1)
> the point release they are using has the feature -- which means you
> would want to know the earliest tag that comes after the commit, or
> (2) if the branch they are working on already has that
> feature -- which again means if the head follows the commit.  So
> I am not sure when preceding tag is interesting...

This commit introduces function which does job that was intended
I guess for X-Git-Tag: header... perhaps it should be renamed...

 gitweb/gitweb.perl |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index a068a81..3bc3ff3 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -800,6 +800,22 @@ sub git_get_preceding_references {
 	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;
+	}
+}
+
 ## ----------------------------------------------------------------------
 ## parse to hash functions
 
-- 
1.4.1.1