# [PATCH] gitweb : disambiguate heads and tags withs the same name

3 messages from 2007-10-28 to 2007-11-03. Participants: Guillaume Seguin, Junio C Hamano.
Thread: https://gitlist.dev/t/10501

## Guillaume Seguin, 2007-10-28 13:12

Subject: [PATCH] gitweb : disambiguate heads and tags withs the same name
Message-ID: <e877c31c0710280612l5d783ab0o50ce00c70b3311db@mail.gmail.com>
URL: https://gitlist.dev/e/e877c31c0710280612l5d783ab0o50ce00c70b3311db%40mail.gmail.com

```
Avoid wrong disambiguation that would link logs/trees of tags and heads which
share the same name to the same page, leading to a disambiguation that would
prefer the tag, thus making it impossible to access the corresponding
head log and
tree without hacking the url by hand.

---
 gitweb/gitweb.perl |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 48e21da..f918c00 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3534,6 +3534,7 @@ sub git_tags_body {
 	for (my $i = $from; $i <= $to; $i++) {
 		my $entry = $taglist->[$i];
 		my %tag = %$entry;
+		my $name = "refs/tags/$tag{'name'}";
 		my $comment = $tag{'subject'};
 		my $comment_short;
 		if (defined $comment) {
@@ -3570,8 +3571,8 @@ sub git_tags_body {
 		      "<td class=\"link\">" . " | " .
 		      $cgi->a({-href => href(action=>$tag{'reftype'},
hash=>$tag{'refid'})}, $tag{'reftype'});
 		if ($tag{'reftype'} eq "commit") {
-			print " | " . $cgi->a({-href => href(action=>"shortlog",
hash=>$tag{'name'})}, "shortlog") .
-			      " | " . $cgi->a({-href => href(action=>"log",
hash=>$tag{'name'})}, "log");
+			print " | " . $cgi->a({-href => href(action=>"shortlog",
hash=>$name)}, "shortlog") .
+			      " | " . $cgi->a({-href => href(action=>"log", hash=>$name)}, "log");
 		} elsif ($tag{'reftype'} eq "blob") {
 			print " | " . $cgi->a({-href => href(action=>"blob_plain",
hash=>$tag{'refid'})}, "raw");
 		}
@@ -3597,6 +3598,7 @@ sub git_heads_body {
 	for (my $i = $from; $i <= $to; $i++) {
 		my $entry = $headlist->[$i];
 		my %ref = %$entry;
+		my $name = "refs/heads/$ref{'name'}";
 		my $curr = $ref{'id'} eq $head;
 		if ($alternate) {
 			print "<tr class=\"dark\">\n";
@@ -3606,13 +3608,13 @@ sub git_heads_body {
 		$alternate ^= 1;
 		print "<td><i>$ref{'age'}</i></td>\n" .
 		      ($curr ? "<td class=\"current_head\">" : "<td>") .
-		      $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'name'}),
+		      $cgi->a({-href => href(action=>"shortlog", hash=>$name),
 		               -class => "list name"},esc_html($ref{'name'})) .
 		      "</td>\n" .
 		      "<td class=\"link\">" .
-		      $cgi->a({-href => href(action=>"shortlog",
hash=>$ref{'name'})}, "shortlog") . " | " .
-		      $cgi->a({-href => href(action=>"log", hash=>$ref{'name'})},
"log") . " | " .
-		      $cgi->a({-href => href(action=>"tree", hash=>$ref{'name'},
hash_base=>$ref{'name'})}, "tree") .
+		      $cgi->a({-href => href(action=>"shortlog", hash=>$name)},
"shortlog") . " | " .
+		      $cgi->a({-href => href(action=>"log", hash=>$name)}, "log") . " | " .
+		      $cgi->a({-href => href(action=>"tree", hash=>$name,
hash_base=>$name)}, "tree") .
 		      "</td>\n" .
 		      "</tr>";
 	}
-- 
1.5.3.4.395.g85b0

```

## Junio C Hamano, 2007-10-30 18:19

Subject: Re: [PATCH] gitweb : disambiguate heads and tags withs the same name
Message-ID: <7v3avsmpmj.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v3avsmpmj.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <e877c31c0710280612l5d783ab0o50ce00c70b3311db@mail.gmail.com>

```
"Guillaume Seguin" <guillaume@segu.in> writes:

> Avoid wrong disambiguation that would link logs/trees of tags and heads which
> share the same name to the same page, leading to a disambiguation that would
> prefer the tag, thus making it impossible to access the corresponding
> head log and
> tree without hacking the url by hand.
>
> ---
>  gitweb/gitweb.perl |   14 ++++++++------
>  1 files changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 48e21da..f918c00 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -3534,6 +3534,7 @@ sub git_tags_body {
>  	for (my $i = $from; $i <= $to; $i++) {
>  		my $entry = $taglist->[$i];
>  		my %tag = %$entry;
> +		my $name = "refs/tags/$tag{'name'}";
>  		my $comment = $tag{'subject'};
>  		my $comment_short;
>  		if (defined $comment) {
> @@ -3570,8 +3571,8 @@ sub git_tags_body {
>  		      "<td class=\"link\">" . " | " .
>  		      $cgi->a({-href => href(action=>$tag{'reftype'},
> hash=>$tag{'refid'})}, $tag{'reftype'});
>  		if ($tag{'reftype'} eq "commit") {
> -			print " | " . $cgi->a({-href => href(action=>"shortlog",
> hash=>$tag{'name'})}, "shortlog") .
> -			      " | " . $cgi->a({-href => href(action=>"log",
> hash=>$tag{'name'})}, "log");
> +			print " | " . $cgi->a({-href => href(action=>"shortlog",
> hash=>$name)}, "shortlog") .
> ...

Just in case anybody is wondering, the patch is whitespace
mangled and lacks a sign-off.

I suspect what the patch does may be a good idea, although I
haven't followed the existing code closely to verify it.

```

## Guillaume Seguin, 2007-11-03 21:40

Subject: [PATCH] gitweb : disambiguate heads and tags withs the same name
Message-ID: <1194126032.15420.4.camel@ed3n-m>
URL: https://gitlist.dev/e/1194126032.15420.4.camel%40ed3n-m
In-Reply-To: <7v3avsmpmj.fsf@gitster.siamese.dyndns.org>

```
   Avoid wrong disambiguation that would link logs/trees of tags and heads which 
   share the same name to the same page, leading to a disambiguation that would
   prefer the tag, thus making it impossible to access the corresponding
   head log and tree without hacking the url by hand.

   Signed-off-by: Guillaume Seguin <guillaume@segu.in>

---
 gitweb/gitweb.perl |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl 
index 48e21da..f918c00 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3534,6 +3534,7 @@ sub git_tags_body {
     for (my $i = $from; $i <= $to; $i++) {
         my $entry = $taglist->[$i]; 
         my %tag = %$entry;
+        my $name = "refs/tags/$tag{'name'}";
         my $comment = $tag{'subject'};
         my $comment_short;
         if (defined $comment) {
@@ -3570,8 +3571,8 @@ sub git_tags_body { 
               "<td class=\"link\">" . " | " .
               $cgi->a({-href => href(action=>$tag{'reftype'}, hash=>$tag{'refid'})}, $tag{'reftype'}); 
         if ($tag{'reftype'} eq "commit") {
-            print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . 
-                  " | " . $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log");
+            print " | " . $cgi->a({-href => href(action=>"shortlog", hash=>$name)}, "shortlog") . 
+                  " | " . $cgi->a({-href => href(action=>"log", hash=>$name)}, "log");
         } elsif ($tag{'reftype'} eq "blob") {
             print " | " . $cgi->a({-href => href(action=>"blob_plain", hash=>$tag{'refid'})}, "raw"); 
         }
@@ -3597,6 +3598,7 @@ sub git_heads_body {
     for (my $i = $from; $i <= $to; $i++) {
         my $entry = $headlist->[$i];
         my %ref = %$entry;
+        my $name = "refs/heads/$ref{'name'}"; 
         my $curr = $ref{'id'} eq $head;
         if ($alternate) {
             print "<tr class=\"dark\">\n";
@@ -3606,13 +3608,13 @@ sub git_heads_body {
         $alternate ^= 1; 
         print "<td><i>$ref{'age'}</i></td>\n" .
               ($curr ? "<td class=\"current_head\">" : "<td>") .
-              $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'name'}), 
+              $cgi->a({-href => href(action=>"shortlog", hash=>$name),
                        -class => "list name"},esc_html($ref{'name'})) .
               "</td>\n" . 
               "<td class=\"link\">" .
-              $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'name'})}, "shortlog") . " | " . 
-              $cgi->a({-href => href(action=>"log", hash=>$ref{'name'})}, "log") . " | " .
-              $cgi->a({-href => href(action=>"tree", hash=>$ref{'name'}, hash_base=>$ref{'name'})}, "tree") . 
+              $cgi->a({-href => href(action=>"shortlog", hash=>$name)}, "shortlog") . " | " .
+              $cgi->a({-href => href(action=>"log", hash=>$name)}, "log") . " | " . 
+              $cgi->a({-href => href(action=>"tree", hash=>$name, hash_base=>$name)}, "tree") .
               "</td>\n" .
               "</tr>"; 
     }
-- 
1.5.3.4.395.g85b0

```
