summaryrefslogtreecommitdiffstats
path: root/git_hooks
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre.ledru@scilab-enterprises.com>2012-01-27 15:17:37 +0100
committerVincent COUVERT <vincent.couvert@scilab.org>2012-01-31 17:11:40 +0100
commit6442d5aaf6fd5cfcbf1df009c0ac415051fb3770 (patch)
tree5c99a1070ce3d72e86b504db396bb495d7180e08 /git_hooks
parent2c5d5494b05f0add87ba33ad5aab9cb51f1bdcd0 (diff)
downloadscilab-6442d5aaf6fd5cfcbf1df009c0ac415051fb3770.zip
scilab-6442d5aaf6fd5cfcbf1df009c0ac415051fb3770.tar.gz
Switch to astyle for the C, C++ & Java indentation
Change-Id: I1435140105a2e0520847e568a21554c3463fb9c6
Diffstat (limited to 'git_hooks')
-rwxr-xr-xgit_hooks/pre-commit62
1 files changed, 43 insertions, 19 deletions
diff --git a/git_hooks/pre-commit b/git_hooks/pre-commit
index 73bac24..13d1891 100755
--- a/git_hooks/pre-commit
+++ b/git_hooks/pre-commit
@@ -46,31 +46,31 @@ else
46 XMLINDENT_IGNORED="$(find $(git config --get-all xmlindent.ignored))" 46 XMLINDENT_IGNORED="$(find $(git config --get-all xmlindent.ignored))"
47fi 47fi
48 48
49INDENT="$(git config --get hooks.indent)" 49INDENT="$(git config --get hooks.astyle)"
50if test ! -x "$INDENT" 50if test ! -x "$INDENT"
51then 51then
52 echo "Unable to find indent executable on the configuration." 52 echo "Unable to find astyle executable on the configuration."
53 echo 53 echo
54 echo "Please configure it with :" 54 echo "Please configure it with :"
55 echo " git config --global hooks.indent C:/path/to/indent" 55 echo " git config --global hooks.astyle C:/path/to/astyle"
56 echo " or " 56 echo " or "
57 echo " git config --global hooks.indent /usr/bin/indent" 57 echo " git config --global hooks.astyle /usr/bin/astyle"
58 echo 58 echo
59fi 59fi
60 60
61if test -z "$(git config --get-all indent.ignored)" 61if test -z "$(git config --get-all astyle.ignored)"
62then 62then
63 echo "Unable to find indent ignored list on the configuration, ignored" 63 echo "Unable to find astyle ignored list on the configuration, ignored"
64 echo 64 echo
65 echo "You can configure it with :" 65 echo "You can configure it with :"
66 echo " git config --add indent.ignored 'scilab/modules/*/src/jni/*.hxx' " 66 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.hxx' "
67 echo " git config --add indent.ignored 'scilab/modules/*/src/jni/*.cpp' " 67 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.cpp' "
68 echo " git config --add indent.ignored 'scilab/modules/*/src/jni/*.c' " 68 echo " git config --add astyle.ignored 'scilab/modules/*/src/jni/*.c' "
69 echo 69 echo
70 70
71 INDENT_IGNORED="" 71 ASTYLE_IGNORED=""
72else 72else
73 INDENT_IGNORED="$(find $(git config --get-all indent.ignored))" 73 ASTYLE_IGNORED="$(find $(git config --get-all astyle.ignored))"
74fi 74fi
75 75
76# indent / format file by type 76# indent / format file by type
@@ -96,9 +96,13 @@ indent() {
96 .h|.c|.hxx|.cpp) 96 .h|.c|.hxx|.cpp)
97 __indent_C; 97 __indent_C;
98 ;; 98 ;;
99 .java)
100 __indent_java;
101 ;;
99 esac 102 esac
100 done 103 done
101} 104}
105
102# Indent the file with xmlindent if this is an xcos file 106# Indent the file with xmlindent if this is an xcos file
103__indent_Xml() { 107__indent_Xml() {
104 108
@@ -126,10 +130,11 @@ __indent_Xml() {
126 "$XMLINDENT" -i 2 -o "$file" "$file" 130 "$XMLINDENT" -i 2 -o "$file" "$file"
127 git add "$file" 131 git add "$file"
128} 132}
129# Indent the file with `indent' if this is a C/CPP file
130__indent_C() {
131 133
132 if test ! -x "$INDENT" 134# Pre process before the indent
135__pre_indent() {
136
137 if test ! -x "$ASTYLE"
133 then 138 then
134 return; 139 return;
135 fi 140 fi
@@ -139,21 +144,40 @@ __indent_C() {
139 fi 144 fi
140 145
141 # ignored globs 146 # ignored globs
142 if test -n "$INDENT_IGNORED" 147 if test -n "$ASTYLE_IGNORED"
143 then 148 then
144 echo $INDENT_IGNORED |grep -q "$file" 149 echo $ASTYLE_IGNORED |grep -q "$file"
145 if test $? -eq 0 150 if test $? -eq 0
146 then 151 then
147 echo "Indenting" $file ": ignored" 152 echo "Indenting" $file ": ignored"
148 return 153 return
149 fi 154 fi
150 fi 155 fi
151
152 156
153 echo "Indenting" $file 157 echo "Indenting" $file
154 "$INDENT" -npro --braces-after-if-line -i4 -ts4 -sob -ss -ncs -sc --no-space-after-parentheses -cp1 --no-tabs -bap -bad -npcs --dont-break-function-decl-args --dont-break-procedure-type -bli0 -l150 -il0 "$file" 158
159}
160
161# post process after the indent
162__post_indent() {
155 git add "$file" 163 git add "$file"
156} 164}
157 165
158indent 166COMMON_ASTYLE_ARGS="--pad-header -n --pad-oper --indent-col1-comments --indent-switches"
159 167
168# Indent the file with `astyle' if this is a C/CPP file
169__indent_C() {
170 __pre_indent
171 astyle $COMMON_ASTYLE_ARGS --style=linux --indent=spaces=4 -A1 "$file"
172 __post_indent
173}
174
175# Indent the file with `astyle' if this is a Java file
176__indent_java() {
177 __pre_indent
178 astyle $COMMON_ASTYLE_ARGS --style=java --indent=tab "$file"
179 __post_indent
180
181}
182
183indent