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

[PATCH 1/4] diff.c: return pattern entry pointer rather than just the hunk header pattern

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
Sep 18, 2008, 00:08 UTC
Message-ID
<bM_-9C7AsEGzvM1pnb0gAo_24GfK0SpJFM36WzkP4Ho@cipher.nrlssc.navy.mil>
In-Reply-To
<7v3ak06jzj.fsf@gitster.siamese.dyndns.org>

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>
---
Sorry for the dup, I forgot to add the list.
Junio C Hamano wrote:
Show 9 quoted lines
> Brandon Casey <casey@nrlssc.navy.mil> writes:
> 
>> It's too late to change diff.*.funcname now, but an alternative fix
>> which would probably not require every other platform to use GNU regex,
>> is to introduce a new funcname option which would allow extended regular
>> expression syntax and to convert the internal regular expressions to
>> that format.
> 
> That's a very sensible approach, I would agree.
 diff.c |   53 ++++++++++++++++++++++++++++++-----------------------
 1 files changed, 30 insertions(+), 23 deletions(-)
diff --git a/diff.c b/diff.c
index 998dcaa..e040088 100644
--- a/diff.c
+++ b/diff.c
@@ -94,6 +94,8 @@ static int parse_lldiff_command(const char *var, const char *ep, const char *val
  * 'diff.<what>.funcname' attribute can be specified in the configuration
  * to define a customized regexp to find the beginning of a function to
  * be used for hunk header lines of "diff -p" style output.
+ * Note: If this structure is modified, it must retain the ability to be cast
+ * to a struct funcname_pattern_entry, defined elsewhere.
  */
 static struct funcname_pattern {
 	char *name;
@@ -1382,17 +1384,11 @@ int diff_filespec_is_binary(struct diff_filespec *one)
 	return one->is_binary;
 }
 
-static const char *funcname_pattern(const char *ident)
-{
-	struct funcname_pattern *pp;
-
-	for (pp = funcname_pattern_list; pp; pp = pp->next)
-		if (!strcmp(ident, pp->name))
-			return pp->pattern;
-	return NULL;
-}
-
-static struct builtin_funcname_pattern {
+/*
+ * Note: The elements of this structure must be arranged so that they are
+ *       compatible with the elements of the funcname_pattern structure.
+ */
+static struct funcname_pattern_entry {
 	const char *name;
 	const char *pattern;
 } builtin_funcname_pattern[] = {
@@ -1415,9 +1411,20 @@ static struct builtin_funcname_pattern {
 	{ "tex", "^\\(\\\\\\(\\(sub\\)*section\\|chapter\\|part\\)\\*\\{0,1\\}{.*\\)$" },
 };
 
-static const char *diff_funcname_pattern(struct diff_filespec *one)
+static const struct funcname_pattern_entry *funcname_pattern(const char *ident)
+{
+	struct funcname_pattern *pp;
+
+	for (pp = funcname_pattern_list; pp; pp = pp->next)
+		if (!strcmp(ident, pp->name))
+			return (struct funcname_pattern_entry*) pp;
+	return NULL;
+}
+
+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;
 
 	diff_filespec_check_attr(one);
@@ -1432,9 +1439,9 @@ static const char *diff_funcname_pattern(struct diff_filespec *one)
 		return funcname_pattern("default");
 
 	/* Look up custom "funcname.$ident" regexp from config. */
-	pattern = funcname_pattern(ident);
-	if (pattern)
-		return pattern;
+	pe = funcname_pattern(ident);
+	if (pe)
+		return pe;
 
 	/*
 	 * And define built-in fallback patterns here.  Note that
@@ -1442,7 +1449,7 @@ static const char *diff_funcname_pattern(struct diff_filespec *one)
 	 */
 	for (i = 0; i < ARRAY_SIZE(builtin_funcname_pattern); i++)
 		if (!strcmp(ident, builtin_funcname_pattern[i].name))
-			return builtin_funcname_pattern[i].pattern;
+			return &builtin_funcname_pattern[i];
 
 	return NULL;
 }
@@ -1520,11 +1527,11 @@ static void builtin_diff(const char *name_a,
 		xdemitconf_t xecfg;
 		xdemitcb_t ecb;
 		struct emit_callback ecbdata;
-		const char *funcname_pattern;
+		const struct funcname_pattern_entry *pe;
 
-		funcname_pattern = diff_funcname_pattern(one);
-		if (!funcname_pattern)
-			funcname_pattern = diff_funcname_pattern(two);
+		pe = diff_funcname_pattern(one);
+		if (!pe)
+			pe = diff_funcname_pattern(two);
 
 		memset(&xecfg, 0, sizeof(xecfg));
 		memset(&ecbdata, 0, sizeof(ecbdata));
@@ -1536,8 +1543,8 @@ static void builtin_diff(const char *name_a,
 		xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
 		xecfg.ctxlen = o->context;
 		xecfg.flags = XDL_EMIT_FUNCNAMES;
-		if (funcname_pattern)
-			xdiff_set_find_func(&xecfg, funcname_pattern);
+		if (pe)
+			xdiff_set_find_func(&xecfg, pe->pattern);
 		if (!diffopts)
 			;
 		else if (!prefixcmp(diffopts, "--unified="))
-- 
1.6.0.1.244.gdc19
Previous: Junio C HamanoNext: Brandon Casey
Message 14 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.