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 <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Rast committed
Dec 12, 2011 at 22:16 UTC
b8ffedca6f9e1043956ba611ae52bea449779456
2 files changed
+18
-3
grep.c
+4
-3
@@ -948,8 +948,8 @@ int grep_threads_ok(const struct grep_opt *opt)
948
* machinery in grep_buffer_1. The attribute code is not
949
* thread safe, so we disable the use of threads.
950
*/
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)
953
return 0;
954
955
return 1;
@@ -1008,7 +1008,8 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
1008
}
1009
1010
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 &&
1013
!opt->name_only && !binary_match_only && !collect_hits) {
1014
struct userdiff_driver *drv = userdiff_find_by_path(name);
1015
if (drv && drv->funcname.pattern) {
t/t7810-grep.sh
+14
@@ -523,6 +523,20 @@ test_expect_success 'grep -W' '
523
test_cmp expected actual
524
'
525
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
+
540
test_expect_success 'grep from a subdirectory to search wider area (1)' '
541
mkdir -p s &&
542
(