forked from qgis/QGIS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare-commit.sh
executable file
·64 lines (51 loc) · 995 Bytes
/
prepare-commit.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
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 "$@"
}
fi
set -e
# determine changed files
MODIFIED=$(svn status | sed -ne "s/^[MA] *//p")
if [ -z "$MODIFIED" ]; then
echo nothing was modified
exit 1
fi
# save original changes
REV=$(svn info | sed -ne "s/Revision: //p")
svn diff >r$REV.diff
ASTYLEDIFF=astyle.r$REV.diff
>$ASTYLEDIFF
# reformat
for f in $MODIFIED; do
case "$f" in
*.cpp|*.h|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H)
;;
*)
continue
;;
esac
m=$f.r$REV.prepare
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
else
rm $ASTYLEDIFF
fi