2008-08-24 13:57:54 +00:00
|
|
|
#!/bin/bash
|
2012-10-04 19:33:47 +02:00
|
|
|
###########################################################################
|
|
|
|
# prepare-commit.sh
|
|
|
|
# ---------------------
|
|
|
|
# Date : August 2008
|
|
|
|
# Copyright : (C) 2008 by Juergen E. Fischer
|
|
|
|
# Email : jef at norbit dot de
|
|
|
|
###########################################################################
|
|
|
|
# #
|
|
|
|
# This program is free software; you can redistribute it and/or modify #
|
|
|
|
# it under the terms of the GNU General Public License as published by #
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
###########################################################################
|
|
|
|
|
2008-08-24 13:57:54 +00:00
|
|
|
|
2008-08-30 15:20:16 +00:00
|
|
|
PATH=$PATH:$(dirname $0)
|
|
|
|
|
|
|
|
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 "$@"
|
|
|
|
}
|
2008-08-24 13:57:54 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# determine changed files
|
2010-11-16 20:20:27 +00:00
|
|
|
if [ -d .svn ]; then
|
|
|
|
MODIFIED=$(svn status | sed -ne "s/^[MA] *//p")
|
|
|
|
elif [ -d .git ]; then
|
2012-07-29 21:37:22 +02:00
|
|
|
MODIFIED=$(git status --porcelain| sed -ne "s/^ *[MA] *//p" | sort -u)
|
2010-11-16 20:20:27 +00:00
|
|
|
else
|
|
|
|
echo No working copy
|
|
|
|
exit 1
|
|
|
|
fi
|
2008-08-24 13:57:54 +00:00
|
|
|
|
|
|
|
if [ -z "$MODIFIED" ]; then
|
|
|
|
echo nothing was modified
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# save original changes
|
2010-11-16 20:20:27 +00:00
|
|
|
if [ -d .svn ]; then
|
2011-05-04 21:56:25 +02:00
|
|
|
REV=r$(svn info | sed -ne "s/Revision: //p")
|
2012-04-26 13:51:33 +02:00
|
|
|
svn diff >rev-$REV.diff
|
2010-11-16 20:20:27 +00:00
|
|
|
elif [ -d .git ]; then
|
2011-05-04 21:56:25 +02:00
|
|
|
REV=$(git log -n1 --pretty=%H)
|
2012-04-26 13:51:33 +02:00
|
|
|
git diff >sha-$REV.diff
|
2010-11-16 20:20:27 +00:00
|
|
|
fi
|
2008-08-24 13:57:54 +00:00
|
|
|
|
2011-05-04 21:56:25 +02:00
|
|
|
ASTYLEDIFF=astyle.$REV.diff
|
2008-08-24 13:57:54 +00:00
|
|
|
>$ASTYLEDIFF
|
|
|
|
|
|
|
|
# reformat
|
|
|
|
for f in $MODIFIED; do
|
|
|
|
case "$f" in
|
2010-01-11 10:36:44 +00:00
|
|
|
src/core/spatialite/*|src/core/gps/qextserialport/*)
|
2009-12-23 16:14:24 +00:00
|
|
|
echo $f skipped
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
|
|
|
|
*.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H)
|
2008-08-24 13:57:54 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2011-05-04 21:56:25 +02:00
|
|
|
m=$f.$REV.prepare
|
2008-08-24 13:57:54 +00:00
|
|
|
|
|
|
|
cp $f $m
|
|
|
|
astyle.sh $f
|
|
|
|
if diff -u $m $f >>$ASTYLEDIFF; then
|
|
|
|
# no difference found
|
|
|
|
rm $m
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -s "$ASTYLEDIFF" ]; then
|
|
|
|
if tty -s; then
|
|
|
|
# review astyle changes
|
|
|
|
colordiff <$ASTYLEDIFF | less -r
|
|
|
|
else
|
|
|
|
echo "Files changed (see $ASTYLEDIFF)"
|
|
|
|
fi
|
2011-05-08 21:01:34 +02:00
|
|
|
exit 1
|
2008-08-24 13:57:54 +00:00
|
|
|
else
|
|
|
|
rm $ASTYLEDIFF
|
|
|
|
fi
|
2011-05-08 21:01:34 +02:00
|
|
|
|
|
|
|
exit 0
|