Skip to content

Commit fc8fcd2

Browse files
jnarebgitster
authored andcommitted
gitweb: Fix 'grep' search for multiple matches in file
Commit ff7f218 (gitweb: Fix file links in "grep" search, 2012-01-05), added $file_href variable, to reduce duplication and have the fix applied in single place. Unfortunately it made variable defined inside the loop, not taking into account the fact that $file_href was set only if file changed. Therefore for files with multiple matches $file_href was undefined for second and subsequent matches. Fix this bug by moving $file_href declaration outside loop. Adds tests for almost all forms of sarch in gitweb, which were missing from testuite. Note that it only tests if there are no warnings, and it doesn't check that gitweb finds what it should find. Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d1ba7a4 commit fc8fcd2

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

gitweb/gitweb.perl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5850,9 +5850,10 @@ sub git_search_files {
58505850
my $alternate = 1;
58515851
my $matches = 0;
58525852
my $lastfile = '';
5853+
my $file_href;
58535854
while (my $line = <$fd>) {
58545855
chomp $line;
5855-
my ($file, $file_href, $lno, $ltext, $binary);
5856+
my ($file, $lno, $ltext, $binary);
58565857
last if ($matches++ > 1000);
58575858
if ($line =~ /^Binary file (.+) matches$/) {
58585859
$file = $1;

t/t9500-gitweb-standalone-no-errors.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,45 @@ test_expect_success \
629629
'config override: tree view, features enabled in repo config (2)' \
630630
'gitweb_run "p=.git;a=tree"'
631631

632+
# ----------------------------------------------------------------------
633+
# searching
634+
635+
cat >>gitweb_config.perl <<\EOF
636+
637+
# enable search
638+
$feature{'search'}{'default'} = [1];
639+
$feature{'grep'}{'default'} = [1];
640+
$feature{'pickaxe'}{'default'} = [1];
641+
EOF
642+
643+
test_expect_success \
644+
'search: preparation' \
645+
'echo "1st MATCH" >>file &&
646+
echo "2nd MATCH" >>file &&
647+
echo "MATCH" >>bar &&
648+
git add file bar &&
649+
git commit -m "Added MATCH word"'
650+
651+
test_expect_success \
652+
'search: commit author' \
653+
'gitweb_run "p=.git;a=search;h=HEAD;st=author;s=A+U+Thor"'
654+
655+
test_expect_success \
656+
'search: commit message' \
657+
'gitweb_run "p=.git;a=search;h=HEAD;st=commitr;s=MATCH"'
658+
659+
test_expect_success \
660+
'search: grep' \
661+
'gitweb_run "p=.git;a=search;h=HEAD;st=grep;s=MATCH"'
662+
663+
test_expect_success \
664+
'search: pickaxe' \
665+
'gitweb_run "p=.git;a=search;h=HEAD;st=pickaxe;s=MATCH"'
666+
667+
test_expect_success \
668+
'search: projects' \
669+
'gitweb_run "a=project_list;s=.git"'
670+
632671
# ----------------------------------------------------------------------
633672
# non-ASCII in README.html
634673

0 commit comments

Comments
 (0)