summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Schildknecht <adrien+dev@schischi.me>2015-03-10 00:40:32 +0100
committerJunio C Hamano <gitster@pobox.com>2015-03-13 21:56:52 -0700
commitf7711b353572616e7d2fdff7a3cc5f757d314eb8 (patch)
treec0f40891db419cdc384748c18e226db09f0ebcda
parent1165ae6f3d42e0eb0ddfc2d4e6dfa8bd0b88eb60 (diff)
downloadgit-as/userdiff-sh.tar.gz
userdiff: funcname and word patterns for shas/userdiff-sh
Add regexp based on the "Shell Command Language" specifications. Because of the lax syntax of sh, some corner cases may not be handled properly. Signed-off-by: Adrien Schildknecht <adrien+dev@schischi.me> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--Documentation/gitattributes.txt2
-rwxr-xr-xt/t4018-diff-funcname.sh1
-rw-r--r--t/t4018/sh-function4
-rw-r--r--t/t4018/sh-function-comment6
-rw-r--r--t/t4018/sh-function-nested7
-rw-r--r--t/t4018/sh-function-prefix4
-rw-r--r--t/t4018/sh-function-string4
-rwxr-xr-xt/t4034-diff-words.sh1
-rw-r--r--t/t4034/sh/expect46
-rw-r--r--t/t4034/sh/post36
-rw-r--r--t/t4034/sh/pre36
-rw-r--r--userdiff.c7
12 files changed, 154 insertions, 0 deletions
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index c892ffa5ce..fb137614ee 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -545,6 +545,8 @@ patterns are available:
- `ruby` suitable for source code in the Ruby language.
+- `sh` suitable for source code in the Shell language.
+
- `tex` suitable for source code for LaTeX documents.
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 1dbaa3864a..960b6e4375 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -40,6 +40,7 @@ diffpatterns="
php
python
ruby
+ sh
tex
custom1
custom2
diff --git a/t/t4018/sh-function b/t/t4018/sh-function
new file mode 100644
index 0000000000..1d5096a0ac
--- /dev/null
+++ b/t/t4018/sh-function
@@ -0,0 +1,4 @@
+RIGHT_foo()
+{
+ ChangeMe;
+}
diff --git a/t/t4018/sh-function-comment b/t/t4018/sh-function-comment
new file mode 100644
index 0000000000..f340ee79e4
--- /dev/null
+++ b/t/t4018/sh-function-comment
@@ -0,0 +1,6 @@
+ RIGHT_foo() # echo 'foo'
+#bar()
+{
+ #bar()
+ ChangeMe;
+}
diff --git a/t/t4018/sh-function-nested b/t/t4018/sh-function-nested
new file mode 100644
index 0000000000..d3263f3ade
--- /dev/null
+++ b/t/t4018/sh-function-nested
@@ -0,0 +1,7 @@
+foo ( )
+{
+ RIGHT_bar()
+ {
+ echo ChangeMe
+ }
+}
diff --git a/t/t4018/sh-function-prefix b/t/t4018/sh-function-prefix
new file mode 100644
index 0000000000..e96eb7aa58
--- /dev/null
+++ b/t/t4018/sh-function-prefix
@@ -0,0 +1,4 @@
+function RIGHT_foo()
+{
+ ChangeMe;
+}
diff --git a/t/t4018/sh-function-string b/t/t4018/sh-function-string
new file mode 100644
index 0000000000..f60a899bc3
--- /dev/null
+++ b/t/t4018/sh-function-string
@@ -0,0 +1,4 @@
+RIGHT_foo() {
+ echo "bar()"
+ ChangeMe;
+}
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index f2f55fc51c..24fd9aa454 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -312,6 +312,7 @@ test_language_driver perl
test_language_driver php
test_language_driver python
test_language_driver ruby
+test_language_driver sh
test_language_driver tex
test_expect_success 'word-diff with diff.sbe' '
diff --git a/t/t4034/sh/expect b/t/t4034/sh/expect
new file mode 100644
index 0000000000..1c6de2d92e
--- /dev/null
+++ b/t/t4034/sh/expect
@@ -0,0 +1,46 @@
+<BOLD>diff --git a/pre b/post<RESET>
+<BOLD>index 20229c3..ab791db 100644<RESET>
+<BOLD>--- a/pre<RESET>
+<BOLD>+++ b/post<RESET>
+<CYAN>@@ -1,36 +1,36 @@<RESET>
+foo() {ls&echo}<RESET>
+$((<RED>a<RESET><GREEN>x<RESET>++))
+$((<RED>a<RESET><GREEN>x<RESET>--))
+$((--<RED>a<RESET><GREEN>x<RESET>))
+$((++<RED>a<RESET><GREEN>x<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>*<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>&<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>**<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>/<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>%<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>+<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>-<RED>b<RESET><GREEN>y<RESET>))
+[ <RED>a<RESET><GREEN>x<RESET><=<RED>b<RESET><GREEN>y<RESET> ]
+[ <RED>a<RESET><GREEN>x<RESET>>=<RED>b<RESET><GREEN>y<RESET> ]
+[ <RED>a<RESET><GREEN>x<RESET>==<RED>b<RESET><GREEN>y<RESET> ]
+[ <RED>a<RESET><GREEN>x<RESET>!=<RED>b<RESET><GREEN>y<RESET> ]
+<RED>a<RESET><GREEN>x<RESET><<<RED>b a<RESET><GREEN>y x<RESET>>><RED>b a<RESET><GREEN>y x<RESET><<-<RED>b a<RESET><GREEN>y x<RESET><<RED>b a<RESET><GREEN>y x<RESET>><RED>b a<RESET><GREEN>y x<RESET>>|<RED>b a<RESET><GREEN>y x<RESET><&<RED>b a<RESET><GREEN>y x<RESET>>&<RED>b a<RESET><GREEN>y x<RESET><><RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>&<RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>&&<RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>|<RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>||<RED>b<RESET>
+<RED>a<RESET><GREEN>y<RESET>
+<GREEN>x<RESET>=<RED>b<RESET><GREEN>y<RESET>
+$((<RED>a<RESET><GREEN>x<RESET>+=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>-=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>*=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>/=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>%=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET><<=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>>>=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>&=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>^=<RED>b<RESET><GREEN>y<RESET>))
+$((<RED>a<RESET><GREEN>x<RESET>|=<RED>b<RESET><GREEN>y<RESET>))
+*)<RED>a<RESET><GREEN>b<RESET>;;ls
+FOO=42&<RED>foo<RESET><GREEN>fro<RESET>
+BAR=$(0)<RESET>
+[[ $<RED>a<RESET><GREEN>x<RESET> -eq $<RED>b<RESET><GREEN>y<RESET> ]]
diff --git a/t/t4034/sh/post b/t/t4034/sh/post
new file mode 100644
index 0000000000..ab791db1e6
--- /dev/null
+++ b/t/t4034/sh/post
@@ -0,0 +1,36 @@
+foo() {ls&echo}
+$((x++))
+$((x--))
+$((--x))
+$((++x))
+$((x*y))
+$((x&y))
+$((x**y))
+$((x/y))
+$((x%y))
+$((x+y))
+$((x-y))
+[ x<=y ]
+[ x>=y ]
+[ x==y ]
+[ x!=y ]
+x<<y x>>y x<<-y x<y x>y x>|y x<&y x>&y x<>y
+x&y
+x&&y
+x|y
+x||y
+x=y
+$((x+=y))
+$((x-=y))
+$((x*=y))
+$((x/=y))
+$((x%=y))
+$((x<<=y))
+$((x>>=y))
+$((x&=y))
+$((x^=y))
+$((x|=y))
+*)b;;ls
+FOO=42&fro
+BAR=$(0)
+[[ $x -eq $y ]]
diff --git a/t/t4034/sh/pre b/t/t4034/sh/pre
new file mode 100644
index 0000000000..20229c36f7
--- /dev/null
+++ b/t/t4034/sh/pre
@@ -0,0 +1,36 @@
+foo() {ls&echo}
+$((a++))
+$((a--))
+$((--a))
+$((++a))
+$((a*b))
+$((a&b))
+$((a**b))
+$((a/b))
+$((a%b))
+$((a+b))
+$((a-b))
+[ a<=b ]
+[ a>=b ]
+[ a==b ]
+[ a!=b ]
+a<<b a>>b a<<-b a<b a>b a>|b a<&b a>&b a<>b
+a&b
+a&&b
+a|b
+a||b
+a=b
+$((a+=b))
+$((a-=b))
+$((a*=b))
+$((a/=b))
+$((a%=b))
+$((a<<=b))
+$((a>>=b))
+$((a&=b))
+$((a^=b))
+$((a|=b))
+*)a;;ls
+FOO=42&foo
+BAR=$(0)
+[[ $a -eq $b ]]
diff --git a/userdiff.c b/userdiff.c
index 2ccbee50cb..cd0cf21f88 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -146,6 +146,13 @@ PATTERNS("csharp",
"[a-zA-Z_][a-zA-Z0-9_]*"
"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
"|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
+PATTERNS("sh",
+ "^([ \t]*(function[ \t]+)?[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\).*)$",
+ /* -- */
+ "[a-zA-Z0-9_]+"
+ "|[-+0-9]+"
+ "|[-+*/<>%&^|=!]=|>>=?|<<=?|\\+\\+|--|\\*\\*|&&|\\|\\||\\[\\[|\\]\\]"
+ "|>\\||[<>]+&|<>|<<-|;;"),
{ "default", NULL, -1, { NULL, 0 } },
};
#undef PATTERNS