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

Jakub Narebski committed Feb 15, 2012 at 17:37 UTC fc8fcd27e67ad06689a823dd83a929624e359cc1
2 files changed +41 -1
gitweb/gitweb.perl
+2 -1
@@ -5850,9 +5850,10 @@ sub git_search_files {
5850 my $alternate = 1;
5851 my $matches = 0;
5852 my $lastfile = '';
5853 + my $file_href;
5854 while (my $line = <$fd>) {
5855 chomp $line;
5855 - my ($file, $file_href, $lno, $ltext, $binary);
5856 + my ($file, $lno, $ltext, $binary);
5857 last if ($matches++ > 1000);
5858 if ($line =~ /^Binary file (.+) matches$/) {
5859 $file = $1;
t/t9500-gitweb-standalone-no-errors.sh
+39
@@ -629,6 +629,45 @@ test_expect_success \
629 'config override: tree view, features enabled in repo config (2)' \
630 'gitweb_run "p=.git;a=tree"'
631
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 +
671 # ----------------------------------------------------------------------
672 # non-ASCII in README.html
673