]> git.ipfire.org Git - thirdparty/git.git/commitdiff
userdiff: improve Fortran xfuncname regex
authorPhilippe Blain <levraiphilippeblain@gmail.com>
Wed, 12 Aug 2020 22:30:29 +0000 (22:30 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 13 Aug 2020 18:21:18 +0000 (11:21 -0700)
The third part of the Fortran xfuncname regex wants to match the
beginning of a subroutine or function, so it allows for all characters
except `'`, `"` or whitespace before the keyword 'function' or
'subroutine'. This is meant to match the 'recursive', 'elemental' or
'pure' keywords, as well as function return types, and to prevent
matches inside strings.

However, the negated set does not contain the `!` comment character,
so a line with an end-of-line comment containing the keyword 'function' or
'subroutine' followed by another word is mistakenly chosen as a hunk header.

Improve the regex by adding `!` to the negated set.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4018/fortran-comment-keyword
userdiff.c

index c5dbdb4c617906965c2d0c5b1b7da6da07f5122a..e9206a53799dc36710c9fc8a3a0ae55b75f4c02c 100644 (file)
@@ -8,7 +8,6 @@
       real funcB  ! grid function b
 
       real ChangeMe
-      integer broken
 
       end subroutine RIGHT
 
index 707d82435ae285fd327af829dd24246bdbeb0a47..fde02f225b2b9ed17a8246913c3bddfa6483c98b 100644 (file)
@@ -53,7 +53,7 @@ IPATTERN("fortran",
         /* Program, module, block data */
         "^[ \t]*((END[ \t]+)?(PROGRAM|MODULE|BLOCK[ \t]+DATA"
                /* Subroutines and functions */
-               "|([^'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$",
+               "|([^!'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$",
         /* -- */
         "[a-zA-Z][a-zA-Z0-9_]*"
         "|\\.([Ee][Qq]|[Nn][Ee]|[Gg][TtEe]|[Ll][TtEe]|[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|[Aa][Nn][Dd]|[Oo][Rr]|[Nn]?[Ee][Qq][Vv]|[Nn][Oo][Tt])\\."