123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #!/usr/bin/env bash
- TOPLEVEL=$(git rev-parse --show-toplevel)
- PATH=$TOPLEVEL/scripts:$PATH
- cd $TOPLEVEL
- GP=
- if [[ "$OSTYPE" =~ darwin* ]]; then
- GP=g
- fi
- if ! type -p astyle.sh >/dev/null; then
- echo astyle.sh not found
- exit 1
- fi
- if ! type -p colordiff >/dev/null; then
- colordiff()
- {
- cat "$@"
- }
- fi
- if [ "$1" = "-c" ]; then
- echo "Cleaning..."
- remove_temporary_files.sh
- fi
- set -e
- MODIFIED=$(git status --porcelain| ${GP}sed -ne "s/^ *[MA] *//p" | sort -u)
- if [ -z "$MODIFIED" ]; then
- echo nothing was modified
- exit 0
- fi
- REV=$(git log -n1 --pretty=%H)
- git diff >sha-$REV.diff
- ASTYLEDIFF=astyle.$REV.diff
- >$ASTYLEDIFF
- i=0
- N=$(echo $MODIFIED | wc -w)
- for f in $MODIFIED; do
- (( i++ )) || true
- case "$f" in
- thirdparty/*)
- echo $f skipped
- continue
- ;;
- *.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.sip|*.py)
- ;;
- *)
- continue
- ;;
- esac
- m=$f.$REV.prepare
- cp $f $m
- ASTYLEPROGRESS=" [$i/$N]" astyle.sh $f
- if diff -u $m $f >>$ASTYLEDIFF; then
-
- rm $m
- fi
- done
- if [ -s "$ASTYLEDIFF" ]; then
- if tty -s; then
-
- colordiff <$ASTYLEDIFF | less -r
- else
- echo "Files changed (see $ASTYLEDIFF)"
- fi
- exit 1
- else
- rm $ASTYLEDIFF
- fi
- exec git diff-index --check --cached HEAD --
- exit 0
|