Git fork

userdiff: support Bash

Support POSIX, bashism and mixed function declarations, all four
compound command types, trailing comments and mixed whitespace.

Even though Bash allows locale-dependent characters in function names
<https://unix.stackexchange.com/a/245336/3645>, only detect function
names with characters allowed by POSIX.1-2017
<https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_235>
for simplicity. This should cover the vast majority of use cases, and
produces system-agnostic results.

Since a word pattern has to be specified, but there is no easy way to
know the default word pattern, use the default `IFS` characters for a
starter. A later patch can improve this.

Signed-off-by: Victor Engmark <victor@engmark.name>
Acked-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Victor Engmark and committed by
Junio C Hamano
2ff6c346 69986e19

+91
+3
Documentation/gitattributes.txt
··· 802 802 803 803 - `ada` suitable for source code in the Ada language. 804 804 805 + - `bash` suitable for source code in the Bourne-Again SHell language. 806 + Covers a superset of POSIX shell function definitions. 807 + 805 808 - `bibtex` suitable for files with BibTeX coded references. 806 809 807 810 - `cpp` suitable for source code in the C and C++ languages.
+1
t/t4018-diff-funcname.sh
··· 27 27 28 28 diffpatterns=" 29 29 ada 30 + bash 30 31 bibtex 31 32 cpp 32 33 csharp
+4
t/t4018/bash-arithmetic-function
··· 1 + RIGHT() (( 2 + 3 + ChangeMe = "$x" + "$y" 4 + ))
+6
t/t4018/bash-bashism-style-compact
··· 1 + function RIGHT { 2 + function InvalidSyntax{ 3 + : 4 + echo 'ChangeMe' 5 + } 6 + }
+4
t/t4018/bash-bashism-style-function
··· 1 + function RIGHT { 2 + : 3 + echo 'ChangeMe' 4 + }
+4
t/t4018/bash-bashism-style-whitespace
··· 1 + function RIGHT ( ) { 2 + 3 + ChangeMe 4 + }
+4
t/t4018/bash-conditional-function
··· 1 + RIGHT() [[ \ 2 + 3 + "$a" > "$ChangeMe" 4 + ]]
+6
t/t4018/bash-missing-parentheses
··· 1 + function RIGHT { 2 + functionInvalidSyntax { 3 + : 4 + echo 'ChangeMe' 5 + } 6 + }
+4
t/t4018/bash-mixed-style-compact
··· 1 + function RIGHT(){ 2 + : 3 + echo 'ChangeMe' 4 + }
+4
t/t4018/bash-mixed-style-function
··· 1 + function RIGHT() { 2 + 3 + ChangeMe 4 + }
+6
t/t4018/bash-nested-functions
··· 1 + outer() { 2 + RIGHT() { 3 + : 4 + echo 'ChangeMe' 5 + } 6 + }
+4
t/t4018/bash-other-characters
··· 1 + _RIGHT_0n() { 2 + 3 + ChangeMe 4 + }
+4
t/t4018/bash-posix-style-compact
··· 1 + RIGHT(){ 2 + 3 + ChangeMe 4 + }
+4
t/t4018/bash-posix-style-function
··· 1 + RIGHT() { 2 + 3 + ChangeMe 4 + }
+4
t/t4018/bash-posix-style-whitespace
··· 1 + RIGHT ( ) { 2 + 3 + ChangeMe 4 + }
+4
t/t4018/bash-subshell-function
··· 1 + RIGHT() ( 2 + 3 + ChangeMe=2 4 + )
+4
t/t4018/bash-trailing-comment
··· 1 + RIGHT() { # Comment 2 + 3 + ChangeMe 4 + }
+21
userdiff.c
··· 23 23 "[a-zA-Z][a-zA-Z0-9_]*" 24 24 "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?" 25 25 "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"), 26 + PATTERNS("bash", 27 + /* Optional leading indentation */ 28 + "^[ \t]*" 29 + /* Start of captured text */ 30 + "(" 31 + "(" 32 + /* POSIX identifier with mandatory parentheses */ 33 + "[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\))" 34 + "|" 35 + /* Bashism identifier with optional parentheses */ 36 + "(function[ \t]+[a-zA-Z_][a-zA-Z0-9_]*(([ \t]*\\([ \t]*\\))|([ \t]+))" 37 + ")" 38 + /* Optional whitespace */ 39 + "[ \t]*" 40 + /* Compound command starting with `{`, `(`, `((` or `[[` */ 41 + "(\\{|\\(\\(?|\\[\\[)" 42 + /* End of captured text */ 43 + ")", 44 + /* -- */ 45 + /* Characters not in the default $IFS value */ 46 + "[^ \t]+"), 26 47 PATTERNS("dts", 27 48 "!;\n" 28 49 "!=\n"