diff.c: associate a flag with each pattern and use it for compiling regex
This is in preparation for allowing extended regular expression patterns. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
45e7ca0f0e
commit
a013585b20
21
diff.c
21
diff.c
@ -97,13 +97,14 @@ static int parse_lldiff_command(const char *var, const char *ep, const char *val
|
|||||||
struct funcname_pattern_entry {
|
struct funcname_pattern_entry {
|
||||||
char *name;
|
char *name;
|
||||||
char *pattern;
|
char *pattern;
|
||||||
|
int cflags;
|
||||||
};
|
};
|
||||||
static struct funcname_pattern_list {
|
static struct funcname_pattern_list {
|
||||||
struct funcname_pattern_list *next;
|
struct funcname_pattern_list *next;
|
||||||
struct funcname_pattern_entry e;
|
struct funcname_pattern_entry e;
|
||||||
} *funcname_pattern_list;
|
} *funcname_pattern_list;
|
||||||
|
|
||||||
static int parse_funcname_pattern(const char *var, const char *ep, const char *value)
|
static int parse_funcname_pattern(const char *var, const char *ep, const char *value, int cflags)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
int namelen;
|
int namelen;
|
||||||
@ -123,6 +124,7 @@ static int parse_funcname_pattern(const char *var, const char *ep, const char *v
|
|||||||
}
|
}
|
||||||
free(pp->e.pattern);
|
free(pp->e.pattern);
|
||||||
pp->e.pattern = xstrdup(value);
|
pp->e.pattern = xstrdup(value);
|
||||||
|
pp->e.cflags = cflags;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +187,8 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
|
|||||||
if (!strcmp(ep, ".funcname")) {
|
if (!strcmp(ep, ".funcname")) {
|
||||||
if (!value)
|
if (!value)
|
||||||
return config_error_nonbool(var);
|
return config_error_nonbool(var);
|
||||||
return parse_funcname_pattern(var, ep, value);
|
return parse_funcname_pattern(var, ep, value,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1395,16 +1398,16 @@ static const struct funcname_pattern_entry builtin_funcname_pattern[] = {
|
|||||||
"new\\|return\\|switch\\|throw\\|while\\)\n"
|
"new\\|return\\|switch\\|throw\\|while\\)\n"
|
||||||
"^[ ]*\\(\\([ ]*"
|
"^[ ]*\\(\\([ ]*"
|
||||||
"[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}"
|
"[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}"
|
||||||
"[ ]*([^;]*\\)$" },
|
"[ ]*([^;]*\\)$", 0 },
|
||||||
{ "pascal", "^\\(\\(procedure\\|function\\|constructor\\|"
|
{ "pascal", "^\\(\\(procedure\\|function\\|constructor\\|"
|
||||||
"destructor\\|interface\\|implementation\\|"
|
"destructor\\|interface\\|implementation\\|"
|
||||||
"initialization\\|finalization\\)[ \t]*.*\\)$"
|
"initialization\\|finalization\\)[ \t]*.*\\)$"
|
||||||
"\\|"
|
"\\|"
|
||||||
"^\\(.*=[ \t]*\\(class\\|record\\).*\\)$"
|
"^\\(.*=[ \t]*\\(class\\|record\\).*\\)$",
|
||||||
},
|
0 },
|
||||||
{ "bibtex", "\\(@[a-zA-Z]\\{1,\\}[ \t]*{\\{0,1\\}[ \t]*[^ \t\"@',\\#}{~%]*\\).*$" },
|
{ "bibtex", "\\(@[a-zA-Z]\\{1,\\}[ \t]*{\\{0,1\\}[ \t]*[^ \t\"@',\\#}{~%]*\\).*$", 0 },
|
||||||
{ "tex", "^\\(\\\\\\(\\(sub\\)*section\\|chapter\\|part\\)\\*\\{0,1\\}{.*\\)$" },
|
{ "tex", "^\\(\\\\\\(\\(sub\\)*section\\|chapter\\|part\\)\\*\\{0,1\\}{.*\\)$", 0 },
|
||||||
{ "ruby", "^\\s*\\(\\(class\\|module\\|def\\)\\s.*\\)$" },
|
{ "ruby", "^\\s*\\(\\(class\\|module\\|def\\)\\s.*\\)$", 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct funcname_pattern_entry *diff_funcname_pattern(struct diff_filespec *one)
|
static const struct funcname_pattern_entry *diff_funcname_pattern(struct diff_filespec *one)
|
||||||
@ -1530,7 +1533,7 @@ static void builtin_diff(const char *name_a,
|
|||||||
xecfg.ctxlen = o->context;
|
xecfg.ctxlen = o->context;
|
||||||
xecfg.flags = XDL_EMIT_FUNCNAMES;
|
xecfg.flags = XDL_EMIT_FUNCNAMES;
|
||||||
if (pe)
|
if (pe)
|
||||||
xdiff_set_find_func(&xecfg, pe->pattern);
|
xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
|
||||||
if (!diffopts)
|
if (!diffopts)
|
||||||
;
|
;
|
||||||
else if (!prefixcmp(diffopts, "--unified="))
|
else if (!prefixcmp(diffopts, "--unified="))
|
||||||
|
@ -206,7 +206,7 @@ static long ff_regexp(const char *line, long len,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value)
|
void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value, int cflags)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct ff_regs *regs;
|
struct ff_regs *regs;
|
||||||
@ -231,7 +231,7 @@ void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value)
|
|||||||
expression = buffer = xstrndup(value, ep - value);
|
expression = buffer = xstrndup(value, ep - value);
|
||||||
else
|
else
|
||||||
expression = value;
|
expression = value;
|
||||||
if (regcomp(®->re, expression, 0))
|
if (regcomp(®->re, expression, cflags))
|
||||||
die("Invalid regexp to look for hunk header: %s", expression);
|
die("Invalid regexp to look for hunk header: %s", expression);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
value = ep + 1;
|
value = ep + 1;
|
||||||
|
@ -21,6 +21,6 @@ int parse_hunk_header(char *line, int len,
|
|||||||
int read_mmfile(mmfile_t *ptr, const char *filename);
|
int read_mmfile(mmfile_t *ptr, const char *filename);
|
||||||
int buffer_is_binary(const char *ptr, unsigned long size);
|
int buffer_is_binary(const char *ptr, unsigned long size);
|
||||||
|
|
||||||
extern void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line);
|
extern void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user