Subject: [PATCH] gitweb: Try harder in parse_tag; perhaps it was given ambiguous name

From: Jakub Narebski <[email-masked]>
Date: Sat, 1 Dec 2007 02:47:24 +0100

If parse_tag was given ambiguous name, i.e. name which is both head
(branch) name and tag name, parse_tag failed because git prefer heads
to tags if there is ambiguity.  Now it tries harder: if git-cat-file
doesn't produce output, try to resolve argument as tag name using
git-show-ref.

Signed-off-by: Jakub Narebski <[email-masked]>
---
This supplements previous patch; while previous modified links to always
use unambiguous name, this one makes 'tag' view work even if passed
ambiguous name which is both name of head and of tag.

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

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 6ff4221..0427290 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1876,6 +1876,18 @@ sub parse_tag {
 	my @comment;
 
 	open my $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
+	# try harder in case there is head (branch) with the same name as tag
+	if (eof($fd)) {
+		close $fd or return;
+		my $git_command = git_cmd_str();
+		$tag_id = qx($git_command show-ref --hash --tags $tag_id);
+		return unless $tag_id;
+		open $fd, "-|", git_cmd(), "cat-file", "tag", $tag_id or return;
+		if (eof($fd)) {
+			close $fd;
+			return;
+		};
+	}
 	$tag{'id'} = $tag_id;
 	while (my $line = <$fd>) {
 		chomp $line;
-- 
1.5.3.6