Skip to content

Commit

Permalink
gitweb: Fix file links in "grep" search
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jakub Narebski authored and Junio C Hamano committed Jan 5, 2012
1 parent 1327d83 commit ff7f218
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -5715,7 +5715,7 @@ sub git_search_files {
my $lastfile = '';
while (my $line = <$fd>) {
chomp $line;
my ($file, $lno, $ltext, $binary);
my ($file, $file_href, $lno, $ltext, $binary);
last if ($matches++ > 1000);
if ($line =~ /^Binary file (.+) matches$/) {
$file = $1;
Expand All @@ -5730,10 +5730,10 @@ sub git_search_files {
} else {
print "<tr class=\"light\">\n";
}
$file_href = href(action=>"blob", hash_base=>$co{'id'},
file_name=>$file);
print "<td class=\"list\">".
$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
file_name=>"$file"),
-class => "list"}, esc_path($file));
$cgi->a({-href => $file_href, -class => "list"}, esc_path($file));
print "</td><td>\n";
$lastfile = $file;
}
Expand All @@ -5751,10 +5751,9 @@ sub git_search_files {
$ltext = esc_html($ltext, -nbsp=>1);
}
print "<div class=\"pre\">" .
$cgi->a({-href => href(action=>"blob", hash=>$co{'hash'},
file_name=>"$file").'#l'.$lno,
-class => "linenr"}, sprintf('%4i', $lno))
. ' ' . $ltext . "</div>\n";
$cgi->a({-href => $file_href.'#l'.$lno,
-class => "linenr"}, sprintf('%4i', $lno)) .
' ' . $ltext . "</div>\n";
}
}
if ($lastfile) {
Expand Down

0 comments on commit ff7f218

Please sign in to comment.