summaryrefslogtreecommitdiffstats
path: root/git_hooks
diff options
context:
space:
mode:
authorClément DAVID <clement.david@scilab-enterprises.com>2013-08-22 08:57:08 +0200
committerPaul BIGNIER <paul.bignier@scilab-enterprises.com>2013-08-22 09:19:38 +0200
commit7e02f4351992cb97ea8822e040531f65075a3694 (patch)
tree3e6ca528180b16f4762d7dbf45a594712b998b37 /git_hooks
parent4457d94705f3f9c0c615ea1cf921919a652b2821 (diff)
downloadscilab-7e02f4351992cb97ea8822e040531f65075a3694.zip
scilab-7e02f4351992cb97ea8822e040531f65075a3694.tar.gz
Hooks: only call the indenter once and indent .tst
Only calling once each tool improve the speed (especially on scilab indent). Change-Id: I547642daf2ee0ed44db2e9e54148c0caf2b931dd
Diffstat (limited to 'git_hooks')
-rwxr-xr-xgit_hooks/pre-commit100
1 files changed, 37 insertions, 63 deletions
diff --git a/git_hooks/pre-commit b/git_hooks/pre-commit
index 01b22a4..5ba588f 100755
--- a/git_hooks/pre-commit
+++ b/git_hooks/pre-commit
@@ -39,7 +39,7 @@ then
39 echo " git config --add xmlindent.ignored 'scilab/Visual-Studio-settings/*.xml' " 39 echo " git config --add xmlindent.ignored 'scilab/Visual-Studio-settings/*.xml' "
40 echo " git config --add xmlindent.ignored 'scilab/checkstyle/*.xml' " 40 echo " git config --add xmlindent.ignored 'scilab/checkstyle/*.xml' "
41 echo 41 echo
42 42
43 XMLINDENT_IGNORED="" 43 XMLINDENT_IGNORED=""
44else 44else
45 XMLINDENT_IGNORED="$(find $(git config --get-all xmlindent.ignored))" 45 XMLINDENT_IGNORED="$(find $(git config --get-all xmlindent.ignored))"
@@ -77,9 +77,9 @@ then
77 echo " git config --add astyle.ignored 'scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/MatchingBlockScanner.java' " 77 echo " git config --add astyle.ignored 'scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/MatchingBlockScanner.java' "
78 echo " git config --add astyle.ignored 'scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/ScilabLexer.java' " 78 echo " git config --add astyle.ignored 'scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/ScilabLexer.java' "
79 echo " git config --add astyle.ignored 'scilab/modules/scicos/src/scicos_sundials/*' " 79 echo " git config --add astyle.ignored 'scilab/modules/scicos/src/scicos_sundials/*' "
80 80
81 echo 81 echo
82 82
83 ASTYLE_IGNORED="" 83 ASTYLE_IGNORED=""
84else 84else
85 ASTYLE_IGNORED="$(find $(git config --get-all astyle.ignored))" 85 ASTYLE_IGNORED="$(find $(git config --get-all astyle.ignored))"
@@ -97,55 +97,34 @@ indent() {
97 local against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 97 local against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
98 fi 98 fi
99 99
100 # loop on modified files 100 # get the modified files per kind filtering out ignored files and call the
101 git diff --cached --name-only $against |while read file; 101 # __indent_XXX helper
102 do 102
103 local ext=$(expr "$file" : ".*\(\..*\)") 103 FILES=$(git diff --cached --name-only $against |grep -E "\.(xcos|xml|xsl)$" |grep -v -F "$XMLINDENT_IGNORED")
104 case $ext in 104 [ -z "$FILES" ] || __indent_xml;
105 .xcos|.xml|.xsl) 105
106 __indent_xml; 106 FILES=$(git diff --cached --name-only $against |grep -E "\.(h|c|hxx|cpp)$" |grep -v -F "$ASTYLE_IGNORED")
107 ;; 107 [ -z "$FILES" ] || __indent_C;
108 .h|.c|.hxx|.cpp) 108
109 __indent_C; 109 FILES=$(git diff --cached --name-only $against |grep -E "\.java$" |grep -v -F "$ASTYLE_IGNORED")
110 ;; 110 [ -z "$FILES" ] || __indent_java;
111 .java) 111
112 __indent_java; 112 FILES=$(git diff --cached --name-only $against |grep -E "\.(sce|sci|tst)$")
113 ;; 113 [ -z "$FILES" ] || __indent_scilab;
114 .sce|.sci)
115 __indent_scilab;
116 ;;
117 esac
118 done
119 114
120 return 0; 115 return 0;
121} 116}
122 117
123# Indent the file with xmlindent if this is an xcos file 118# Indent the file with xmlindent if this is an xcos file
124__indent_xml() { 119__indent_xml() {
125
126 if test ! -x "$XMLINDENT" 120 if test ! -x "$XMLINDENT"
127 then 121 then
128 return 1; 122 return 1;
129 fi 123 fi
130 if test ! -f $file
131 then
132 return 2;
133 fi
134
135 # ignored globs
136 if test -n "$XMLINDENT_IGNORED"
137 then
138 echo $XMLINDENT_IGNORED |grep -q $file
139 if test $? -eq 0
140 then
141 echo "Formatting" $file ": ignored"
142 return 3;
143 fi
144 fi
145 124
146 echo "Formatting" $file 125 echo "Formatting" "$FILES"
147 "$XMLINDENT" -w -i 4 "$file" || return 4; 126 "$XMLINDENT" -w -i 4 $FILES || return 2;
148 git add "$file" || return 5; 127 git add $FILES || return 3;
149} 128}
150 129
151# Pre process before the indent 130# Pre process before the indent
@@ -154,29 +133,14 @@ __pre_indent() {
154 then 133 then
155 return 1; 134 return 1;
156 fi 135 fi
157 if test ! -f $file
158 then
159 return 2;
160 fi
161
162 # ignored globs
163 if test -n "$ASTYLE_IGNORED"
164 then
165 echo $ASTYLE_IGNORED |grep -q "$file"
166 if test $? -eq 0
167 then
168 echo "Indenting" $file ": ignored"
169 return 3;
170 fi
171 fi
172 136
173 echo "Indenting" $file 137 echo "Indenting" $FILES
174 return 0; 138 return 0;
175} 139}
176 140
177# post process after the indent 141# post process after the indent
178__post_indent() { 142__post_indent() {
179 git add "$file" 143 git add $FILES
180} 144}
181 145
182COMMON_ASTYLE_ARGS="--pad-header --suffix=none --pad-oper --indent-col1-comments --indent-switches --indent=spaces=4 --add-brackets --formatted" 146COMMON_ASTYLE_ARGS="--pad-header --suffix=none --pad-oper --indent-col1-comments --indent-switches --indent=spaces=4 --add-brackets --formatted"
@@ -184,7 +148,7 @@ COMMON_ASTYLE_ARGS="--pad-header --suffix=none --pad-oper --indent-col1-comments
184# Indent the file with `astyle' if this is a C/CPP file 148# Indent the file with `astyle' if this is a C/CPP file
185__indent_C() { 149__indent_C() {
186 __pre_indent || return 1 150 __pre_indent || return 1
187 $ASTYLE $COMMON_ASTYLE_ARGS --style=bsd "$file" || return 2 151 $ASTYLE $COMMON_ASTYLE_ARGS --style=bsd $FILES || return 2
188 __post_indent || return 3 152 __post_indent || return 3
189 return 0 153 return 0
190} 154}
@@ -192,7 +156,7 @@ __indent_C() {
192# Indent the file with `astyle' if this is a Java file 156# Indent the file with `astyle' if this is a Java file
193__indent_java() { 157__indent_java() {
194 __pre_indent || return 1 158 __pre_indent || return 1
195 $ASTYLE $COMMON_ASTYLE_ARGS --style=java "$file" || return 2 159 $ASTYLE $COMMON_ASTYLE_ARGS --style=java $FILES || return 2
196 __post_indent || return 3 160 __post_indent || return 3
197 return 0 161 return 0
198} 162}
@@ -200,20 +164,30 @@ __indent_java() {
200# Indent the file with `scinotes' if this is a Scilab file 164# Indent the file with `scinotes' if this is a Scilab file
201__indent_scilab() { 165__indent_scilab() {
202 __pre_indent || return 1 166 __pre_indent || return 1
167
168 TMPFILE="scinotes_indent.sce"
169 echo "files = [" >$TMPFILE
170 printf "'%s'\n" $FILES >>$TMPFILE
171 echo "];" >>$TMPFILE
172
173 echo "scinotes(files, ['indent','trailing','quote'])" >>$TMPFILE
174 echo "exit(0)" >>$TMPFILE
175
203 if test -f scilab/scilab-bin; then 176 if test -f scilab/scilab-bin; then
204 scilab/bin/scinotes -indent "$file" || return 2 177 scilab/bin/scilab -nw -f $TMPFILE || return 2
205 else 178 else
206 if test -f scilab/bin/WScilex.exe; then 179 if test -f scilab/bin/WScilex.exe; then
207 scilab/bin/scilex.exe -e "scinotes('$file', ['indent','trailing','quote'])" || return 2 180 scilab/bin/scilex.exe -f $TMPFILE || return 2
208 else 181 else
209 echo "Scilab has not been built." 182 echo "Scilab has not been built."
183 rm $TMPFILE
210 return 4 184 return 4
211 fi 185 fi
212 fi 186 fi
187 rm $TMPFILE
213 188
214 __post_indent || return 3 189 __post_indent || return 3
215 return 0 190 return 0
216} 191}
217 192
218indent 193indent
219