@matheusbsbs / matheus-bagliano / commits / a013585b20
Fork 0

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>

Brandon Casey committed Sep 18, 2008 at 17:42 UTC a013585b20ac757b0e75a72181ffa44674f35235
3 files changed +15 -12
diff.c
+12 -9
@@ -97,13 +97,14 @@ static int parse_lldiff_command(const char *var, const char *ep, const char *val
97 struct funcname_pattern_entry {
98 char *name;
99 char *pattern;
100 + int cflags;
101 };
102 static struct funcname_pattern_list {
103 struct funcname_pattern_list *next;
104 struct funcname_pattern_entry e;
105 } *funcname_pattern_list;
106
106 -static int parse_funcname_pattern(const char *var, const char *ep, const char *value)
107 +static int parse_funcname_pattern(const char *var, const char *ep, const char *value, int cflags)
108 {
109 const char *name;
110 int namelen;
@@ -123,6 +124,7 @@ static int parse_funcname_pattern(const char *var, const char *ep, const char *v
124 }
125 free(pp->e.pattern);
126 pp->e.pattern = xstrdup(value);
127 + pp->e.cflags = cflags;
128 return 0;
129 }
130
@@ -185,7 +187,8 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
187 if (!strcmp(ep, ".funcname")) {
188 if (!value)
189 return config_error_nonbool(var);
188 - return parse_funcname_pattern(var, ep, value);
190 + return parse_funcname_pattern(var, ep, value,
191 + 0);
192 }
193 }
194 }
@@ -1395,16 +1398,16 @@ static const struct funcname_pattern_entry builtin_funcname_pattern[] = {
1398 "new\\|return\\|switch\\|throw\\|while\\)\n"
1399 "^[ ]*\\(\\([ ]*"
1400 "[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}"
1398 - "[ ]*([^;]*\\)$" },
1401 + "[ ]*([^;]*\\)$", 0 },
1402 { "pascal", "^\\(\\(procedure\\|function\\|constructor\\|"
1403 "destructor\\|interface\\|implementation\\|"
1404 "initialization\\|finalization\\)[ \t]*.*\\)$"
1405 "\\|"
1403 - "^\\(.*=[ \t]*\\(class\\|record\\).*\\)$"
1404 - },
1405 - { "bibtex", "\\(@[a-zA-Z]\\{1,\\}[ \t]*{\\{0,1\\}[ \t]*[^ \t\"@',\\#}{~%]*\\).*$" },
1406 - { "tex", "^\\(\\\\\\(\\(sub\\)*section\\|chapter\\|part\\)\\*\\{0,1\\}{.*\\)$" },
1407 - { "ruby", "^\\s*\\(\\(class\\|module\\|def\\)\\s.*\\)$" },
1406 + "^\\(.*=[ \t]*\\(class\\|record\\).*\\)$",
1407 + 0 },
1408 + { "bibtex", "\\(@[a-zA-Z]\\{1,\\}[ \t]*{\\{0,1\\}[ \t]*[^ \t\"@',\\#}{~%]*\\).*$", 0 },
1409 + { "tex", "^\\(\\\\\\(\\(sub\\)*section\\|chapter\\|part\\)\\*\\{0,1\\}{.*\\)$", 0 },
1410 + { "ruby", "^\\s*\\(\\(class\\|module\\|def\\)\\s.*\\)$", 0 },
1411 };
1412
1413 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,
1533 xecfg.ctxlen = o->context;
1534 xecfg.flags = XDL_EMIT_FUNCNAMES;
1535 if (pe)
1533 - xdiff_set_find_func(&xecfg, pe->pattern);
1536 + xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
1537 if (!diffopts)
1538 ;
1539 else if (!prefixcmp(diffopts, "--unified="))
xdiff-interface.c
+2 -2
@@ -206,7 +206,7 @@ static long ff_regexp(const char *line, long len,
206 return result;
207 }
208
209 -void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value)
209 +void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value, int cflags)
210 {
211 int i;
212 struct ff_regs *regs;
@@ -231,7 +231,7 @@ void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value)
231 expression = buffer = xstrndup(value, ep - value);
232 else
233 expression = value;
234 - if (regcomp(&reg->re, expression, 0))
234 + if (regcomp(&reg->re, expression, cflags))
235 die("Invalid regexp to look for hunk header: %s", expression);
236 free(buffer);
237 value = ep + 1;
xdiff-interface.h
+1 -1
@@ -21,6 +21,6 @@ int parse_hunk_header(char *line, int len,
21 int read_mmfile(mmfile_t *ptr, const char *filename);
22 int buffer_is_binary(const char *ptr, unsigned long size);
23
24 -extern void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line);
24 +extern void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags);
25
26 #endif