#include "cache.h"
#include "grep.h"
+#include "userdiff.h"
#include "xdiff-interface.h"
void append_header_grep_pattern(struct grep_opt *opt, enum grep_header_field field, const char *pat)
{
int rest = eol - bol;
- if (opt->pre_context || opt->post_context || opt->funcname) {
+ if (opt->pre_context || opt->post_context) {
if (opt->last_shown == 0) {
if (opt->show_hunk_mark)
- fputs(opt->funcname ? "==\n" : "--\n", stdout);
+ fputs("--\n", stdout);
else
opt->show_hunk_mark = 1;
- } else if (lno > opt->last_shown + 1) {
- if (opt->pre_context || opt->post_context)
- fputs((sign == '=') ? "==\n" : "--\n", stdout);
- else if (sign == '=')
- fputs("==\n", stdout);
- }
+ } else if (lno > opt->last_shown + 1)
+ fputs("--\n", stdout);
}
opt->last_shown = lno;
printf("%.*s\n", rest, bol);
}
-static int match_funcname(char *bol, char *eol)
+static int match_funcname(struct grep_opt *opt, char *bol, char *eol)
{
+ xdemitconf_t *xecfg = opt->priv;
+ if (xecfg && xecfg->find_func) {
+ char buf[1];
+ return xecfg->find_func(bol, eol - bol, buf, 1,
+ xecfg->find_func_priv) >= 0;
+ }
+
if (bol == eol)
return 0;
if (isalpha(*bol) || *bol == '_' || *bol == '$')
if (lno <= opt->last_shown)
break;
- if (match_funcname(bol, eol)) {
+ if (match_funcname(opt, bol, eol)) {
show_line(opt, bol, eol, name, lno, '=');
break;
}
while (bol > buf && bol[-1] != '\n')
bol--;
cur--;
- if (funcname_needed && match_funcname(bol, eol)) {
+ if (funcname_needed && match_funcname(opt, bol, eol)) {
funcname_lno = cur;
funcname_needed = 0;
}
int binary_match_only = 0;
unsigned count = 0;
enum grep_context ctx = GREP_CONTEXT_HEAD;
+ xdemitconf_t xecfg;
opt->last_shown = 0;
}
}
+ memset(&xecfg, 0, sizeof(xecfg));
+ if (opt->funcname && !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) {
+ const struct userdiff_funcname *pe = &drv->funcname;
+ xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
+ opt->priv = &xecfg;
+ }
+ }
+
while (left) {
char *eol, ch;
int hit;
return 1;
}
+ xdiff_clear_find_func(&xecfg);
+ opt->priv = NULL;
+
/* NEEDSWORK:
* The real "grep -c foo *.c" gives many "bar.c:0" lines,
* which feels mostly useless but sometimes useful. Maybe