git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jakub Narebski <jnareb@gmail.com>
Date
Dec 1, 2007, 01:47 UTC
Message-ID
<200712010247.25107.jnareb@gmail.com>
In-Reply-To
<200712010245.29204.jnareb@gmail.com>

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 <jnareb@gmail.com>
---
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
Previous: Jakub NarebskiNext: Jakub Narebski
Message 2 of 8 in “gitweb: disambiguate heads and tags withs the same name”
  1. gitweb: disambiguate heads and tags withs the same nameJakub Narebski, Dec 1, 2007
  2. gitweb: Try harder in parse_tag; perhaps it was given ambiguous nameJakub Narebski, Dec 1, 2007
  3. Jakub NarebskiDec 1, 2007
  4. Junio C HamanoDec 5, 2007
  5. Jakub NarebskiDec 5, 2007
  6. Junio C HamanoDec 5, 2007
  7. Jakub NarebskiDec 5, 2007
  8. Junio C HamanoDec 5, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.