[PATCH RFC 2/2] gitweb: Hyperlink multiple git hashes on the same commit message line

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Marcel M. Cary
Date: Tuesday, February 17, 2009 - 8:00 pm

The current implementation only hyperlinks the first hash on
a given line of the commit message.  It seems sensible to
highlight all of them if there are multiple, and it seems
plausible that there would be multiple even with a tidy line
length limit, because they can be abbreviated as short as 8
characters.

Benchmark:

I wanted to make sure that using the 'e' switch to the Perl regex
wasn't going to kill performance, since this is called once per commit
message line displayed.

In all three A/B scenarios I tried, the A and B yielded the same
results within 2%, where A is the version of code before this patch
and B is the version after.

1: View a commit message containing the last 1000 commit hashes
2: View a commit message containing 1000 lines of 40 dots to avoid
   hyperlinking at the same message length
3: View a short merge commit message with a few lines of text and
   no hashes

All were run in CGI mode on my sub-production hardware on a recent
clone of git.git.  Numbers are the average of 10 reqests per second
with the first request discarded, since I expect this change to affect
primarily CPU usage.  Measured with ApacheBench.

Note that the web page rendered was the same; while the new code
supports multiple hashes per line, there was at most one per line.

The primary purpose of scenarios 2 and 3 were to verify that the
addition of 1000 commit messages had an impact on how much of the time
was spent rendering commit messages.  They were all within 2% of 0.80
requests per second (much faster).

So I think the patch has no noticeable effect on performance.

Signed-off-by: Marcel M. Cary <marcel@oak.homeunix.org>
---

And here's another.

Marcel


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

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 653f0be..51b7f56 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1384,13 +1384,11 @@ sub format_log_line_html {
 	my $line = shift;
 
 	$line = esc_html($line, -nbsp=>1);
-	if ($line =~ m/\b([0-9a-fA-F]{8,40})\b/) {
-		my $hash_text = $1;
-		my $link =
-			$cgi->a({-href => href(action=>"object", hash=>$hash_text),
-			        -class => "text"}, $hash_text);
-		$line =~ s/$hash_text/$link/;
-	}
+	$line =~ s{\b([0-9a-fA-F]{8,40})\b}{
+		return $cgi->a({-href => href(action=>"object", hash=>$1),
+					   -class => "text"}, $1);
+	}eg;
+
 	return $line;
 }
 
-- 
1.6.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC] Configuring (future) committags support in gitweb, Jakub Narebski, (Sat Nov 8, 12:07 pm)
Re: [RFC] Configuring (future) committags support in gitweb, Francis Galiegue, (Sat Nov 8, 1:02 pm)
Re: [RFC] Configuring (future) committags support in gitweb, Francis Galiegue, (Sat Nov 8, 4:27 pm)
[PATCH RFC 2/2] gitweb: Hyperlink multiple git hashes on t ..., Marcel M. Cary, (Tue Feb 17, 8:00 pm)
Re: [PATCH RFC 1/2] gitweb: Fix warnings with override per ..., Giuseppe Bilotta, (Wed Feb 18, 12:41 am)
Addresses with full names in patch emails, Marcel M. Cary, (Tue Feb 24, 8:38 am)
Re: Addresses with full names in patch emails, Jakub Narebski, (Tue Feb 24, 8:58 am)
[RFC PATCH 0/6] Second round of committag series, Marcel M. Cary, (Tue Nov 17, 11:22 pm)
Re: [RFC PATCH 0/6] Second round of committag series, Jakub Narebski, (Fri Nov 20, 4:24 pm)