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

[PATCH 1/3] gitweb: Show target of symbolic link in "tree" view

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

In "tree" view (git_print_tree_entry subroutine), for entries which are symbolic links, add " -> link_target" after file name (a la "ls -l").

Link target is _not_ hyperlinked.

While at it, correct whitespaces (tabs are for aling, spaces are for indent) in modified git_print_tree_entry subroutine.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Jakub Narebski wrote:
> I'll split the patch into two: first to read link target and show it in 
> "tree" view _without_ hyperlink, and later perhaps either your or mine 
> solution (most probably yours), depending on feedback.
That implements the first part.
 gitweb/gitweb.perl |   42 ++++++++++++++++++++++++++++++++++--------
 1 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 5ea3fda..0c2cfc7 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1989,12 +1989,31 @@ sub git_print_log ($;%) {
 	}
 }
 
+# return link target (what link points to)
+sub git_get_link_target {
+	my $hash = shift;
+	my $link_target;
+
+	# read link
+	open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
+		or return;
+	{
+		local $/;
+		$link_target = <$fd>;
+	}
+	close $fd
+		or return;
+
+	return $link_target;
+}
+
+
 # print tree entry (row of git_tree), but without encompassing <tr> element
 sub git_print_tree_entry {
 	my ($t, $basedir, $hash_base, $have_blame) = @_;
 
 	my %base_key = ();
-	$base_key{hash_base} = $hash_base if defined $hash_base;
+	$base_key{'hash_base'} = $hash_base if defined $hash_base;
 
 	# The format of a table row is: mode list link.  Where mode is
 	# the mode of the entry, list is the name of the entry, an href,
@@ -2005,16 +2024,23 @@ sub git_print_tree_entry {
 		print "<td class=\"list\">" .
 			$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
 			                       file_name=>"$basedir$t->{'name'}", %base_key),
-			        -class => "list"}, esc_path($t->{'name'})) . "</td>\n";
+			        -class => "list"}, esc_path($t->{'name'}));
+		if (S_ISLNK(oct $t->{'mode'})) {
+			my $link_target = git_get_link_target($t->{'hash'});
+			if ($link_target) {
+				print " -> " . esc_path($link_target);
+			}
+		}
+		print "</td>\n";
 		print "<td class=\"link\">";
 		print $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
-					     file_name=>"$basedir$t->{'name'}", %base_key)},
-			      "blob");
+		                             file_name=>"$basedir$t->{'name'}", %base_key)},
+		              "blob");
 		if ($have_blame) {
 			print " | " .
 			      $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
-				                           file_name=>"$basedir$t->{'name'}", %base_key)},
-				            "blame");
+			                             file_name=>"$basedir$t->{'name'}", %base_key)},
+			              "blame");
 		}
 		if (defined $hash_base) {
 			print " | " .
@@ -2036,8 +2062,8 @@ sub git_print_tree_entry {
 		print "</td>\n";
 		print "<td class=\"link\">";
 		print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
-					     file_name=>"$basedir$t->{'name'}", %base_key)},
-			      "tree");
+		                             file_name=>"$basedir$t->{'name'}", %base_key)},
+		              "tree");
 		if (defined $hash_base) {
 			print " | " .
 			      $cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
-- 
1.4.4.1
Previous: Jakub NarebskiNext: Jakub Narebski
Message 8 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.