- add fg-check script; Can be used to check source/data before committing or
submitting. Detects various kinds of ugliness, but also reports false positives. (People aren't supposed to compress texture filer so save 40 bytes. ;-) - bugfix in fg-submit + some more cleanup and cosmetics
This commit is contained in:
parent
9a1d1e389a
commit
48a57250be
2 changed files with 148 additions and 38 deletions
95
scripts/tools/fg-check
Executable file
95
scripts/tools/fg-check
Executable file
|
@ -0,0 +1,95 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Checks source code and data for potential problems.
|
||||||
|
# Meant to be executed before submitting/committing.
|
||||||
|
|
||||||
|
|
||||||
|
SELF=${0/#*\/}
|
||||||
|
|
||||||
|
# optional apps
|
||||||
|
RLE=$(which rle &>/dev/null) # http://members.aon.at/mfranz/rle.tar.gz (depends on Qt lib)
|
||||||
|
AC3D_SCAN=$(which ac3d-scan 2>/dev/null) # http://members.aon.at/mfranz/ac3d-scan
|
||||||
|
|
||||||
|
|
||||||
|
function ERROR { echo -e "\e[31;1m$*\e[m"; }
|
||||||
|
function LOG { echo -e "\e[35m$*\e[m"; }
|
||||||
|
function RESULT { echo -e "\t$*"; }
|
||||||
|
|
||||||
|
|
||||||
|
TMP=$(mktemp -d -t $SELF.XXX) || (echo "$0: can't create temporary dir"; exit 1)
|
||||||
|
trap "rm -rf $TMP" 0 1 2 3 13 15
|
||||||
|
|
||||||
|
|
||||||
|
LOG "checking for spaces in filenames ..."
|
||||||
|
find .|grep " "|while read i; do RESULT "$i"; done
|
||||||
|
|
||||||
|
|
||||||
|
LOG "checking for upper-case extensions ..." # except *.TXT
|
||||||
|
find .|while read i; do
|
||||||
|
case "$i" in .|..|CVS/*|*/CVS/*|*.Opt|*.README|*.Po) continue ;; esac
|
||||||
|
base=${i/#.*\/}
|
||||||
|
ext=${base/#*./}
|
||||||
|
[ "$base" == "$ext" ] && continue # has no extension
|
||||||
|
ext=$(echo $ext|sed -e 's,[^A-Za-z],,'g)
|
||||||
|
[ -z "$ext" ] && continue # only non-letters
|
||||||
|
lcext=$(echo $ext|sed -e 's,\(.*\),\L\1,')
|
||||||
|
[ "$ext" != "$lcext" -a "$lcext" != "txt" ] && RESULT "$i"
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
LOG "checking for DOS line endings ..."
|
||||||
|
find . -type f|while read i; do
|
||||||
|
desc=$(file -b "$i")
|
||||||
|
case "$desc" in *text*)
|
||||||
|
grep "
$" "$i" >/dev/null && RESULT "$i"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
LOG "checking for uncompressed textures ..."
|
||||||
|
find . -iname \*.rgb -o -iname \*.rgba|while read i; do
|
||||||
|
if file "$i"|grep -v RLE >/dev/null; then
|
||||||
|
new=$TMP/sgi.rgb
|
||||||
|
convert "$i" -compress RLE sgi:$new
|
||||||
|
[ "$RLE" ] && $RLE $new 2>/dev/null
|
||||||
|
perl -e '
|
||||||
|
my $file = shift;
|
||||||
|
my $old = -s $file;
|
||||||
|
my $new = -s shift;
|
||||||
|
if ($new < $old) {
|
||||||
|
printf "\t$file: could be %0.02f%% of current size (%d bytes less)\n",
|
||||||
|
100 * $new / $old, $old - $new;
|
||||||
|
}
|
||||||
|
' "$i" $new
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
if [ "$AC3D_SCAN" ]; then
|
||||||
|
LOG "checking for AC3D sanity ..."
|
||||||
|
find . -iname \*.ac|while read i; do
|
||||||
|
case "$i" in configure.ac|*/configure.ac) continue ;; esac
|
||||||
|
result=$($AC3D_SCAN <$i 2>&1)
|
||||||
|
[ "$result" ] && echo -e "$result\n\t... in file \e[36m$i\e[m";
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
LOG "checking for XML syntax ..."
|
||||||
|
find . -name \*.xml|while read i; do
|
||||||
|
xmllint $i >/dev/null || RESULT "... min file \e[36m$i\e[m"
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
LOG "checking for 'if (foo) delete foo;' ..."
|
||||||
|
find . -iregex ".*\.\([ch]\(xx\|pp\)\|cc\|h\)$"|while read i; do perl -e '
|
||||||
|
my $i = 0;
|
||||||
|
my $name = $ARGV[0];
|
||||||
|
undef $/;
|
||||||
|
$_ = <>;
|
||||||
|
s/(if\s*\(([^\)]+)\)\s*delete(?:\s+|\s*\[\]\s*)\2\s*;)/print "$1\n" and $i++/ges;
|
||||||
|
print "\t... \033[36min file $name\033[m\n" if $i;
|
||||||
|
' "$i"; done
|
||||||
|
|
||||||
|
|
|
@ -11,39 +11,44 @@
|
||||||
# $ fg-submit # generates foo.tar.bz2 and foo.diff
|
# $ fg-submit # generates foo.tar.bz2 and foo.diff
|
||||||
#
|
#
|
||||||
# The archive contains a copy of the diff, so the extra diff file
|
# The archive contains a copy of the diff, so the extra diff file
|
||||||
# shouldn't be sumitted. It's only left for convenience.
|
# shouldn't be submitted. It's only left for (in?)convenience.
|
||||||
|
|
||||||
SELF=$(basename $0)
|
SELF=${0/#*\/}
|
||||||
AIRCRAFT=$(basename $PWD)
|
AIRCRAFT=${PWD/#*\/}
|
||||||
|
|
||||||
CVS=/usr/bin/cvs
|
CVS=/usr/bin/cvs
|
||||||
ARCHIVE=$AIRCRAFT.tar.bz2
|
ARCHIVE=$AIRCRAFT.tar.bz2
|
||||||
DIFF=$AIRCRAFT.diff
|
DIFF=$AIRCRAFT.diff
|
||||||
|
CDIFF=$DIFF.bz2
|
||||||
|
|
||||||
|
|
||||||
function ERROR { echo -e "\e[31;1m$*\e[m"; }
|
function ERROR { echo -e "\e[31;1m$*\e[m"; }
|
||||||
function LOG { echo -e "\e[35m$*\e[m"; }
|
function LOG { echo -e "\e[35m$*\e[m"; }
|
||||||
function ADD { echo -e "\e[32m\t+ $*\e[m"; }
|
function NEW { echo -e "\e[32m\t+ $*\e[m"; }
|
||||||
|
function CHANGED { echo -e "\e[36m\t+ $*\e[m"; }
|
||||||
function REJECT { echo -e "\e[31m\t- $*\e[m"; }
|
function REJECT { echo -e "\e[31m\t- $*\e[m"; }
|
||||||
|
|
||||||
function diffstat {
|
function diffstat {
|
||||||
# output diff statistics, similar to the "diffstat" utility
|
# output diff statistics, similar to the "diffstat" utility
|
||||||
awk '
|
awk '
|
||||||
|
function line(a, r, c, f) {
|
||||||
|
print "\t\033[32m"a"\033[m\t\033[31m"r"\033[m\t\033[34m"c"\033[m\t"f
|
||||||
|
}
|
||||||
function dofile() {
|
function dofile() {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
if (bin) {
|
if (bin) {
|
||||||
print "\t\tbinary\t\t"file;
|
line("\033[m. . . .", "\033[mbinary", "\033[m. . . .", file)
|
||||||
} else {
|
} else {
|
||||||
print "\t+"a"\t-"r"\t!"c"\t"file
|
line(a, r, c, file)
|
||||||
at += a; rt += r; ct += c;
|
at += a; rt += r; ct += c;
|
||||||
}
|
}
|
||||||
a = r = c = 0;
|
a = r = c = 0
|
||||||
}
|
}
|
||||||
BEGIN {
|
BEGIN {
|
||||||
print "\tadded___removed_changed___________________________________";
|
print "\tadded---removed-changed----------------------------------------"
|
||||||
a = r = c = at = rt = ct = n = bin = 0;
|
a = r = c = at = rt = ct = n = bin = 0
|
||||||
}
|
}
|
||||||
/^Index: / { dofile(); scan = bin = 0; file = $2; n += 1; next }
|
/^Index: / { dofile(); scan = bin = 0; file = $2; n += 1; next }
|
||||||
/^@@/ { scan = 1; next }
|
/^@@/ { scan = 1; next }
|
||||||
|
@ -52,11 +57,11 @@ function diffstat {
|
||||||
/^-/ { if (scan) { r += 1 } next }
|
/^-/ { if (scan) { r += 1 } next }
|
||||||
/^!/ { if (scan) { c += 1 } next }
|
/^!/ { if (scan) { c += 1 } next }
|
||||||
END {
|
END {
|
||||||
dofile();
|
dofile()
|
||||||
print "\t-----------------------------------total------------------";
|
print "\t----------------------------------------total------------------"
|
||||||
print "\t+"at"\t-"rt"\t!"ct"\tin "n" files"
|
line(at, rt, ct, "\033[min "n" files")
|
||||||
}
|
}
|
||||||
' < $1
|
' <$1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,12 +70,13 @@ TMP=$(mktemp -d -t $SELF.$AIRCRAFT.XXX) || (echo "$0: can't create temporary dir
|
||||||
trap "rm -rf $TMP" 0 1 2 3 13 15
|
trap "rm -rf $TMP" 0 1 2 3 13 15
|
||||||
|
|
||||||
|
|
||||||
# move older archive or diff file out of the way
|
# move older archive or diff files out of the way
|
||||||
[ -f $DIFF ] && mv $DIFF $(mktemp $DIFF.X)
|
[ -f $DIFF ] && mv $DIFF $(mktemp $DIFF.X)
|
||||||
|
[ -f $CDIFF ] && mv $CDIFF $(mktemp $CDIFF.X)
|
||||||
[ -f $ARCHIVE ] && mv $ARCHIVE $(mktemp $ARCHIVE.X)
|
[ -f $ARCHIVE ] && mv $ARCHIVE $(mktemp $ARCHIVE.X)
|
||||||
|
|
||||||
|
|
||||||
LOG "updating and checking for changed and new files ..."
|
LOG "updating and checking for new files ..."
|
||||||
$CVS -q up -dP >$TMP/up
|
$CVS -q up -dP >$TMP/up
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,37 +91,36 @@ LOG "making diff ..."
|
||||||
if ! $CVS -q diff -up >$DIFF; then
|
if ! $CVS -q diff -up >$DIFF; then
|
||||||
LOG "diff statistics:"
|
LOG "diff statistics:"
|
||||||
diffstat $DIFF
|
diffstat $DIFF
|
||||||
|
echo
|
||||||
|
|
||||||
# add diff file itself
|
# add diff file itself
|
||||||
echo $DIFF >>$TMP/include
|
echo $DIFF >>$TMP/files
|
||||||
|
|
||||||
# add changed binary files
|
# add changed binary files
|
||||||
awk '
|
awk '
|
||||||
/^Index: / { scan = 1; file = $2 }
|
/^Index: / { scan = 1; file = $2; next }
|
||||||
/^@@/ { scan = 0 }
|
/^@@/ { scan = 0; next }
|
||||||
/^Binary/ { if (scan) { print file } }
|
/^Binary/ { if (scan) { print file } }
|
||||||
' <$DIFF >>$TMP/include
|
' <$DIFF >>$TMP/files
|
||||||
else
|
else
|
||||||
rm -f $DIFF
|
rm -f $DIFF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# write list of all files to add
|
LOG "checking for files to submit ..."
|
||||||
LOG "adding to archive ..."
|
if [ -f $TMP/files ]; then
|
||||||
if [ -f $TMP/include ]; then
|
cat $TMP/files|while read i; do
|
||||||
cat $TMP/include|while read i; do
|
CHANGED "$i"
|
||||||
ADD "$i"
|
|
||||||
echo $i >>$TMP/files
|
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
grep "^? " $TMP/up|while read i; do
|
grep "^? " $TMP/up|while read i; do
|
||||||
find ${i#? } -type f >>$TMP/files
|
find ${i#? } -type f >>$TMP/check
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# classify and filter files
|
# classify and filter files
|
||||||
if [ -f $TMP/files ]; then
|
if [ -f $TMP/check ]; then
|
||||||
for i in $(cat $TMP/files); do
|
for i in $(cat $TMP/check); do
|
||||||
case "$i" in
|
case "$i" in
|
||||||
$ARCHIVE*|$DIFF*) # don't add files generated by the script
|
$ARCHIVE*|$DIFF*) # don't add files generated by the script
|
||||||
;;
|
;;
|
||||||
|
@ -134,19 +139,29 @@ if [ -f $TMP/files ]; then
|
||||||
REJECT "$i\t\t(graphics file)"
|
REJECT "$i\t\t(graphics file)"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
ADD "$i"
|
NEW "$i"
|
||||||
echo "$i" >>$TMP/include
|
echo "$i" >>$TMP/files
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ -f $TMP/include ]; then
|
if ! [ -f $TMP/files ]; then
|
||||||
LOG "creating archive $ARCHIVE"
|
LOG "no changed or new files found"
|
||||||
tar -cjf $ARCHIVE --files-from $TMP/include
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
numfiles=$(awk '//{n+=1}END{print n}' <$TMP/files)
|
||||||
|
if [ -f $DIFF -a $numfiles == 1 ]; then
|
||||||
|
LOG "only changed non-binary files found"
|
||||||
|
LOG "creating compressed diff \e[1;37;40m$CDIFF\e[m\e[35m ..."
|
||||||
|
bzip2 -k $DIFF
|
||||||
else
|
else
|
||||||
LOG "no changed or new files detected"
|
LOG "changed and/or new files found"
|
||||||
|
LOG "creating archive \e[1;37;40m$ARCHIVE\e[m\e[35m ..."
|
||||||
|
tar -cjf $ARCHIVE --files-from $TMP/files
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue