git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/4] diff.c: associate a flag with each pattern and use it for compiling regex

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
Sep 18, 2008, 00:10 UTC
Message-ID
<GZAEBf1BcP9-dznrIesxaE4Rb8bim6DpwDWCb9yWl99UVoQC9Dog0A@cipher.nrlssc.navy.mil>
In-Reply-To
<7v3ak06jzj.fsf@gitster.siamese.dyndns.org>
This is in preparation for allowing extended regular expression patterns.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
 diff.c            |   28 ++++++++++++++++------------
 xdiff-interface.c |    4 ++--
 xdiff-interface.h |    2 +-
 3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/diff.c b/diff.c
index e040088..4363d0d 100644
--- a/diff.c
+++ b/diff.c
@@ -100,10 +100,11 @@ static int parse_lldiff_command(const char *var, const char *ep, const char *val
 static struct funcname_pattern {
 	char *name;
 	char *pattern;
+	int cflags;
 	struct funcname_pattern *next;
 } *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;
 	int namelen;
@@ -123,6 +124,7 @@ static int parse_funcname_pattern(const char *var, const char *ep, const char *v
 	}
 	free(pp->pattern);
 	pp->pattern = xstrdup(value);
+	pp->cflags = cflags;
 	return 0;
 }
 
@@ -191,7 +193,8 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
 			if (!strcmp(ep, ".funcname")) {
 				if (!value)
 					return config_error_nonbool(var);
-				return parse_funcname_pattern(var, ep, value);
+				return parse_funcname_pattern(var, ep, value,
+					0);
 			}
 		}
 	}
@@ -1391,24 +1394,25 @@ int diff_filespec_is_binary(struct diff_filespec *one)
 static struct funcname_pattern_entry {
 	const char *name;
 	const char *pattern;
+	const int cflags;
 } builtin_funcname_pattern[] = {
-	{ "bibtex", "\\(@[a-zA-Z]\\{1,\\}[ \t]*{\\{0,1\\}[ \t]*[^ \t\"@',\\#}{~%]*\\).*$" },
-	{ "html", "^\\s*\\(<[Hh][1-6]\\s.*>.*\\)$" },
+	{ "bibtex", "\\(@[a-zA-Z]\\{1,\\}[ \t]*{\\{0,1\\}[ \t]*[^ \t\"@',\\#}{~%]*\\).*$", 0 },
+	{ "html", "^\\s*\\(<[Hh][1-6]\\s.*>.*\\)$", 0 },
 	{ "java", "!^[ 	]*\\(catch\\|do\\|for\\|if\\|instanceof\\|"
 			"new\\|return\\|switch\\|throw\\|while\\)\n"
 			"^[ 	]*\\(\\([ 	]*"
 			"[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}"
-			"[ 	]*([^;]*\\)$" },
+			"[ 	]*([^;]*\\)$", 0 },
 	{ "pascal", "^\\(\\(procedure\\|function\\|constructor\\|"
 			"destructor\\|interface\\|implementation\\|"
 			"initialization\\|finalization\\)[ \t]*.*\\)$"
 			"\\|"
-			"^\\(.*=[ \t]*\\(class\\|record\\).*\\)$"
-			},
-	{ "php", "^[\t ]*\\(\\(function\\|class\\).*\\)" },
-	{ "python", "^\\s*\\(\\(class\\|def\\)\\s.*\\)$" },
-	{ "ruby", "^\\s*\\(\\(class\\|module\\|def\\)\\s.*\\)$" },
-	{ "tex", "^\\(\\\\\\(\\(sub\\)*section\\|chapter\\|part\\)\\*\\{0,1\\}{.*\\)$" },
+			"^\\(.*=[ \t]*\\(class\\|record\\).*\\)$",
+			0 },
+	{ "php", "^[\t ]*\\(\\(function\\|class\\).*\\)", 0 },
+	{ "python", "^\\s*\\(\\(class\\|def\\)\\s.*\\)$", 0 },
+	{ "ruby", "^\\s*\\(\\(class\\|module\\|def\\)\\s.*\\)$", 0 },
+	{ "tex", "^\\(\\\\\\(\\(sub\\)*section\\|chapter\\|part\\)\\*\\{0,1\\}{.*\\)$", 0 },
 };
 
 static const struct funcname_pattern_entry *funcname_pattern(const char *ident)
@@ -1544,7 +1548,7 @@ static void builtin_diff(const char *name_a,
 		xecfg.ctxlen = o->context;
 		xecfg.flags = XDL_EMIT_FUNCNAMES;
 		if (pe)
-			xdiff_set_find_func(&xecfg, pe->pattern);
+			xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
 		if (!diffopts)
 			;
 		else if (!prefixcmp(diffopts, "--unified="))
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 944ad98..7f1a7d3 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -218,7 +218,7 @@ static long ff_regexp(const char *line, long len,
 	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;
 	struct ff_regs *regs;
@@ -243,7 +243,7 @@ void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value)
 			expression = buffer = xstrndup(value, ep - value);
 		else
 			expression = value;
-		if (regcomp(&reg->re, expression, 0))
+		if (regcomp(&reg->re, expression, cflags))
 			die("Invalid regexp to look for hunk header: %s", expression);
 		free(buffer);
 		value = ep + 1;
diff --git a/xdiff-interface.h b/xdiff-interface.h
index 558492b..23c49b9 100644
--- a/xdiff-interface.h
+++ b/xdiff-interface.h
@@ -16,6 +16,6 @@ int parse_hunk_header(char *line, int len,
 int read_mmfile(mmfile_t *ptr, const char *filename);
 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
-- 
1.6.0.1.244.gdc19
Previous: Brandon CaseyNext: Junio C Hamano
Message 15 of 44 in “Use compatibility regex library for OSX/Darwin”
  1. Use compatibility regex library for OSX/DarwinArjen Laarhoven, Sep 7, 2008
  2. Mike RalphsonSep 10, 2008
  3. Johannes SixtSep 10, 2008
  4. Arjen LaarhovenSep 10, 2008
  5. Mike RalphsonSep 10, 2008
  6. Mike RalphsonSep 11, 2008
  7. Use compatibility regex library also on AIXJohannes Sixt, Sep 11, 2008
  8. Arjen LaarhovenSep 11, 2008
  9. Mike RalphsonSep 11, 2008
  10. Jeff KingSep 11, 2008
  11. Junio C HamanoSep 11, 2008
  12. Brandon CaseySep 16, 2008
  13. Junio C HamanoSep 16, 2008
  14. 1/4 diff.c: return pattern entry pointer rather than just the hunk header patternBrandon Casey, Sep 18, 2008
  15. 2/4 diff.c: associate a flag with each pattern and use it for compiling regexBrandon Casey, Sep 18, 2008
  16. Junio C HamanoSep 18, 2008
  17. Andreas EricssonSep 18, 2008
  18. Junio C HamanoSep 18, 2008
  19. Andreas EricssonSep 18, 2008
  20. Junio C HamanoSep 18, 2008
  21. 3/4 diff.*.xfuncname which uses "extended" regex's for hunk header selectionBrandon Casey, Sep 18, 2008
  22. 4/4 diff.c: convert builtin funcname patterns to extended regular expressionsBrandon Casey, Sep 18, 2008
  23. 4/4 diff.c: convert builtin funcname patterns to extended regular expressionsBrandon Casey, Sep 18, 2008
  24. Andreas EricssonSep 18, 2008
  25. Junio C HamanoSep 18, 2008
  26. Johan HerlandSep 18, 2008
  27. Gustaf HendebySep 18, 2008
  28. Jonathan del StrotherSep 18, 2008
  29. Brandon CaseySep 18, 2008
  30. Jeff KingSep 16, 2008
  31. Boyd Lynn GerberSep 16, 2008
  32. Jeff KingSep 16, 2008
  33. Boyd Lynn GerberSep 16, 2008
  34. Jeff KingSep 16, 2008
  35. Boyd Lynn GerberSep 17, 2008
  36. Brandon CaseySep 17, 2008
  37. Boyd Lynn GerberSep 17, 2008
  38. Brandon CaseySep 17, 2008
  39. Boyd Lynn GerberSep 17, 2008
  40. Brandon CaseySep 17, 2008
  41. Boyd Lynn GerberSep 17, 2008
  42. Brandon CaseySep 17, 2008
  43. Boyd Lynn GerberSep 17, 2008
  44. Brandon CaseySep 19, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.