diff options
-rwxr-xr-x | t/t4018-diff-funcname.sh | 36 | ||||
-rw-r--r-- | userdiff.c | 2 |
2 files changed, 37 insertions, 1 deletions
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index 38a092a0da..1e80b157d9 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -93,6 +93,29 @@ sed -e ' s/song;/song();/ ' <Beer.perl >Beer-correct.perl +cat >Beer.c <<\EOF +static int foo(void) +{ +label: + int x = old; +} + +struct foo; /* catch failure below */ +static int +gnu(int arg) +{ + int x = old; +} + +struct foo; /* catch failure below */ +int multiline(int arg, + char *arg2) +{ + int x = old; +} +EOF +sed s/old/new/ <Beer.c >Beer-correct.c + test_expect_funcname () { lang=${2-java} test_expect_code 1 git diff --no-index -U1 \ @@ -127,6 +150,7 @@ test_expect_success 'set up .gitattributes declaring drivers to test' ' cat >.gitattributes <<-\EOF *.java diff=java *.perl diff=perl + *.c diff=cpp EOF ' @@ -158,6 +182,18 @@ test_expect_success 'perl pattern is not distracted by forward declaration' ' test_expect_funcname "package Beer;\$" perl ' +test_expect_success 'c pattern skips labels' ' + test_expect_funcname "static int foo(void)" c +' + +test_expect_success 'c pattern matches GNU-style functions' ' + test_expect_funcname "gnu(int arg)\$" c +' + +test_expect_success 'c pattern matches multiline functions' ' + test_expect_funcname "int multiline(int arg,\$" c +' + test_expect_success 'custom pattern' ' test_config diff.java.funcname "!static !String diff --git a/userdiff.c b/userdiff.c index 10b61ec37d..b9d52b79bc 100644 --- a/userdiff.c +++ b/userdiff.c @@ -127,7 +127,7 @@ PATTERNS("cpp", /* Jump targets or access declarations */ "!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:.*$\n" /* C/++ functions/methods at top level */ - "^([A-Za-z_][A-Za-z_0-9]*([ \t*]+[A-Za-z_][A-Za-z_0-9]*([ \t]*::[ \t]*[^[:space:]]+)?){1,}[ \t]*\\([^;]*)$\n" + "^([A-Za-z_].*\\([^;]*)$\n" /* compound type at top level */ "^((struct|class|enum)[^;]*)$", /* -- */ |