git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 7, 2020, 18:47 UTC
Message-ID
<xmqqpn5t27rj.fsf@gitster.c.googlers.com>
In-Reply-To
<xmqqeema4la5.fsf@gitster.c.googlers.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 7 quoted lines
> "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_]*"
Previous: Junio C HamanoNext: Javier Spagnoletti via GitGitGadget
Message 6 of 7 in “Improve diff pattern for PHP files”
  1. Improve diff pattern for PHP filesJavier Spagnoletti via GitGitGadget, Oct 6, 2020
  2. Johannes SixtOct 6, 2020
  3. Junio C HamanoOct 6, 2020
  4. Improve diff pattern for PHP filesJavier Spagnoletti via GitGitGadget, Oct 7, 2020
  5. Junio C HamanoOct 7, 2020
  6. Junio C HamanoOct 7, 2020
  7. userdiff: php: Add "final" and "abstract" to the list of function modifiersJavier Spagnoletti via GitGitGadget, Oct 7, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.