Skip to content

Commit ff7f218

Browse files
jnarebgitster
authored andcommitted
gitweb: Fix file links in "grep" search
There were two bugs in generating file links (links to "blob" view), one hidden by the other. The correct way of generating file link is href(action=>"blob", hash_base=>$co{'id'}, file_name=>$file); It was $co{'hash'} (this key does not exist, and therefore this is undef), and 'hash' instead of 'hash_base'. To have this fix applied in single place, this commit also reduces code duplication by saving file link (which is used for line links) in $file_href. Reported-by: Thomas Perl <[email protected]> Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1327d83 commit ff7f218

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

gitweb/gitweb.perl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5715,7 +5715,7 @@ sub git_search_files {
57155715
my $lastfile = '';
57165716
while (my $line = <$fd>) {
57175717
chomp $line;
5718-
my ($file, $lno, $ltext, $binary);
5718+
my ($file, $file_href, $lno, $ltext, $binary);
57195719
last if ($matches++ > 1000);
57205720
if ($line =~ /^Binary file (.+) matches$/) {
57215721
$file = $1;
@@ -5730,10 +5730,10 @@ sub git_search_files {
57305730
} else {
57315731
print "<tr class=\"light\">\n";
57325732
}
5733+
$file_href = href(action=>"blob", hash_base=>$co{'id'},
5734+
file_name=>$file);
57335735
print "<td class=\"list\">".
5734-
$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
5735-
file_name=>"$file"),
5736-
-class => "list"}, esc_path($file));
5736+
$cgi->a({-href => $file_href, -class => "list"}, esc_path($file));
57375737
print "</td><td>\n";
57385738
$lastfile = $file;
57395739
}
@@ -5751,10 +5751,9 @@ sub git_search_files {
57515751
$ltext = esc_html($ltext, -nbsp=>1);
57525752
}
57535753
print "<div class=\"pre\">" .
5754-
$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
5755-
file_name=>"$file").'#l'.$lno,
5756-
-class => "linenr"}, sprintf('%4i', $lno))
5757-
. ' ' . $ltext . "</div>\n";
5754+
$cgi->a({-href => $file_href.'#l'.$lno,
5755+
-class => "linenr"}, sprintf('%4i', $lno)) .
5756+
' ' . $ltext . "</div>\n";
57585757
}
57595758
}
57605759
if ($lastfile) {

0 commit comments

Comments
 (0)