Skip to contentSkip to conversation

gitweb: Add title attribute with full first line of tag comment if it is needed

PATCH In review Jakub Narebski 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gitweb: Add title attribute with full first line of tag comment if it is needed

For commits in oneline view (summary, shortlog, history) commit title (first line of commit message) is link to commit itself. If commit title (commit description) is shortened in output, hyperlink has title attribute with full title.

This commit does the same also for tags. It is much more rare to have long tag description, though.

Misfeature: sometimes tag link has title attribute even if tag description doesn't seem to be shortened.

Needs refactoring (twice done almost exactly the same, four times similar code is used).

---

 gitweb/gitweb.cgi |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

e41a09e140c1ecd933ae90e7b55660d67f33dc1b

gitweb/gitweb.cgi +16 -6
index e044c61..8f8ae4a 100755
@@ -326,7 +326,7 @@ EOF
 		} elsif (defined $hash) {
 			$search_hash = $hash;
 		} else {
-			$search_hash  = "HEAD";
+			$search_hash = "HEAD";
 		}
 		$cgi->param("a", "search");
 		$cgi->param("h", $search_hash);
@@ -1107,7 +1107,8 @@ sub git_summary {
 		foreach my $entry (@$taglist) {
 			my %tag = %$entry;
 			my $comment_lines = $tag{'comment'};
-			my $comment = shift @$comment_lines;
+			my $comment_long = shift @$comment_lines;
+			my $comment = $comment_long;
 			if (defined($comment)) {
 				$comment = chop_str($comment, 30, 5);
 			}
@@ -1119,13 +1120,17 @@ sub git_summary {
 			$alternate ^= 1;
 			if ($i-- > 0) {
 				print "<td><i>$tag{'age'}</i></td>\n" .
-				      "<td>" .
+				      "<td>";
 				      $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
 				      "<b>" . esc_html($tag{'name'}) . "</b>") .
 				      "</td>\n" .
 				      "<td>";
 				if (defined($comment)) {
-				      print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
+					if (length($comment) < length($comment_long)) {
+						print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}"), -title => "$comment_long"}, $comment);
+					} else {
+						print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
+					}
 				}
 				print "</td>\n" .
 				      "<td class=\"link\">";
@@ -1346,7 +1351,8 @@ sub git_tags {
 		foreach my $entry (@$taglist) {
 			my %tag = %$entry;
 			my $comment_lines = $tag{'comment'};
-			my $comment = shift @$comment_lines;
+			my $comment_long = shift @$comment_lines;
+			my $comment = $comment_long;
 			if (defined($comment)) {
 				$comment = chop_str($comment, 30, 5);
 			}
@@ -1363,7 +1369,11 @@ sub git_tags {
 			      "</td>\n" .
 			      "<td>";
 			if (defined($comment)) {
-			      print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
+				if (length($comment) < length($comment_long)) {
+					print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}"), -title => "$comment_long"}, $comment);
+				} else {
+					print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
+				}
 			}
 			print "</td>\n" .
 			      "<td class=\"link\">";
Signature · 1 line
1.3.0
#1 lore raw
Quoted 4 lines · Jakub Narebski

For commits in oneline view (summary, shortlog, history) commit title (first line of commit message) is link to commit itself. If commit title (commit description) is shortened in output, hyperlink has title attribute with full title.

There are pure fixes and this "-title" enhancement intermixed. Can we have fixes-only first?

gitweb/gitweb.cgi EOF · line 332

Quoted 13 lines
gitweb/gitweb.cgi +1 -1
index e044c61..8f8ae4a 100755
@@ -326,7 +326,7 @@ EOF
 		} elsif (defined $hash) {
 			$search_hash = $hash;
 		} else {
-			$search_hash  = "HEAD";
+			$search_hash = "HEAD";
 		}
 		$cgi->param("a", "search");
 		$cgi->param("h", $search_hash);

Is a fix.

gitweb/gitweb.cgi sub git_summary { · line 1114

Quoted 10 lines
gitweb/gitweb.cgi +2 -1
@@ -1107,7 +1107,8 @@ sub git_summary {
 		foreach my $entry (@$taglist) {
 			my %tag = %$entry;
 			my $comment_lines = $tag{'comment'};
-			my $comment = shift @$comment_lines;
+			my $comment_long = shift @$comment_lines;
+			my $comment = $comment_long;
 			if (defined($comment)) {
 				$comment = chop_str($comment, 30, 5);
 			}

Is an enhancement.

gitweb/gitweb.cgi sub git_summary { · line 1127

Quoted 10 lines
gitweb/gitweb.cgi +1 -1
@@ -1119,13 +1120,17 @@ sub git_summary {
 			$alternate ^= 1;
 			if ($i-- > 0) {
 				print "<td><i>$tag{'age'}</i></td>\n" .
-				      "<td>" .
+				      "<td>";
 				      $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
 				      "<b>" . esc_html($tag{'name'}) . "</b>") .
 				      "</td>\n" .
 				      "<td>";

Is a fix. How could we have missed this?

gitweb/gitweb.cgi sub git_summary { · line 1136

Quoted 10 lines
gitweb/gitweb.cgi +5 -1
 				if (defined($comment)) {
-				      print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
+					if (length($comment) < length($comment_long)) {
+						print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}"), -title => "$comment_long"}, $comment);
+					} else {
+						print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
+					}
 				}
 				print "</td>\n" .
 				      "<td class=\"link\">";

Is an enhancement -- I suspect it is not worth to switch depending on the length of $comment_long. Does it clutter the output too much if you did -title to everybody?

gitweb/gitweb.cgi sub git_tags { · line 1358

Quoted 10 lines
gitweb/gitweb.cgi +2 -1
@@ -1346,7 +1351,8 @@ sub git_tags {
 		foreach my $entry (@$taglist) {
 			my %tag = %$entry;
 			my $comment_lines = $tag{'comment'};
-			my $comment = shift @$comment_lines;
+			my $comment_long = shift @$comment_lines;
+			my $comment = $comment_long;
 			if (defined($comment)) {
 				$comment = chop_str($comment, 30, 5);
 			}

Is an enhancement. I think the matching hunk to fix the same "$cgi->a() output concatenated as print argument" problem is missing here. And the next hunk the same comment as the one for git_summary applies.

And as you say, git_summary and git_tags do look similar. Maybe we would want to refactor them first to clean things up before piling up more features?

#2 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 4 lines · Jakub Narebski

For commits in oneline view (summary, shortlog, history) commit title (first line of commit message) is link to commit itself. If commit title (commit description) is shortened in output, hyperlink has title attribute with full title.

There are pure fixes and this "-title" enhancement intermixed. Can we have fixes-only first?

O.K. done.

Quoted 3 lines

And as you say, git_summary and git_tags do look similar. Maybe we would want to refactor them first to clean things up before piling up more features?

O.K. will do.

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git