gitweb: Show target of symbolic link in "tree" view
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> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jakub Narebski committed
Dec 10, 2006 at 13:25 UTC
e33fba4c5a33bce748d2c8a1c7a38b78a1fd2cda
1 file changed
+34
-8
gitweb/gitweb.perl
+34
-8
@@ -1989,12 +1989,31 @@ sub git_print_log ($;%) {
1989
}
1990
}
1991
1992
+# return link target (what link points to)
1993
+sub git_get_link_target {
1994
+ my $hash = shift;
1995
+ my $link_target;
1996
+
1997
+ # read link
1998
+ open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
1999
+ or return;
2000
+ {
2001
+ local $/;
2002
+ $link_target = <$fd>;
2003
+ }
2004
+ close $fd
2005
+ or return;
2006
+
2007
+ return $link_target;
2008
+}
2009
+
2010
+
2011
# print tree entry (row of git_tree), but without encompassing <tr> element
2012
sub git_print_tree_entry {
2013
my ($t, $basedir, $hash_base, $have_blame) = @_;
2014
2015
my %base_key = ();
1997
- $base_key{hash_base} = $hash_base if defined $hash_base;
2016
+ $base_key{'hash_base'} = $hash_base if defined $hash_base;
2017
2018
# The format of a table row is: mode list link. Where mode is
2019
# the mode of the entry, list is the name of the entry, an href,
@@ -2005,16 +2024,23 @@ sub git_print_tree_entry {
2024
print "<td class=\"list\">" .
2025
$cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
2026
file_name=>"$basedir$t->{'name'}", %base_key),
2008
- -class => "list"}, esc_path($t->{'name'})) . "</td>\n";
2027
+ -class => "list"}, esc_path($t->{'name'}));
2028
+ if (S_ISLNK(oct $t->{'mode'})) {
2029
+ my $link_target = git_get_link_target($t->{'hash'});
2030
+ if ($link_target) {
2031
+ print " -> " . esc_path($link_target);
2032
+ }
2033
+ }
2034
+ print "</td>\n";
2035
print "<td class=\"link\">";
2036
print $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
2011
- file_name=>"$basedir$t->{'name'}", %base_key)},
2012
- "blob");
2037
+ file_name=>"$basedir$t->{'name'}", %base_key)},
2038
+ "blob");
2039
if ($have_blame) {
2040
print " | " .
2041
$cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'},
2016
- file_name=>"$basedir$t->{'name'}", %base_key)},
2017
- "blame");
2042
+ file_name=>"$basedir$t->{'name'}", %base_key)},
2043
+ "blame");
2044
}
2045
if (defined $hash_base) {
2046
print " | " .
@@ -2036,8 +2062,8 @@ sub git_print_tree_entry {
2062
print "</td>\n";
2063
print "<td class=\"link\">";
2064
print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
2039
- file_name=>"$basedir$t->{'name'}", %base_key)},
2040
- "tree");
2065
+ file_name=>"$basedir$t->{'name'}", %base_key)},
2066
+ "tree");
2067
if (defined $hash_base) {
2068
print " | " .
2069
$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,