Skip to content

Commit

Permalink
grep: load funcname patterns for -W
Browse files Browse the repository at this point in the history
git-grep avoids loading the funcname patterns unless they are needed.
ba8ea74 (grep: add option to show whole function as context,
2011-08-01) forgot to extend this test also to the new funcbody
feature.  Do so.

The catch is that we also have to disable threading when using
userdiff, as explained in grep_threads_ok().  So we must be careful to
introduce the same test there.

Signed-off-by: Thomas Rast <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
trast authored and gitster committed Dec 12, 2011
1 parent 9859a02 commit b8ffedc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 4 additions & 3 deletions grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,8 @@ int grep_threads_ok(const struct grep_opt *opt)
* machinery in grep_buffer_1. The attribute code is not
* thread safe, so we disable the use of threads.
*/
if (opt->funcname && !opt->unmatch_name_only && !opt->status_only &&
!opt->name_only)
if ((opt->funcname || opt->funcbody)
&& !opt->unmatch_name_only && !opt->status_only && !opt->name_only)
return 0;

return 1;
Expand Down Expand Up @@ -1008,7 +1008,8 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
}

memset(&xecfg, 0, sizeof(xecfg));
if (opt->funcname && !opt->unmatch_name_only && !opt->status_only &&
if ((opt->funcname || opt->funcbody)
&& !opt->unmatch_name_only && !opt->status_only &&
!opt->name_only && !binary_match_only && !collect_hits) {
struct userdiff_driver *drv = userdiff_find_by_path(name);
if (drv && drv->funcname.pattern) {
Expand Down
14 changes: 14 additions & 0 deletions t/t7810-grep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,20 @@ test_expect_success 'grep -W' '
test_cmp expected actual
'

cat >expected <<EOF
hello.c= printf("Hello world.\n");
hello.c: return 0;
hello.c- /* char ?? */
EOF

test_expect_success 'grep -W with userdiff' '
test_when_finished "rm -f .gitattributes" &&
git config diff.custom.xfuncname "(printf.*|})$" &&
echo "hello.c diff=custom" >.gitattributes &&
git grep -W return >actual &&
test_cmp expected actual
'

test_expect_success 'grep from a subdirectory to search wider area (1)' '
mkdir -p s &&
(
Expand Down

0 comments on commit b8ffedc

Please sign in to comment.