diff mbox series

[v2] Improve diff pattern for PHP files

Message ID pull.864.v2.git.git.1602041898670.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit aff92827b54f4b7f9e339982a49bab4bdbd1fc55
Headers show
Series [v2] Improve diff pattern for PHP files | expand

Commit Message

Jean-Noël Avila via GitGitGadget Oct. 7, 2020, 3:38 a.m. UTC
From: Javier Spagnoletti <phansys@gmail.com>

PHP allows some function modifiers that are not recognized in our current hunk header pattern

       final public function foo() { }
       abstract protected function bar() { }

Add "final" and "abstract" to the list of function modifiers.

Signed-off-by: Javier Spagnoletti <phansys@gmail.com>
---
    Improve diff pattern for PHP files
    
    PHP allows some function modifiers that are not recognized in our
    current hunk header pattern
    
       final public function foo() { }
       abstract protected function bar() { }
    
    Add "final" and "abstract" to the list of function modifiers. See:
    
     * https://www.php.net/manual/en/language.oop5.abstract.php#example-213;
     * https://www.php.net/manual/en/language.oop5.final.php#language.oop5.traits.static.ex1
       .
    
    Signed-off-by: Javier Spagnoletti phansys@gmail.com [phansys@gmail.com]

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-864%2Fphansys%2Fuserdiff_php-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-864/phansys/userdiff_php-v2
Pull-Request: https://github.com/git/git/pull/864

Range-diff vs v1:

 1:  aa65d43a40 ! 1:  4cb59950ff Improve diff pattern for PHP files
     @@ Metadata
       ## Commit message ##
          Improve diff pattern for PHP files
      
     -    Improve the output diff readability for php files by taking into account some missing function modifiers.
     +    PHP allows some function modifiers that are not recognized in our current hunk header pattern
     +
     +           final public function foo() { }
     +           abstract protected function bar() { }
     +
     +    Add "final" and "abstract" to the list of function modifiers.
      
          Signed-off-by: Javier Spagnoletti <phansys@gmail.com>
      
     + ## t/t4018/php-abstract-method (new) ##
     +@@
     ++abstract class Klass
     ++{
     ++    abstract public function RIGHT(): ?string
     ++    {
     ++        return 'ChangeMe';
     ++    }
     ++}
     +
     + ## t/t4018/php-final-method (new) ##
     +@@
     ++class Klass
     ++{
     ++    final public function RIGHT(): string
     ++    {
     ++        return 'ChangeMe';
     ++    }
     ++}
     +
       ## userdiff.c ##
      @@ userdiff.c: PATTERNS("perl",
       	 "|=~|!~"


 t/t4018/php-abstract-method | 7 +++++++
 t/t4018/php-final-method    | 7 +++++++
 userdiff.c                  | 2 +-
 3 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 t/t4018/php-abstract-method
 create mode 100644 t/t4018/php-final-method


base-commit: 47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc

Comments

Junio C Hamano Oct. 7, 2020, 6:12 a.m. UTC | #1
"Javier Spagnoletti via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> Subject: Re: [PATCH v2] Improve diff pattern for PHP files

You seem to have read J6t's excellent suggestion well but forgot to
retitle.

> From: Javier Spagnoletti <phansys@gmail.com>
>
> PHP allows some function modifiers that are not recognized in our current hunk header pattern
>
>        final public function foo() { }
>        abstract protected function bar() { }
>
> Add "final" and "abstract" to the list of function modifiers.
>
> Signed-off-by: Javier Spagnoletti <phansys@gmail.com>
> ...
>  t/t4018/php-abstract-method | 7 +++++++
>  t/t4018/php-final-method    | 7 +++++++
>  userdiff.c                  | 2 +-
>  3 files changed, 15 insertions(+), 1 deletion(-)
>  create mode 100644 t/t4018/php-abstract-method
>  create mode 100644 t/t4018/php-final-method
>
> diff --git a/t/t4018/php-abstract-method b/t/t4018/php-abstract-method
> new file mode 100644
> index 0000000000..ce215df75a
> --- /dev/null
> +++ b/t/t4018/php-abstract-method
> @@ -0,0 +1,7 @@
> +abstract class Klass
> +{
> +    abstract public function RIGHT(): ?string
> +    {
> +        return 'ChangeMe';
> +    }
> +}
> diff --git a/t/t4018/php-final-method b/t/t4018/php-final-method
> new file mode 100644
> index 0000000000..537fb8ad9a
> --- /dev/null
> +++ b/t/t4018/php-final-method
> @@ -0,0 +1,7 @@
> +class Klass
> +{
> +    final public function RIGHT(): string
> +    {
> +        return 'ChangeMe';
> +    }
> +}
> diff --git a/userdiff.c b/userdiff.c
> index 1df884ef0b..a99d84a7e3 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -143,7 +143,7 @@ PATTERNS("perl",
>  	 "|=~|!~"
>  	 "|<<|<>|<=>|>>"),
>  PATTERNS("php",
> -	 "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
> +	 "^[\t ]*(((public|protected|private|static|abstract|final)[\t ]+)*function.*)$\n"
>  	 "^[\t ]*((((final|abstract)[\t ]+)?class|interface|trait).*)$",
>  	 /* -- */
>  	 "[a-zA-Z_][a-zA-Z0-9_]*"
>
> base-commit: 47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc
Junio C Hamano Oct. 7, 2020, 6:47 p.m. UTC | #2
Junio C Hamano <gitster@pobox.com> writes:

> "Javier Spagnoletti via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
>> Subject: Re: [PATCH v2] Improve diff pattern for PHP files
>
> You seem to have read J6t's excellent suggestion well but forgot to
> retitle.

Will queue with minimum copy-editing (reproduced below).

Thanks.

commit aff92827b54f4b7f9e339982a49bab4bdbd1fc55
Author: Javier Spagnoletti <phansys@gmail.com>
Date:   Wed Oct 7 03:38:18 2020 +0000

    userdiff: PHP: catch "abstract" and "final" functions
    
    PHP permits functions to be defined like
    
           final public function foo() { }
           abstract protected function bar() { }
    
    but our hunk header pattern does not recognize these decorations.
    Add "final" and "abstract" to the list of function modifiers.
    
    Helped-by: Johannes Sixt <j6t@kdbg.org>
    Signed-off-by: Javier Spagnoletti <phansys@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>

diff --git a/t/t4018/php-abstract-method b/t/t4018/php-abstract-method
new file mode 100644
index 0000000000..ce215df75a
--- /dev/null
+++ b/t/t4018/php-abstract-method
@@ -0,0 +1,7 @@
+abstract class Klass
+{
+    abstract public function RIGHT(): ?string
+    {
+        return 'ChangeMe';
+    }
+}
diff --git a/t/t4018/php-final-method b/t/t4018/php-final-method
new file mode 100644
index 0000000000..537fb8ad9a
--- /dev/null
+++ b/t/t4018/php-final-method
@@ -0,0 +1,7 @@
+class Klass
+{
+    final public function RIGHT(): string
+    {
+        return 'ChangeMe';
+    }
+}
diff --git a/userdiff.c b/userdiff.c
index fde02f225b..4e2b55a5e0 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -147,7 +147,7 @@ PATTERNS("perl",
 	 "|=~|!~"
 	 "|<<|<>|<=>|>>"),
 PATTERNS("php",
-	 "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
+	 "^[\t ]*(((public|protected|private|static|abstract|final)[\t ]+)*function.*)$\n"
 	 "^[\t ]*((((final|abstract)[\t ]+)?class|interface|trait).*)$",
 	 /* -- */
 	 "[a-zA-Z_][a-zA-Z0-9_]*"
diff mbox series

Patch

diff --git a/t/t4018/php-abstract-method b/t/t4018/php-abstract-method
new file mode 100644
index 0000000000..ce215df75a
--- /dev/null
+++ b/t/t4018/php-abstract-method
@@ -0,0 +1,7 @@ 
+abstract class Klass
+{
+    abstract public function RIGHT(): ?string
+    {
+        return 'ChangeMe';
+    }
+}
diff --git a/t/t4018/php-final-method b/t/t4018/php-final-method
new file mode 100644
index 0000000000..537fb8ad9a
--- /dev/null
+++ b/t/t4018/php-final-method
@@ -0,0 +1,7 @@ 
+class Klass
+{
+    final public function RIGHT(): string
+    {
+        return 'ChangeMe';
+    }
+}
diff --git a/userdiff.c b/userdiff.c
index 1df884ef0b..a99d84a7e3 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -143,7 +143,7 @@  PATTERNS("perl",
 	 "|=~|!~"
 	 "|<<|<>|<=>|>>"),
 PATTERNS("php",
-	 "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
+	 "^[\t ]*(((public|protected|private|static|abstract|final)[\t ]+)*function.*)$\n"
 	 "^[\t ]*((((final|abstract)[\t ]+)?class|interface|trait).*)$",
 	 /* -- */
 	 "[a-zA-Z_][a-zA-Z0-9_]*"