OLD | NEW |
1 #!/bin/sh | 1 #!/bin/sh |
2 self="$0" | 2 self="$0" |
3 dirname_self=$(dirname "$self") | 3 dirname_self=$(dirname "$self") |
4 | 4 |
5 usage() { | 5 usage() { |
6 cat <<EOF >&2 | 6 cat <<EOF >&2 |
7 Usage: $self [option] | 7 Usage: $self [option] |
8 | 8 |
9 This script applies a whitespace transformation to the commit at HEAD. If no | 9 This script applies a whitespace transformation to the commit at HEAD. If no |
10 options are given, then the modified files are left in the working tree. | 10 options are given, then the modified files are left in the working tree. |
(...skipping 11 matching lines...) Expand all Loading... |
22 exit 1 | 22 exit 1 |
23 } | 23 } |
24 | 24 |
25 | 25 |
26 log() { | 26 log() { |
27 echo "${self##*/}: $@" >&2 | 27 echo "${self##*/}: $@" >&2 |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 vpx_style() { | 31 vpx_style() { |
32 astyle --style=bsd --min-conditional-indent=0 --break-blocks \ | 32 for f; do |
33 --pad-oper --pad-header --unpad-paren \ | 33 case "$f" in |
34 --align-pointer=name \ | 34 *.h|*.c|*.cc) |
35 --indent-preprocessor --convert-tabs --indent-labels \ | 35 "${dirname_self}"/vpx-astyle.sh "$f" |
36 --suffix=none --quiet "$@" | 36 ;; |
37 sed -i "" 's/[[:space:]]\{1,\},/,/g' "$@" | 37 esac |
| 38 done |
38 } | 39 } |
39 | 40 |
40 | 41 |
41 apply() { | 42 apply() { |
42 [ $INTERSECT_RESULT -ne 0 ] && patch -p1 < "$1" | 43 [ $INTERSECT_RESULT -ne 0 ] && patch -p1 < "$1" |
43 } | 44 } |
44 | 45 |
45 | 46 |
46 commit() { | 47 commit() { |
47 LAST_CHANGEID=$(git show | awk '/Change-Id:/{print $2}') | 48 LAST_CHANGEID=$(git show | awk '/Change-Id:/{print $2}') |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 exit 1 | 113 exit 1 |
113 fi | 114 fi |
114 | 115 |
115 # Need to be in the root | 116 # Need to be in the root |
116 cd "$(git rev-parse --show-toplevel)" | 117 cd "$(git rev-parse --show-toplevel)" |
117 | 118 |
118 # Collect the original diff | 119 # Collect the original diff |
119 git show > "${ORIG_DIFF}" | 120 git show > "${ORIG_DIFF}" |
120 | 121 |
121 # Apply the style guide on new and modified files and collect its diff | 122 # Apply the style guide on new and modified files and collect its diff |
122 for f in $(git diff HEAD^ --name-only -M90 --diff-filter=AM \ | 123 for f in $(git diff HEAD^ --name-only -M90 --diff-filter=AM); do |
123 | grep '\.[ch]$'); do | |
124 case "$f" in | 124 case "$f" in |
125 third_party/*) continue;; | 125 third_party/*) continue;; |
126 nestegg/*) continue;; | 126 nestegg/*) continue;; |
127 esac | 127 esac |
128 vpx_style "$f" | 128 vpx_style "$f" |
129 done | 129 done |
130 git diff --no-color --no-ext-diff > "${MODIFIED_DIFF}" | 130 git diff --no-color --no-ext-diff > "${MODIFIED_DIFF}" |
131 | 131 |
132 # Intersect the two diffs | 132 # Intersect the two diffs |
133 "${dirname_self}"/intersect-diffs.py \ | 133 "${dirname_self}"/intersect-diffs.py \ |
(...skipping 17 matching lines...) Expand all Loading... |
151 else | 151 else |
152 apply "${FINAL_DIFF}" | 152 apply "${FINAL_DIFF}" |
153 if ! git diff --quiet; then | 153 if ! git diff --quiet; then |
154 log "Formatting changes applied, verify and commit." | 154 log "Formatting changes applied, verify and commit." |
155 log "See also: http://www.webmproject.org/code/contribute/conventions/" | 155 log "See also: http://www.webmproject.org/code/contribute/conventions/" |
156 git diff --stat | 156 git diff --stat |
157 fi | 157 fi |
158 fi | 158 fi |
159 | 159 |
160 rm -f ${CLEAN_FILES} | 160 rm -f ${CLEAN_FILES} |
OLD | NEW |