# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1222915108 -7200
# Node ID 80edda6f89cdf5e5c30612a0ca757dd5f26f3163
# Parent 1437eaaa5a5b583f9f91479c09b732c7ec363039
Improvements in code checking and unification (ticket #138)
By default check-sources.sh checks only the modified files, but using the
"--all" (or "-a") option it checks all source files (as unify-sources.sh).
The Makefile.am files are included into the checking and unification.
diff --git a/scripts/check-sources.sh b/scripts/check-sources.sh
a
|
b
|
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function check_file() { |
39 | | echo 'check' $1 ... |
| 39 | echo ' check' $FILENAME ... |
40 | 40 | |
41 | 41 | FILE_FAILED=NO |
42 | | if check_header $1 |
| 42 | |
| 43 | if echo $1 | grep -q -v -E 'Makefile\.am$' |
43 | 44 | then |
44 | | echo "header failed" |
45 | | FILE_FAILED=YES |
46 | | GLOBAL_FAILED=YES |
47 | | fi |
48 | | |
49 | | if grep -q -E "$TAB" $1 |
50 | | then |
51 | | echo "tabs failed:" |
52 | | grep -n -E "$TAB" $1 |
53 | | FILE_FAILED=YES |
54 | | GLOBAL_FAILED=YES |
| 45 | if check_header $1 |
| 46 | then |
| 47 | echo "header failed" |
| 48 | FILE_FAILED=YES |
| 49 | GLOBAL_FAILED=YES |
| 50 | fi |
| 51 | |
| 52 | if grep -q -E "$TAB" $1 |
| 53 | then |
| 54 | echo "tabs failed:" |
| 55 | grep -n -E "$TAB" $1 |
| 56 | FILE_FAILED=YES |
| 57 | GLOBAL_FAILED=YES |
| 58 | fi |
| 59 | else |
| 60 | if grep -q -E " " $1 |
| 61 | then |
| 62 | echo "spaces failed:" |
| 63 | grep -n -E " " $1 |
| 64 | FILE_FAILED=YES |
| 65 | GLOBAL_FAILED=YES |
| 66 | fi |
55 | 67 | fi |
56 | 68 | |
57 | 69 | if grep -q -E ' $' $1 |
… |
… |
|
66 | 78 | then |
67 | 79 | echo "long lines failed:" |
68 | 80 | grep -n -E '.{81,}' $1 |
69 | | if [ $GLOBAL_FAILED != YES ] |
70 | | then |
71 | | echo -n "Abort commit? (yes/no) " |
72 | | read RESULT |
73 | | if [ "$RESULT" != "no" ] |
74 | | then |
75 | | FILE_FAILED=YES |
76 | | GLOBAL_FAILED=YES |
77 | | fi |
78 | | fi |
| 81 | FILE_FAILED=YES |
| 82 | GLOBAL_FAILED=YES |
79 | 83 | fi |
80 | 84 | |
81 | 85 | if [[ $FILE_FAILED = YES ]]; |
… |
… |
|
88 | 92 | TOTAL_FILES=0 |
89 | 93 | GLOBAL_FAILED=NO |
90 | 94 | |
| 95 | function list_files() { |
| 96 | hg status -a -m -c | |
| 97 | cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | sort | uniq |
| 98 | } |
| 99 | |
91 | 100 | function changed_files() { |
92 | 101 | { |
93 | 102 | if [ -n "$HG_PARENT1" ] |
… |
… |
|
98 | 107 | then |
99 | 108 | hg status --rev $HG_PARENT2:$HG_NODE -a -m |
100 | 109 | fi |
101 | | } | cut -d ' ' -f 2 | grep -E '\.(cc|h|dox)$' | sort | uniq |
| 110 | } | cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | sort | uniq |
102 | 111 | } |
103 | 112 | |
104 | 113 | if [ $# == 0 ]; then |
105 | 114 | echo Check all modified files... |
106 | | |
107 | 115 | while read FILENAME |
108 | 116 | do |
109 | 117 | check_file "$HGROOT/$FILENAME" |
110 | 118 | ((TOTAL_FILES++)) |
111 | 119 | done < <(changed_files) |
112 | 120 | echo ' done.' |
| 121 | elif [[ ($# == 1) && (($1 == "--all") || ($1 == "-a")) ]]; then |
| 122 | echo Check all source files... |
| 123 | while read FILENAME |
| 124 | do |
| 125 | check_file "$HGROOT/$FILENAME" |
| 126 | ((TOTAL_FILES++)) |
| 127 | done < <(list_files) |
| 128 | echo ' done.' |
113 | 129 | else |
114 | | for i in $@ |
| 130 | for FILENAME in $@ |
115 | 131 | do |
116 | | check_file $i |
| 132 | check_file $FILENAME |
117 | 133 | ((TOTAL_FILES++)) |
118 | 134 | done |
119 | 135 | fi |
diff --git a/scripts/unify-sources.sh b/scripts/unify-sources.sh
a
|
b
|
|
43 | 43 | TMP_FILE=`mktemp` |
44 | 44 | FILE_NAME=$1 |
45 | 45 | |
46 | | cat $1 | |
47 | | sed -e 's/\t/ /g' >$TMP_FILE |
| 46 | if echo $1 | grep -q -v -E 'Makefile\.am$' |
| 47 | then |
| 48 | cat $1 | sed -e 's/\t/ /g' >$TMP_FILE |
| 49 | else |
| 50 | cat $1 | sed -e 's/ /\t/g' >$TMP_FILE |
| 51 | fi |
48 | 52 | |
49 | 53 | TABS_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES` |
50 | 54 | |
… |
… |
|
72 | 76 | function update_file() { |
73 | 77 | echo -n ' update' $i ... |
74 | 78 | |
75 | | update_header $1 |
| 79 | if echo $1 | grep -q -v -E 'Makefile\.am$' |
| 80 | then |
| 81 | update_header $1 |
| 82 | fi |
76 | 83 | update_tabs $1 |
77 | 84 | remove_trailing_space $1 |
78 | 85 | |
… |
… |
|
84 | 91 | fi |
85 | 92 | if [[ $TABS_CH = YES ]]; |
86 | 93 | then |
87 | | echo -n ' [tabs removed]' |
| 94 | if echo $1 | grep -q -v -E 'Makefile\.am$' |
| 95 | then |
| 96 | echo -n ' [tabs removed]' |
| 97 | else |
| 98 | echo -n ' [spaces replaced with tabs]' |
| 99 | fi |
88 | 100 | CHANGED=YES; |
89 | 101 | fi |
90 | 102 | if [[ $SPACES_CH = YES ]]; |
… |
… |
|
106 | 118 | |
107 | 119 | function list_files() { |
108 | 120 | hg status -a -m -c | |
109 | | cut -d ' ' -f 2 | grep -E '\.(cc|h|dox)$' | sort | uniq |
| 121 | cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | sort | uniq |
110 | 122 | } |
111 | 123 | |
112 | 124 | CHANGED_FILES=0 |