{"thread":{"id":"29636","subject":"[PATCH (bugfix)] gitweb: Fix 'grep' search for multiple matches in file","startedAt":"2012-02-15T16:37:06Z","lastAt":"2012-02-15T16:37:06Z","messageCount":1,"participants":["Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"184769","messageId":"20120215163410.26917.84863.stgit@localhost.localdomain","threadId":"29636","inReplyTo":null,"subject":"[PATCH (bugfix)] gitweb: Fix 'grep' search for multiple matches in file","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-02-15T16:37:06Z","receivedAt":"2012-02-15T16:37:06Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Commit ff7f218 (gitweb: Fix file links in \"grep\" search, 2012-01-05),\nadded $file_href variable, to reduce duplication and have the fix\napplied in single place.\n\nUnfortunately it made variable defined inside the loop, not taking into\naccount the fact that $file_href was set only if file changed.\nTherefore for files with multiple matches $file_href was undefined for\nsecond and subsequent matches.\n\nFix this bug by moving $file_href declaration outside loop.\n\n\nAdds tests for almost all forms of sarch in gitweb, which were missing\nfrom testuite.  Note that it only tests if there are no warnings, and\nit doesn't check that gitweb finds what it should find.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nCommit ff7f218 is in v1.7.9\n\n gitweb/gitweb.perl                     |    3 ++\n t/t9500-gitweb-standalone-no-errors.sh |   39 ++++++++++++++++++++++++++++++++\n 2 files changed, 41 insertions(+), 1 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 4932f4b..a2e2023 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -6040,9 +6040,10 @@ sub git_search_files {\n \tmy $alternate = 1;\n \tmy $matches = 0;\n \tmy $lastfile = '';\n+\tmy $file_href;\n \twhile (my $line = <$fd>) {\n \t\tchomp $line;\n-\t\tmy ($file, $file_href, $lno, $ltext, $binary);\n+\t\tmy ($file, $lno, $ltext, $binary);\n \t\tlast if ($matches++ > 1000);\n \t\tif ($line =~ /^Binary file (.+) matches$/) {\n \t\t\t$file = $1;\ndiff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh\nindex 81246a6..90bb605 100755\n--- a/t/t9500-gitweb-standalone-no-errors.sh\n+++ b/t/t9500-gitweb-standalone-no-errors.sh\n@@ -638,6 +638,45 @@ test_expect_success \\\n \t'gitweb_run \"p=.git;a=tree\"'\n \n # ----------------------------------------------------------------------\n+# searching\n+\n+cat >>gitweb_config.perl <<\\EOF\n+\n+# enable search\n+$feature{'search'}{'default'} = [1];\n+$feature{'grep'}{'default'} = [1];\n+$feature{'pickaxe'}{'default'} = [1];\n+EOF\n+\n+test_expect_success \\\n+\t'search: preparation' \\\n+\t'echo \"1st MATCH\" >>file &&\n+\t echo \"2nd MATCH\" >>file &&\n+\t echo \"MATCH\" >>bar &&\n+\t git add file bar &&\n+\t git commit -m \"Added MATCH word\"'\n+\n+test_expect_success \\\n+\t'search: commit author' \\\n+\t'gitweb_run \"p=.git;a=search;h=HEAD;st=author;s=A+U+Thor\"'\n+\n+test_expect_success \\\n+\t'search: commit message' \\\n+\t'gitweb_run \"p=.git;a=search;h=HEAD;st=commitr;s=MATCH\"'\n+\n+test_expect_success \\\n+\t'search: grep' \\\n+\t'gitweb_run \"p=.git;a=search;h=HEAD;st=grep;s=MATCH\"'\n+\n+test_expect_success \\\n+\t'search: pickaxe' \\\n+\t'gitweb_run \"p=.git;a=search;h=HEAD;st=pickaxe;s=MATCH\"'\n+\n+test_expect_success \\\n+\t'search: projects' \\\n+\t'gitweb_run \"a=project_list;s=.git\"'\n+\n+# ----------------------------------------------------------------------\n # non-ASCII in README.html\n \n test_expect_success \\\n"}]}