From 71a5d4bc0e4025b3fbdeed76052b39fcef284e8c Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sun, 26 Dec 2010 03:07:31 -0600 Subject: [PATCH 1/2] diff: funcname and word patterns for perl The default function name discovery already works quite well for Perl code... with the exception of here-documents (or rather their ending). sub foo { print < Signed-off-by: Junio C Hamano --- Documentation/gitattributes.txt | 2 ++ t/t4018-diff-funcname.sh | 2 +- userdiff.c | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt index 5a7f936429..e59b878293 100644 --- a/Documentation/gitattributes.txt +++ b/Documentation/gitattributes.txt @@ -494,6 +494,8 @@ patterns are available: - `pascal` suitable for source code in the Pascal/Delphi language. +- `perl` suitable for source code in the Perl language. + - `php` suitable for source code in the PHP language. - `python` suitable for source code in the Python language. diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index 0a61b57b5f..3646930623 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -32,7 +32,7 @@ EOF sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java -builtin_patterns="bibtex cpp csharp fortran html java objc pascal php python ruby tex" +builtin_patterns="bibtex cpp csharp fortran html java objc pascal perl php python ruby tex" for p in $builtin_patterns do test_expect_success "builtin $p pattern compiles" ' diff --git a/userdiff.c b/userdiff.c index 2d5453697a..fc2afe33a7 100644 --- a/userdiff.c +++ b/userdiff.c @@ -61,6 +61,21 @@ PATTERNS("pascal", "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+" "|<>|<=|>=|:=|\\.\\." "|[^[:space:]]|[\x80-\xff]+"), +PATTERNS("perl", + "^[ \t]*package .*;\n" + "^[ \t]*sub .* \\{", + /* -- */ + "[[:alpha:]_'][[:alnum:]_']*" + "|0[xb]?[0-9a-fA-F_]*" + /* taking care not to interpret 3..5 as (3.)(.5) */ + "|[0-9a-fA-F_]+(\\.[0-9a-fA-F_]+)?([eE][-+]?[0-9_]+)?" + "|=>|-[rwxoRWXOezsfdlpSugkbctTBMAC>]|~~|::" + "|&&=|\\|\\|=|//=|\\*\\*=" + "|&&|\\|\\||//|\\+\\+|--|\\*\\*|\\.\\.\\.?" + "|[-+*/%.^&<>=!|]=" + "|=~|!~" + "|<<|<>|<=>|>>" + "|[^[:space:]]"), PATTERNS("php", "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n" "^[\t ]*(class.*)$", From a25e47377d6a1ec1efc6972f2e5e55cf429603a1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 27 Dec 2010 09:19:38 -0800 Subject: [PATCH 2/2] userdiff/perl: catch BEGIN/END/... and POD as headers Signed-off-by: Junio C Hamano --- userdiff.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/userdiff.c b/userdiff.c index fc2afe33a7..c384b39e4d 100644 --- a/userdiff.c +++ b/userdiff.c @@ -63,7 +63,9 @@ PATTERNS("pascal", "|[^[:space:]]|[\x80-\xff]+"), PATTERNS("perl", "^[ \t]*package .*;\n" - "^[ \t]*sub .* \\{", + "^[ \t]*sub .* \\{\n" + "^[A-Z]+ \\{\n" /* BEGIN, END, ... */ + "^=head[0-9] ", /* POD */ /* -- */ "[[:alpha:]_'][[:alnum:]_']*" "|0[xb]?[0-9a-fA-F_]*"