diff.c: return pattern entry pointer rather than just the hunk header pattern
This is in preparation for associating a flag with each pattern which will control how the pattern is interpreted. For example, as a basic or extended regular expression. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
1f5a892e52
commit
45e7ca0f0e
55
diff.c
55
diff.c
@ -94,32 +94,35 @@ static int parse_lldiff_command(const char *var, const char *ep, const char *val
|
|||||||
* to define a customized regexp to find the beginning of a function to
|
* to define a customized regexp to find the beginning of a function to
|
||||||
* be used for hunk header lines of "diff -p" style output.
|
* be used for hunk header lines of "diff -p" style output.
|
||||||
*/
|
*/
|
||||||
static struct funcname_pattern {
|
struct funcname_pattern_entry {
|
||||||
char *name;
|
char *name;
|
||||||
char *pattern;
|
char *pattern;
|
||||||
struct funcname_pattern *next;
|
};
|
||||||
|
static struct funcname_pattern_list {
|
||||||
|
struct funcname_pattern_list *next;
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
int namelen;
|
int namelen;
|
||||||
struct funcname_pattern *pp;
|
struct funcname_pattern_list *pp;
|
||||||
|
|
||||||
name = var + 5; /* "diff." */
|
name = var + 5; /* "diff." */
|
||||||
namelen = ep - name;
|
namelen = ep - name;
|
||||||
|
|
||||||
for (pp = funcname_pattern_list; pp; pp = pp->next)
|
for (pp = funcname_pattern_list; pp; pp = pp->next)
|
||||||
if (!strncmp(pp->name, name, namelen) && !pp->name[namelen])
|
if (!strncmp(pp->e.name, name, namelen) && !pp->e.name[namelen])
|
||||||
break;
|
break;
|
||||||
if (!pp) {
|
if (!pp) {
|
||||||
pp = xcalloc(1, sizeof(*pp));
|
pp = xcalloc(1, sizeof(*pp));
|
||||||
pp->name = xmemdupz(name, namelen);
|
pp->e.name = xmemdupz(name, namelen);
|
||||||
pp->next = funcname_pattern_list;
|
pp->next = funcname_pattern_list;
|
||||||
funcname_pattern_list = pp;
|
funcname_pattern_list = pp;
|
||||||
}
|
}
|
||||||
free(pp->pattern);
|
free(pp->e.pattern);
|
||||||
pp->pattern = xstrdup(value);
|
pp->e.pattern = xstrdup(value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1377,20 +1380,17 @@ int diff_filespec_is_binary(struct diff_filespec *one)
|
|||||||
return one->is_binary;
|
return one->is_binary;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *funcname_pattern(const char *ident)
|
static const struct funcname_pattern_entry *funcname_pattern(const char *ident)
|
||||||
{
|
{
|
||||||
struct funcname_pattern *pp;
|
struct funcname_pattern_list *pp;
|
||||||
|
|
||||||
for (pp = funcname_pattern_list; pp; pp = pp->next)
|
for (pp = funcname_pattern_list; pp; pp = pp->next)
|
||||||
if (!strcmp(ident, pp->name))
|
if (!strcmp(ident, pp->e.name))
|
||||||
return pp->pattern;
|
return &pp->e;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct builtin_funcname_pattern {
|
static const struct funcname_pattern_entry builtin_funcname_pattern[] = {
|
||||||
const char *name;
|
|
||||||
const char *pattern;
|
|
||||||
} builtin_funcname_pattern[] = {
|
|
||||||
{ "java", "!^[ ]*\\(catch\\|do\\|for\\|if\\|instanceof\\|"
|
{ "java", "!^[ ]*\\(catch\\|do\\|for\\|if\\|instanceof\\|"
|
||||||
"new\\|return\\|switch\\|throw\\|while\\)\n"
|
"new\\|return\\|switch\\|throw\\|while\\)\n"
|
||||||
"^[ ]*\\(\\([ ]*"
|
"^[ ]*\\(\\([ ]*"
|
||||||
@ -1407,9 +1407,10 @@ static struct builtin_funcname_pattern {
|
|||||||
{ "ruby", "^\\s*\\(\\(class\\|module\\|def\\)\\s.*\\)$" },
|
{ "ruby", "^\\s*\\(\\(class\\|module\\|def\\)\\s.*\\)$" },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *diff_funcname_pattern(struct diff_filespec *one)
|
static const struct funcname_pattern_entry *diff_funcname_pattern(struct diff_filespec *one)
|
||||||
{
|
{
|
||||||
const char *ident, *pattern;
|
const char *ident;
|
||||||
|
const struct funcname_pattern_entry *pe;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
diff_filespec_check_attr(one);
|
diff_filespec_check_attr(one);
|
||||||
@ -1424,9 +1425,9 @@ static const char *diff_funcname_pattern(struct diff_filespec *one)
|
|||||||
return funcname_pattern("default");
|
return funcname_pattern("default");
|
||||||
|
|
||||||
/* Look up custom "funcname.$ident" regexp from config. */
|
/* Look up custom "funcname.$ident" regexp from config. */
|
||||||
pattern = funcname_pattern(ident);
|
pe = funcname_pattern(ident);
|
||||||
if (pattern)
|
if (pe)
|
||||||
return pattern;
|
return pe;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* And define built-in fallback patterns here. Note that
|
* And define built-in fallback patterns here. Note that
|
||||||
@ -1434,7 +1435,7 @@ static const char *diff_funcname_pattern(struct diff_filespec *one)
|
|||||||
*/
|
*/
|
||||||
for (i = 0; i < ARRAY_SIZE(builtin_funcname_pattern); i++)
|
for (i = 0; i < ARRAY_SIZE(builtin_funcname_pattern); i++)
|
||||||
if (!strcmp(ident, builtin_funcname_pattern[i].name))
|
if (!strcmp(ident, builtin_funcname_pattern[i].name))
|
||||||
return builtin_funcname_pattern[i].pattern;
|
return &builtin_funcname_pattern[i];
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1512,11 +1513,11 @@ static void builtin_diff(const char *name_a,
|
|||||||
xdemitconf_t xecfg;
|
xdemitconf_t xecfg;
|
||||||
xdemitcb_t ecb;
|
xdemitcb_t ecb;
|
||||||
struct emit_callback ecbdata;
|
struct emit_callback ecbdata;
|
||||||
const char *funcname_pattern;
|
const struct funcname_pattern_entry *pe;
|
||||||
|
|
||||||
funcname_pattern = diff_funcname_pattern(one);
|
pe = diff_funcname_pattern(one);
|
||||||
if (!funcname_pattern)
|
if (!pe)
|
||||||
funcname_pattern = diff_funcname_pattern(two);
|
pe = diff_funcname_pattern(two);
|
||||||
|
|
||||||
memset(&xecfg, 0, sizeof(xecfg));
|
memset(&xecfg, 0, sizeof(xecfg));
|
||||||
memset(&ecbdata, 0, sizeof(ecbdata));
|
memset(&ecbdata, 0, sizeof(ecbdata));
|
||||||
@ -1528,8 +1529,8 @@ static void builtin_diff(const char *name_a,
|
|||||||
xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
|
xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
|
||||||
xecfg.ctxlen = o->context;
|
xecfg.ctxlen = o->context;
|
||||||
xecfg.flags = XDL_EMIT_FUNCNAMES;
|
xecfg.flags = XDL_EMIT_FUNCNAMES;
|
||||||
if (funcname_pattern)
|
if (pe)
|
||||||
xdiff_set_find_func(&xecfg, funcname_pattern);
|
xdiff_set_find_func(&xecfg, pe->pattern);
|
||||||
if (!diffopts)
|
if (!diffopts)
|
||||||
;
|
;
|
||||||
else if (!prefixcmp(diffopts, "--unified="))
|
else if (!prefixcmp(diffopts, "--unified="))
|
||||||
|
Loading…
Reference in New Issue
Block a user