11#include "cache.h"
22#include "grep.h"
3+ #include "userdiff.h"
34#include "xdiff-interface.h"
45
56void append_header_grep_pattern (struct grep_opt * opt , enum grep_header_field field , const char * pat )
@@ -535,8 +536,15 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
535536 printf ("%.*s\n" , rest , bol );
536537}
537538
538- static int match_funcname (char * bol , char * eol )
539+ static int match_funcname (struct grep_opt * opt , char * bol , char * eol )
539540{
541+ xdemitconf_t * xecfg = opt -> priv ;
542+ if (xecfg && xecfg -> find_func ) {
543+ char buf [1 ];
544+ return xecfg -> find_func (bol , eol - bol , buf , 1 ,
545+ xecfg -> find_func_priv ) >= 0 ;
546+ }
547+
540548 if (bol == eol )
541549 return 0 ;
542550 if (isalpha (* bol ) || * bol == '_' || * bol == '$' )
@@ -557,7 +565,7 @@ static void show_funcname_line(struct grep_opt *opt, const char *name,
557565 if (lno <= opt -> last_shown )
558566 break ;
559567
560- if (match_funcname (bol , eol )) {
568+ if (match_funcname (opt , bol , eol )) {
561569 show_line (opt , bol , eol , name , lno , '=' );
562570 break ;
563571 }
@@ -582,7 +590,7 @@ static void show_pre_context(struct grep_opt *opt, const char *name, char *buf,
582590 while (bol > buf && bol [-1 ] != '\n' )
583591 bol -- ;
584592 cur -- ;
585- if (funcname_needed && match_funcname (bol , eol )) {
593+ if (funcname_needed && match_funcname (opt , bol , eol )) {
586594 funcname_lno = cur ;
587595 funcname_needed = 0 ;
588596 }
@@ -614,6 +622,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
614622 int binary_match_only = 0 ;
615623 unsigned count = 0 ;
616624 enum grep_context ctx = GREP_CONTEXT_HEAD ;
625+ xdemitconf_t xecfg ;
617626
618627 opt -> last_shown = 0 ;
619628
@@ -630,6 +639,17 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
630639 }
631640 }
632641
642+ memset (& xecfg , 0 , sizeof (xecfg ));
643+ if (opt -> funcname && !opt -> unmatch_name_only && !opt -> status_only &&
644+ !opt -> name_only && !binary_match_only && !collect_hits ) {
645+ struct userdiff_driver * drv = userdiff_find_by_path (name );
646+ if (drv && drv -> funcname .pattern ) {
647+ const struct userdiff_funcname * pe = & drv -> funcname ;
648+ xdiff_set_find_func (& xecfg , pe -> pattern , pe -> cflags );
649+ opt -> priv = & xecfg ;
650+ }
651+ }
652+
633653 while (left ) {
634654 char * eol , ch ;
635655 int hit ;
@@ -711,6 +731,9 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,
711731 return 1 ;
712732 }
713733
734+ xdiff_clear_find_func (& xecfg );
735+ opt -> priv = NULL ;
736+
714737 /* NEEDSWORK:
715738 * The real "grep -c foo *.c" gives many "bar.c:0" lines,
716739 * which feels mostly useless but sometimes useful. Maybe
0 commit comments