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 <th.perl@gmail.com> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jakub Narebski committed Jan 5, 2012 at 21:26 UTC ff7f2185d6e04b7bea66f39ee51d79919ab1279c
1 file changed +7 -8
gitweb/gitweb.perl
+7 -8
@@ -5715,7 +5715,7 @@ sub git_search_files {
5715 my $lastfile = '';
5716 while (my $line = <$fd>) {
5717 chomp $line;
5718 - my ($file, $lno, $ltext, $binary);
5718 + my ($file, $file_href, $lno, $ltext, $binary);
5719 last if ($matches++ > 1000);
5720 if ($line =~ /^Binary file (.+) matches$/) {
5721 $file = $1;
@@ -5730,10 +5730,10 @@ sub git_search_files {
5730 } else {
5731 print "<tr class=\"light\">\n";
5732 }
5733 + $file_href = href(action=>"blob", hash_base=>$co{'id'},
5734 + file_name=>$file);
5735 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));
5737 print "</td><td>\n";
5738 $lastfile = $file;
5739 }
@@ -5751,10 +5751,9 @@ sub git_search_files {
5751 $ltext = esc_html($ltext, -nbsp=>1);
5752 }
5753 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";
5757 }
5758 }
5759 if ($lastfile) {