summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-03-08 20:36:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-03-08 20:36:30 (GMT)
commit077cde91d226c305523645a0f30b6955d4aaf9c9 (patch)
tree5b6ae638094a55a11f75a760fa5cd82cf40bce88
parent9bb8eb0c88d210d3575bd484320f9abfef551ed1 (diff)
parent1dbf0c0ad6cabfc35aa1896b4d94f4ee811ba803 (diff)
downloadgit-077cde91d226c305523645a0f30b6955d4aaf9c9.zip
git-077cde91d226c305523645a0f30b6955d4aaf9c9.tar.gz
git-077cde91d226c305523645a0f30b6955d4aaf9c9.tar.bz2
Merge branch 'ag/userdiff-go-funcname'
"git diff" and friends learned funcname patterns for Go language source files. * ag/userdiff-go-funcname: userdiff: add built-in pattern for golang
-rw-r--r--Documentation/gitattributes.txt2
-rwxr-xr-xt/t4018-diff-funcname.sh1
-rw-r--r--t/t4018/golang-complex-function8
-rw-r--r--t/t4018/golang-func4
-rw-r--r--t/t4018/golang-interface4
-rw-r--r--t/t4018/golang-long-func5
-rw-r--r--t/t4018/golang-struct4
-rw-r--r--userdiff.c9
8 files changed, 37 insertions, 0 deletions
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index c21f5ca..d52b254 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -714,6 +714,8 @@ patterns are available:
- `fountain` suitable for Fountain documents.
+- `golang` suitable for source code in the Go language.
+
- `html` suitable for HTML/XHTML documents.
- `java` suitable for source code in the Java language.
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 1795ffc..22f9f88 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -33,6 +33,7 @@ diffpatterns="
css
fortran
fountain
+ golang
html
java
matlab
diff --git a/t/t4018/golang-complex-function b/t/t4018/golang-complex-function
new file mode 100644
index 0000000..e057dce
--- /dev/null
+++ b/t/t4018/golang-complex-function
@@ -0,0 +1,8 @@
+type Test struct {
+ a Type
+}
+
+func (t *Test) RIGHT(a Type) (Type, error) {
+ t.a = a
+ return ChangeMe, nil
+}
diff --git a/t/t4018/golang-func b/t/t4018/golang-func
new file mode 100644
index 0000000..8e9c9ac
--- /dev/null
+++ b/t/t4018/golang-func
@@ -0,0 +1,4 @@
+func RIGHT() {
+ a := 5
+ b := ChangeMe
+}
diff --git a/t/t4018/golang-interface b/t/t4018/golang-interface
new file mode 100644
index 0000000..553bede
--- /dev/null
+++ b/t/t4018/golang-interface
@@ -0,0 +1,4 @@
+type RIGHT interface {
+ a() Type
+ b() ChangeMe
+}
diff --git a/t/t4018/golang-long-func b/t/t4018/golang-long-func
new file mode 100644
index 0000000..ac3a77b
--- /dev/null
+++ b/t/t4018/golang-long-func
@@ -0,0 +1,5 @@
+func RIGHT(aVeryVeryVeryLongVariableName AVeryVeryVeryLongType,
+ anotherLongVariableName AnotherLongType) {
+ a := 5
+ b := ChangeMe
+}
diff --git a/t/t4018/golang-struct b/t/t4018/golang-struct
new file mode 100644
index 0000000..5deda77
--- /dev/null
+++ b/t/t4018/golang-struct
@@ -0,0 +1,4 @@
+type RIGHT struct {
+ a Type
+ b ChangeMe
+}
diff --git a/userdiff.c b/userdiff.c
index dbfb4e1..8f5028f 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -38,6 +38,15 @@ IPATTERN("fortran",
"|//|\\*\\*|::|[/<>=]="),
IPATTERN("fountain", "^((\\.[^.]|(int|ext|est|int\\.?/ext|i/e)[. ]).*)$",
"[^ \t-]+"),
+PATTERNS("golang",
+ /* Functions */
+ "^[ \t]*(func[ \t]*.*(\\{[ \t]*)?)\n"
+ /* Structs and interfaces */
+ "^[ \t]*(type[ \t].*(struct|interface)[ \t]*(\\{[ \t]*)?)",
+ /* -- */
+ "[a-zA-Z_][a-zA-Z0-9_]*"
+ "|[-+0-9.eE]+i?|0[xX]?[0-9a-fA-F]+i?"
+ "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&\\^=?|&&|\\|\\||<-|\\.{3}"),
PATTERNS("html", "^[ \t]*(<[Hh][1-6]([ \t].*)?>.*)$",
"[^<>= \t]+"),
PATTERNS("java",