]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff.*.xfuncname which uses "extended" regex's for hunk header selection
authorBrandon Casey <casey@nrlssc.navy.mil>
Thu, 18 Sep 2008 22:44:33 +0000 (17:44 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2008 03:06:31 +0000 (20:06 -0700)
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>
Documentation/gitattributes.txt
diff.c
t/t4018-diff-funcname.sh

index 94e6752aa2e78e4bcf69334ca92bc41439b33028..9259637609da2b34d15d217daeebeccc6ba853e4 100644 (file)
@@ -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 6881cf4efaf004e939aef8789bc43526f87d10d7..dabb4b4a021414adb89d5647afe14caaff670a76 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -189,6 +189,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);
                        }
                }
        }
index 18bcd9713d4e7a1446639dece4b8bc0173c57b22..602d68f092926ac612f4fe3bca17951fcde3cea9 100755 (executable)
@@ -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("
 '