Skip to content

Commit b8ffedc

Browse files
trastgitster
authored andcommitted
grep: load funcname patterns for -W
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]>
1 parent 9859a02 commit b8ffedc

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

grep.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,8 @@ int grep_threads_ok(const struct grep_opt *opt)
948948
* machinery in grep_buffer_1. The attribute code is not
949949
* thread safe, so we disable the use of threads.
950950
*/
951-
if (opt->funcname && !opt->unmatch_name_only && !opt->status_only &&
952-
!opt->name_only)
951+
if ((opt->funcname || opt->funcbody)
952+
&& !opt->unmatch_name_only && !opt->status_only && !opt->name_only)
953953
return 0;
954954

955955
return 1;
@@ -1008,7 +1008,8 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
10081008
}
10091009

10101010
memset(&xecfg, 0, sizeof(xecfg));
1011-
if (opt->funcname && !opt->unmatch_name_only && !opt->status_only &&
1011+
if ((opt->funcname || opt->funcbody)
1012+
&& !opt->unmatch_name_only && !opt->status_only &&
10121013
!opt->name_only && !binary_match_only && !collect_hits) {
10131014
struct userdiff_driver *drv = userdiff_find_by_path(name);
10141015
if (drv && drv->funcname.pattern) {

t/t7810-grep.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,20 @@ test_expect_success 'grep -W' '
523523
test_cmp expected actual
524524
'
525525

526+
cat >expected <<EOF
527+
hello.c= printf("Hello world.\n");
528+
hello.c: return 0;
529+
hello.c- /* char ?? */
530+
EOF
531+
532+
test_expect_success 'grep -W with userdiff' '
533+
test_when_finished "rm -f .gitattributes" &&
534+
git config diff.custom.xfuncname "(printf.*|})$" &&
535+
echo "hello.c diff=custom" >.gitattributes &&
536+
git grep -W return >actual &&
537+
test_cmp expected actual
538+
'
539+
526540
test_expect_success 'grep from a subdirectory to search wider area (1)' '
527541
mkdir -p s &&
528542
(

0 commit comments

Comments
 (0)