@matheusbsbs / matheus-bagliano / commits / 45d9414fa5
Fork 0

diff.*.xfuncname which uses "extended" regex's for hunk header selection

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Sep 18, 2008 at 17:44 UTC 45d9414fa5599b41578625961b53e18a9b9148c7
3 files changed +8 -3
Documentation/gitattributes.txt
+2 -2
@@ -288,13 +288,13 @@ for paths.
288 *.tex diff=tex
289 ------------------------
290
291 -Then, you would define "diff.tex.funcname" configuration to
291 +Then, you would define "diff.tex.xfuncname" configuration to
292 specify a regular expression that matches a line that you would
293 want to appear as the hunk header, like this:
294
295 ------------------------
296 [diff "tex"]
297 - funcname = "^\\(\\\\\\(sub\\)*section{.*\\)$"
297 + xfuncname = "^(\\\\(sub)*section\\{.*)$"
298 ------------------------
299
300 Note. A single level of backslashes are eaten by the
diff.c
+5
@@ -189,6 +189,11 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
189 return config_error_nonbool(var);
190 return parse_funcname_pattern(var, ep, value,
191 0);
192 + } else if (!strcmp(ep, ".xfuncname")) {
193 + if (!value)
194 + return config_error_nonbool(var);
195 + return parse_funcname_pattern(var, ep, value,
196 + REG_EXTENDED);
197 }
198 }
199 }
t/t4018-diff-funcname.sh
+1 -1
@@ -58,7 +58,7 @@ test_expect_success 'last regexp must not be negated' '
58 '
59
60 test_expect_success 'alternation in pattern' '
61 - git config diff.java.funcname "^[ ]*\\(\\(public\\|static\\).*\\)$"
61 + git config diff.java.xfuncname "^[ ]*((public|static).*)$" &&
62 git diff --no-index Beer.java Beer-correct.java |
63 grep "^@@.*@@ public static void main("
64 '