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

Re: [PATCH v2 4/4] diff.c: convert builtin funcname patterns to non-GNU extended regex syntax

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 20, 2008, 06:58 UTC
Message-ID
<7vy71n482x.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<7v7i97swv3.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 10 quoted lines
> Neither has [4/4] on it.  I'd like two patches so that:
>
>  * [PATCH 1/2] applies to bc/maint-diff-hunk-header-fix, so that the
>    languages in 1.6.0.2 are fixed for non GNU platforms;
>
>  * After applying [1/2] to bc/maint-diff-hunk-header-fix, I'll merge the
>    branch to bc/master-diff-hunk-header-fix and then...
>
>  * [PATCH 2/2] applies on top of it to convert new languages that are
>    supported only on 'master' to use xfuncname.

Here is [1/2] to be applied on top of 45d9414 (diff.*.xfuncname which uses "extended" regex's for hunk header selection, 2008-09-18).

Testing appreciated.
-- >8 --
Subject: [PATCH] diff: use extended regexp to find hunk headers

Using ERE elements such as "|" (alternation) by backquoting in BRE is a GNU extension and should not be done in portable programs.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff.c |   31 +++++++++++++++++--------------
 1 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/diff.c b/diff.c
index dabb4b4..175a044 100644
--- a/diff.c
+++ b/diff.c
@@ -1399,20 +1399,23 @@ static const struct funcname_pattern_entry *funcname_pattern(const char *ident)
 }
 
 static const struct funcname_pattern_entry builtin_funcname_pattern[] = {
-	{ "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\\).*\\)$",
-			0 },
-	{ "bibtex", "\\(@[a-zA-Z]\\{1,\\}[ \t]*{\\{0,1\\}[ \t]*[^ \t\"@',\\#}{~%]*\\).*$", 0 },
-	{ "tex", "^\\(\\\\\\(\\(sub\\)*section\\|chapter\\|part\\)\\*\\{0,1\\}{.*\\)$", 0 },
-	{ "ruby", "^\\s*\\(\\(class\\|module\\|def\\)\\s.*\\)$", 0 },
+	{ "java",
+	  "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
+	  "^[ \t]*(([ \t]*[A-Za-z_][A-Za-z_0-9]*){2,}[ \t]*\\([^;]*)$",
+	  REG_EXTENDED },
+	{ "pascal",
+	  "^((procedure|function|constructor|destructor|interface|"
+		"implementation|initialization|finalization)[ \t]*.*)$"
+	  "|"
+	  "^(.*=[ \t]*(class|record).*)$",
+	  REG_EXTENDED },
+	{ "bibtex", "(@[a-zA-Z]{1,}[ \t]*\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
+	  REG_EXTENDED },
+	{ "tex",
+	  "^(\\\\((sub)*section|chapter|part)\\*{0,1}\{.*)$",
+	  REG_EXTENDED },
+	{ "ruby", "^[ \t]*((class|module|def)[ \t].*)$",
+	  REG_EXTENDED },
 };
 
 static const struct funcname_pattern_entry *diff_funcname_pattern(struct diff_filespec *one)
Previous: Junio C HamanoNext: Brandon Casey
Message 12 of 26 in “diff.c: return pattern entry pointer rather than just the hunk header pattern”
  1. 1/4 diff.c: return pattern entry pointer rather than just the hunk header patternBrandon Casey, Sep 18, 2008
  2. Boyd Lynn GerberSep 19, 2008
  3. Brandon CaseySep 19, 2008
  4. 2/4 diff.c: associate a flag with each pattern and use it for compiling regexBrandon Casey, Sep 18, 2008
  5. 3/4 diff.*.xfuncname which uses "extended" regex's for hunk header selectionBrandon Casey, Sep 18, 2008
  6. 4/4 diff.c: convert builtin funcname patterns to non-GNU extended regex syntaxBrandon Casey, Sep 18, 2008
  7. Brandon CaseySep 18, 2008
  8. Brandon CaseySep 19, 2008
  9. Johan HerlandSep 18, 2008
  10. Brandon CaseySep 19, 2008
  11. Junio C HamanoSep 19, 2008
  12. Junio C HamanoSep 20, 2008
  13. Brandon CaseySep 20, 2008
  14. Junio C HamanoSep 20, 2008
  15. Brandon CaseySep 22, 2008
  16. Brandon CaseySep 24, 2008
  17. Brandon CaseySep 26, 2008
  18. diff.c: remove duplicate bibtex pattern introduced by merge 92bb9785Brandon Casey, Sep 29, 2008
  19. t4018-diff-funcname: test syntax of builtin xfuncname patternsBrandon Casey, Sep 22, 2008
  20. t4018-diff-funcname: test syntax of builtin xfuncname patternsBrandon Casey, Sep 22, 2008
  21. diff funcname_pattern: Allow HTML header tags without attributesJohan Herland, Sep 23, 2008
  22. Junio C HamanoSep 23, 2008
  23. Johan HerlandSep 23, 2008
  24. Junio C HamanoSep 20, 2008
  25. Junio C HamanoSep 20, 2008
  26. Gustaf HendebySep 22, 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.