From: Tassilo Horn <tsdh@gnu•org>
To: git@vger•kernel.org
Cc: Tassilo Horn <tsdh@gnu•org>
Subject: [PATCH] userdiff: improve java regex for generic return types
Date: Mon, 9 Aug 2021 22:33:08 +0200 [thread overview]
Message-ID: <20210809203308.30128-1-tsdh@gnu.org> (raw)
Currently, the git diff hunk headers show the wrong method signature if the
method has a generic return type because the regex doesn't allow < and > in the
return type. This patch adds those.
Bug repro: In a repository with .gitattributes containing "*.java diff=java"
and a java file
--8<---------------cut here---------------start------------->8---
class MyExample {
public void firstMethod() {
// Whatever...
}
public List<Integer> secondMethod() {
// Here is some comment,
// and here is more,
// and here is even more,
// followed by this,
// and that,
// and even more.
return Arrays.asList(1, 2, 3, 4, 5);
}
}
--8<---------------cut here---------------end--------------->8---
when adding the number 6 to the Arrays.asList() call in secondMethod(), the git
diff one gets is
--8<---------------cut here---------------start------------->8---
diff --git a/src/main/java/MyExample.java b/src/main/java/MyExample.java
index a0f1a6b..ea37a98 100644
--- a/src/main/java/MyExample.java
+++ b/src/main/java/MyExample.java
@@ -14,6 +14,6 @@ public void firstMethod() {
// followed by this,
// and that,
// and even more.
- return Arrays.asList(1, 2, 3, 4, 5);
+ return Arrays.asList(1, 2, 3, 4, 5, 6);
}
}
--8<---------------cut here---------------end--------------->8---
where the hunk header shows the signature of firstMethod whereas it should show
the signature of secondMethod.
Signed-off-by: Tassilo Horn <tsdh@gnu•org>
---
userdiff.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/userdiff.c b/userdiff.c
index 3c3bbe38b0..a244ad7ab1 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -142,7 +142,7 @@ PATTERNS("html",
"[^<>= \t]+"),
PATTERNS("java",
"!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
- "^[ \t]*(([A-Za-z_][A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$",
+ "^[ \t]*(([A-Za-z_][A-Za-z_0-9<>]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$",
/* -- */
"[a-zA-Z_][a-zA-Z0-9_]*"
"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
--
2.32.0
next reply other threads:[~2021-08-09 20:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-09 20:33 Tassilo Horn [this message]
2021-08-09 21:00 ` [PATCH] userdiff: improve java regex for generic return types Jeff King
2021-08-10 4:51 ` Tassilo Horn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210809203308.30128-1-tsdh@gnu.org \
--to=tsdh@gnu$(echo .)org \
--cc=git@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox