@matheusbsbs / matheus-bagliano / commits / 077a1fda82
Fork 0

userdiff: support Python async functions

Python's async functions (declared with "async def" rather than "def") were not being displayed in hunk headers. This commit teaches git about the async function syntax, and adds tests for the Python userdiff regex. Signed-off-by: Josh Holland <anowlcalledjosh@gmail.com> Acked-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Josh Holland committed Nov 19, 2019 at 15:08 UTC 077a1fda82b237c16eb10bd988650468683a94b5
7 files changed +32 -1
t/t4018/python-async-def new
+4
@@ -0,0 +1,4 @@
1 +async def RIGHT(pi: int = 3.14):
2 + while True:
3 + break
4 + return ChangeMe()
t/t4018/python-class new
+4
@@ -0,0 +1,4 @@
1 +class RIGHT(int, str):
2 + # comment
3 + # another comment
4 + # ChangeMe
t/t4018/python-def new
+4
@@ -0,0 +1,4 @@
1 +def RIGHT(pi: int = 3.14):
2 + while True:
3 + break
4 + return ChangeMe()
t/t4018/python-indented-async-def new
+7
@@ -0,0 +1,7 @@
1 +class Foo:
2 + async def RIGHT(self, x: int):
3 + return [
4 + 1,
5 + 2,
6 + ChangeMe,
7 + ]
t/t4018/python-indented-class new
+5
@@ -0,0 +1,5 @@
1 +if TYPE_CHECKING:
2 + class RIGHT:
3 + # comment
4 + # another comment
5 + # ChangeMe
t/t4018/python-indented-def new
+7
@@ -0,0 +1,7 @@
1 +class Foo:
2 + def RIGHT(self, x: int):
3 + return [
4 + 1,
5 + 2,
6 + ChangeMe,
7 + ]
userdiff.c
+1 -1
@@ -124,7 +124,7 @@ PATTERNS("php",
124 "[a-zA-Z_][a-zA-Z0-9_]*"
125 "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
126 "|[-+*/<>%&^|=!.]=|--|\\+\\+|<<=?|>>=?|===|&&|\\|\\||::|->"),
127 -PATTERNS("python", "^[ \t]*((class|def)[ \t].*)$",
127 +PATTERNS("python", "^[ \t]*((class|(async[ \t]+)?def)[ \t].*)$",
128 /* -- */
129 "[a-zA-Z_][a-zA-Z0-9_]*"
130 "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"