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

[PATCH/RFC 4/3] gitweb: SHA-1 in commit log message links to "object" view

From
Jakub Narebski <jnareb@gmail.com>
Date
Dec 10, 2006, 12:25 UTC
Message-ID
<11657536473295-git-send-email-jnareb@gmail.com>
In-Reply-To
<7vk616ezu5.fsf@assigned-by-dhcp.cox.net>

Instead of checking if explicit SHA-1 in commit log message is sha1 of commit and making link to "commit" view, make [fragment of] explicit SHA-1 in commit log message link to "object" view. While at it allow to hyperlink also shortened SHA-1, from 8 characters up to full SHA-1, instead of requiring full 40 characters of SHA-1.

This makes the following changes:
 * SHA-1 of objects which no longer exists, for example in commit
   cherry-picked from no longer existing temporary branch, or revert
   of commit in rebased branch, are no longer marked as such by not
   being made into hyperlink (and not having default hyperlink view:
   being underlined among others).  On the other hand it makes gitweb
   to not write error messages when object is not found to web serwer
   log; it also moves cost of getting type and SHA-1 validation to
   when link is clicked, and not only viewed.
 * SHA-1 of other objects: blobs, trees, tags are also hyperlinked
   and lead to appropriate view (although in the case of tags it is
   more natural to just use tag name).
 * You can put shortened SHA-1 of commit in the commit message, and it
   would be hyperlinked; it would be checked on clicking if abbrev is
   unique.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This follows the "lazy hyperlink" idea of symbolic link support in the
"tree" view.

It is an RFC (Requests For Comments) because I'm not sure if it wouldn't be better to make dead SHA-1 marked in commit log message, instead of finfing it out after clicking...

 gitweb/gitweb.perl |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 6493311..7d24c10 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -828,14 +828,12 @@ sub format_log_line_html {
 	my $line = shift;
 
 	$line = esc_html($line, -nbsp=>1);
-	if ($line =~ m/([0-9a-fA-F]{40})/) {
+	if ($line =~ m/([0-9a-fA-F]{8,40})/) {
 		my $hash_text = $1;
-		if (git_get_type($hash_text) eq "commit") {
-			my $link =
-				$cgi->a({-href => href(action=>"commit", hash=>$hash_text),
-				        -class => "text"}, $hash_text);
-			$line =~ s/$hash_text/$link/;
-		}
+		my $link =
+			$cgi->a({-href => href(action=>"object", hash=>$hash_text),
+			        -class => "text"}, $hash_text);
+		$line =~ s/$hash_text/$link/;
 	}
 	return $line;
 }
-- 
1.4.4.1
Previous: Jakub NarebskiNext: Junio C Hamano
Message 11 of 12 in “gitweb: Better symbolic link support in "tree" view”
  1. gitweb: Better symbolic link support in "tree" viewJakub Narebsmi, Dec 4, 2006
  2. Junio C HamanoDec 5, 2006
  3. Jakub NarebskiDec 5, 2006
  4. Junio C HamanoDec 5, 2006
  5. Jakub NarebskiDec 5, 2006
  6. 0/3 gitweb: Better symbolic link support in "tree" viewJakub Narebski, Dec 10, 2006
  7. 0/3 gitweb: Better symbolic link support in "tree" viewJakub Narebski, Dec 10, 2006
  8. 1/3 gitweb: Show target of symbolic link in "tree" viewJakub Narebski, Dec 10, 2006
  9. 2/3 gitweb: Add generic git_object subroutine to display object of any typeJakub Narebski, Dec 10, 2006
  10. 3/3 gitweb: Hyperlink target of symbolic link in "tree" view (if possible)Jakub Narebski, Dec 10, 2006
  11. 4/3 gitweb: SHA-1 in commit log message links to "object" viewJakub Narebski, Dec 10, 2006
  12. Junio C HamanoDec 10, 2006

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.