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

[PATCH v2 3/4] diff.*.xfuncname which uses "extended" regex's for hunk header selection

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
Sep 18, 2008, 22:44 UTC
Message-ID
<fjsVcwP3ERAtOSloTT6E_M76x0-uAuN_SFta0ReZcFZ1h58s6M4jTQ@cipher.nrlssc.navy.mil>
In-Reply-To
<7vskry1485.fsf@gitster.siamese.dyndns.org>

Currently, the hunk headers produced by 'diff -p' are customizable by setting the diff.*.funcname option in the config file. The 'funcname' option takes a basic regular expression. This functionality was designed using the GNU regex library which, by default, allows using backslashed versions of some extended regular expression operators, even in Basic Regular Expression mode. For example, the following characters, when backslashed, are interpreted according to the extended regular expression rules: ?, +, and |. As such, the builtin funcname patterns were created using some extended regular expression operators.

Other platforms which adhere more strictly to the POSIX spec do not interpret the backslashed extended RE operators in Basic Regular Expression mode. This causes the pattern matching for the builtin funcname patterns to fail on those platforms.

Introduce a new option 'xfuncname' which uses extended regular expressions, and advertise it _instead_ of funcname. Since most users are on GNU platforms, the majority of funcname patterns are created and tested there. Advertising only xfuncname should help to avoid the creation of non-portable patterns which work with GNU regex but not elsewhere.

Additionally, the extended regular expressions may be less ugly and complicated compared to the basic RE since many common special operators do not need to be backslashed.

For example, the GNU Basic RE:
    ^[ 	]*\\(\\(public\\|static\\).*\\)$
becomes the following Extended RE:
    ^[ 	]*((public|static).*)$
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
 Documentation/gitattributes.txt |    4 ++--
 diff.c                          |    5 +++++
 t/t4018-diff-funcname.sh        |    2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 6f3551d..9a75257 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -288,13 +288,13 @@ for paths.
 *.tex	diff=tex
 ------------------------
 
-Then, you would define "diff.tex.funcname" configuration to
+Then, you would define "diff.tex.xfuncname" configuration to
 specify a regular expression that matches a line that you would
 want to appear as the hunk header, like this:
 
 ------------------------
 [diff "tex"]
-	funcname = "^\\(\\\\\\(sub\\)*section{.*\\)$"
+	xfuncname = "^(\\\\(sub)*section\\{.*)$"
 ------------------------
 
 Note.  A single level of backslashes are eaten by the
diff --git a/diff.c b/diff.c
index 08cdd8f..9d8fd2b 100644
--- a/diff.c
+++ b/diff.c
@@ -196,6 +196,11 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
 					return config_error_nonbool(var);
 				return parse_funcname_pattern(var, ep, value,
 					0);
+			} else if (!strcmp(ep, ".xfuncname")) {
+				if (!value)
+					return config_error_nonbool(var);
+				return parse_funcname_pattern(var, ep, value,
+					REG_EXTENDED);
 			}
 		}
 	}
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 18bcd97..602d68f 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -58,7 +58,7 @@ test_expect_success 'last regexp must not be negated' '
 '
 
 test_expect_success 'alternation in pattern' '
-	git config diff.java.funcname "^[ 	]*\\(\\(public\\|static\\).*\\)$"
+	git config diff.java.xfuncname "^[ 	]*((public|static).*)$" &&
 	git diff --no-index Beer.java Beer-correct.java |
 	grep "^@@.*@@ public static void main("
 '
-- 
1.6.0.1.244.gdc19
Previous: Brandon CaseyNext: Brandon Casey
Message 5 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.