Thread (11 messages) flat view 11 messages, 3 authors, 2016-06-15

Re: [PATCH v4] gitweb: ref markers link to named shortlogs

From: Jakub Narebski <hidden>
Date: 2016-06-15 22:45:12
Subsystem: the rest · Maintainer: Linus Torvalds

On Fri, 22 August 2008, Giuseppe Bilotta wrote:
quoted hunk ↗ jump to hunk
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index a0d9272..5cb332f 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1201,7 +1201,12 @@ sub format_ref_marker {
 	my $markers = '';
 
 	if (defined $refs->{$id}) {
-		foreach my $ref (@{$refs->{$id}}) {
+		foreach my $aref (@{$refs->{$id}}) {
+			# this code exploits the fact that non-lightweight tags are the
+			# only indirect objects, and that they are the only objects for which
+			# we want to use tag instead of shortlog as action
+			my $ref = $aref->[0];
+			my $indirect = $aref->[1];
 			my ($type, $name) = qw();
 			# e.g. tags/v2.6.11 or heads/next
 			if ($ref =~ m!^(.*?)s?/(.*)$!) {
@@ -1212,8 +1217,14 @@ sub format_ref_marker {
 				$name = $ref;
 			}
 
-			$markers .= " <span class=\"$type\" title=\"$ref\">" .
-			            esc_html($name) . "</span>";
+			my $class = $type;
+			if ($indirect) {
+				$class .= " indirect";
+			}
+
+			$markers .= " <span class=\"$class\" title=\"$ref\">" .
+				$cgi->a({-href => href(action=>( $indirect ? "tag" : "shortlog"), hash=>$ref)}, $name) .
+				"</span>";
 		}
 	}
 
@@ -2035,11 +2046,11 @@ sub git_get_references {
 
 	while (my $line = <$fd>) {
 		chomp $line;
-		if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
+		if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)(\^\{\})?$!) {
 			if (defined $refs{$1}) {
-				push @{$refs{$1}}, $2;
+				push @{$refs{$1}}, [$2, $3];
 			} else {
-				$refs{$1} = [ $2 ];
+				$refs{$1} = [ [$2, $3] ];
 			}
 		}
 	}
Seems overly complicated.  How about something like this, instead?
It simply moves stripping ^{} from refs to format_ref_marker(),
and uses "tags/v1.5.0^{}" instead of [ "tags/v1.5.0", 1 ].

NOT TESTED!

 gitweb/gitweb.perl |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 4c104d2..261307f 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1096,18 +1096,24 @@ sub format_ref_marker {
 
 	if (defined $refs->{$id}) {
 		foreach my $ref (@{$refs->{$id}}) {
-			my ($type, $name) = qw();
+			my ($class, $name, $indirect) = qw();
+			# strip ^{} suffix from indirect refs, like tags/v2.6.11^{}
+			$indirect = ($ref =~ s/\^{}$//);
 			# e.g. tags/v2.6.11 or heads/next
 			if ($ref =~ m!^(.*?)s?/(.*)$!) {
-				$type = $1;
-				$name = $2;
+				$class = $1;
+				$name  = $2;
 			} else {
-				$type = "ref";
-				$name = $ref;
+				$class = "ref";
+				$name  = $ref;
 			}
+			$class .= " indirect" if $indirect;
 
-			$markers .= " <span class=\"$type\" title=\"$ref\">" .
-			            esc_html($name) . "</span>";
+			$markers .= " <span class=\"$class\" title=\"$ref\">" .
+			            esc_html($name) .
+			            $cgi->a({-href => href(action=>($indirect ? "tag" : "shortlog"),
+			                                   hash=>$ref)}, $name) .
+			            "</span>";
 		}
 	}
 
@@ -1959,7 +1965,7 @@ sub git_get_references {
 
 	while (my $line = <$fd>) {
 		chomp $line;
-		if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
+		if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?.+)$!) {
 			if (defined $refs{$1}) {
 				push @{$refs{$1}}, $2;
 			} else {

-- 
Jakub Narebski
Poland
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help