2
2
3
3
set -e
4
4
5
- script_folder=` dirname $0 `
6
- absolute_repository_root=` git rev-parse --show-toplevel`
5
+ script_folder=$( dirname " $0 " )
6
+ absolute_repository_root=$( git rev-parse --show-toplevel)
7
7
mode=$1
8
8
modes=" CPPLINT | DOXYGEN"
9
9
16
16
exit 1
17
17
fi
18
18
19
- if ! [[ -e $script_folder /filter_by_diff .py ]]
19
+ if ! [[ -e ${ script_folder} /filter_by_lines .py ]]
20
20
then
21
21
echo " Filter script could not be found in the $script_folder directory"
22
- echo " Ensure filter_by_diff .py is inside the $script_folder directory then run again"
22
+ echo " Ensure filter_by_lines .py is inside the $script_folder directory then run again"
23
23
exit 1
24
24
fi
25
25
26
26
if [[ " $mode " == " CPPLINT" ]]
27
27
then
28
- if ! [[ -e $script_folder /cpplint.py ]]
28
+ if ! which iconv > /dev/null
29
+ then
30
+ echo " Couldn't find iconv in current path. Please install and try again"
31
+ exit 1
32
+ fi
33
+
34
+ if ! [[ -e " ${script_folder} /cpplint.py" ]]
29
35
then
30
36
echo " Lint script could not be found in the $script_folder directory"
31
37
echo " Ensure cpplint.py is inside the $script_folder directory then run again"
32
38
exit 1
33
39
else
34
- cmd=' $script_folder/cpplint.py $file 2>&1 >/dev/null'
40
+ cmd=' ${ script_folder} /cpplint.py $file 2>&1 >/dev/null'
35
41
fi
36
42
elif [[ " $mode " == " DOXYGEN" ]]
37
43
then
72
78
git_merge_base_end=" HEAD"
73
79
fi
74
80
75
- git_start=` git merge-base $git_start $git_merge_base_end `
81
+ git_start=$( git merge-base $git_start $git_merge_base_end )
76
82
77
83
cleanup ()
78
84
{
79
- rm -f $diff_file
85
+ rm -f " $diff_file " " $added_lines_file "
80
86
}
81
87
82
88
trap cleanup EXIT
83
89
84
- diff_file=` mktemp`
90
+ diff_file=$( mktemp)
91
+ added_lines_file=$( mktemp)
92
+
93
+ # Pass the output through iconv to remove any invalid UTF-8 (diff_to_added_lines.py will die otherwise)
94
+
95
+ git diff $git_start $git_end | iconv -t utf-8 -c > " $diff_file "
85
96
86
- git diff $git_start $git_end > $diff_file
97
+ # Get the list of files that have changed, that end with lintable extensions
98
+ diff_files=$( git diff --name-only $git_start $git_end | grep " \.\(\(cpp\)\|\(hh\)\|\(cc\)\|h\)$" || true)
87
99
88
- # Get the list of files that have changed
89
- diff_files=` git diff --name-only $git_start $git_end `
100
+ " ${script_folder} /diff_to_added_lines.py" " $diff_file " " $absolute_repository_root " > " $added_lines_file "
90
101
91
102
for file in $diff_files ; do
92
103
file=$absolute_repository_root /$file
@@ -98,7 +109,7 @@ for file in $diff_files; do
98
109
99
110
# Run the linting script and filter:
100
111
# The errors from the linter go to STDERR so must be redirected to STDOUT
101
- result=` eval $cmd | $ script_folder/filter_by_diff .py $file $diff_file $absolute_repository_root `
112
+ result=$( eval $cmd | " ${ script_folder} /filter_by_lines .py" " $file " " $added_lines_file " " $absolute_repository_root " )
102
113
103
114
# Providing some errors were relevant we print them out
104
115
if [ " $result " ]
0 commit comments