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

[PATCH] gitweb: Better regexp for SHA-1 committag match

From
Jakub Narebski <jnareb@gmail.com>
Date
Feb 6, 2009, 09:12 UTC
Message-ID
<200902061012.42943.jnareb@gmail.com>
In-Reply-To
<alpine.DEB.1.00.0902031327340.6573@intel-tinevez-2-302>
On Tue, 3 Feb 2009, Johannes Schindelin wrote:
> On Tue, 3 Feb 2009, Toralf Förster wrote:
>> At Monday 02 February 2009 23:54:20 Jakub Narebski wrote :
>>> Toralf Förster <toralf.foerster@gmx.de> writes:
Show 22 quoted lines
>>>> As seen here
>>>> http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.27.y.git;a=commit;h=8ca2918f99b5861359de1805f27b08023c82abd2 the strings [<c043d0f3>]
>>>> and firends shouldn't be recognized as git hashes, isn't it ?
>>>
>>> Gitweb, not webgit.  And gitweb considers ([0-9a-fA-F]{8,40}) i.e.
>>> from 8 to 40 hexadecimal characters to be (shortened) SHA-1.  It
>>> simply cannot afford checking if such object exists when displaying
>>> commit message (for example in 'log' view).
>> 
>> Ah - ok, what's about expecting spaces around such SHA-1 keys ?
> 
> Won't fly: there was a recommendation at some point that you should refer 
> to commits in such a form:
> 
> 	2819075(Merge branch 'maint-1.6.0' into maint)
> 
> However, gitweb being written in Perl, I think a lookbehind like (?<!0x), 
> i.e. that a 0x in front of the hexadecimal characters means it is no 
> SHA-1.
> 
> Even better would be using word boundaries, I guess, but all that fails 
> when you have a hexdump in the commit message.

Here you have it: anchoring SHA-1 regexp to word boundary. It would help eliminate _some_ of false matches.

-- >8 --
Subject: [PATCH] gitweb: Better regexp for SHA-1 committag match

Make SHA-1 regexp to be turned into hyperlink (the SHA-1 committag) to match word boundary at the beginning and the end. This way we reduce number of false matches, for example we now don't match 0x74a5cd01 which is hex decimal (for example memory address), but is not SHA-1.

Suggested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index f27dbb6..bec1af6 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1364,7 +1364,7 @@ sub format_log_line_html {
 	my $line = shift;
 
 	$line = esc_html($line, -nbsp=>1);
-	if ($line =~ m/([0-9a-fA-F]{8,40})/) {
+	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),
-- 
1.6.1
Previous: Johannes SchindelinNext: Rafael Garcia-Suarez
Message 5 of 22 in “webgit highlightes mem adresses as git versions”
  1. Toralf FörsterFeb 2, 2009
  2. Jakub NarebskiFeb 2, 2009
  3. Toralf FörsterFeb 3, 2009
  4. Johannes SchindelinFeb 3, 2009
  5. gitweb: Better regexp for SHA-1 committag matchJakub Narebski, Feb 6, 2009
  6. Rafael Garcia-SuarezFeb 6, 2009
  7. Jakub NarebskiFeb 6, 2009
  8. Rafael Garcia-SuarezFeb 6, 2009
  9. [PATCHv2] gitweb: Better regexp for SHA-1 committag matchJakub Narebski, Feb 6, 2009
  10. Johannes SchindelinFeb 6, 2009
  11. Jay SoffianFeb 6, 2009
  12. Jakub NarebskiFeb 6, 2009
  13. Junio C HamanoFeb 7, 2009
  14. Jakub NarebskiFeb 7, 2009
  15. Junio C HamanoFeb 7, 2009
  16. Jakub NarebskiFeb 7, 2009
  17. demerphqFeb 7, 2009
  18. Jakub NarebskiFeb 7, 2009
  19. Jakub NarebskiFeb 7, 2009
  20. demerphqFeb 7, 2009
  21. Jakub NarebskiFeb 7, 2009
  22. demerphqFeb 7, 2009

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.