2007-03-06 19:23:36 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2007-03-08 16:45:48 +00:00
|
|
|
# This script called in a CVS directory compares local files with
|
|
|
|
# the repository, and prepares an update package containing all
|
|
|
|
# changes and new files for submission to a CVS maintainer. If there
|
|
|
|
# are only changes in text files, then a compressed unified diff is
|
|
|
|
# made (foo.diff.bz2). If there are also changed binary or new files,
|
|
|
|
# then an archive is made instead (foo.tar.bz2). The base name ("foo")
|
|
|
|
# can be given as command line argument. Otherwise the directory name
|
|
|
|
# is used. The script also leaves a diff in uncompressed/unpackaged
|
|
|
|
# form. This is only for developer convenience -- for a quick check
|
|
|
|
# of the diff correctness. It is not to be submitted. The script will
|
|
|
|
# not overwrite any file, but rather rename conflicting files.
|
2007-03-06 19:23:36 +00:00
|
|
|
#
|
2007-03-08 16:45:48 +00:00
|
|
|
# Usage: fg-submit [<basename>]
|
2007-03-06 19:23:36 +00:00
|
|
|
#
|
2007-03-08 16:45:48 +00:00
|
|
|
# Example:
|
|
|
|
# $ cd $FG_ROOT/Aircraft/bo105
|
|
|
|
# $ fg-submit # -> bo105.diff.bz2 or bo105.tar.bz2
|
|
|
|
#
|
|
|
|
# $ fg-submit update # -> update.diff.bz2 or update.tar.bz2
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Spaces in the basename are replaced with "%20". People who prefer
|
|
|
|
# to have the date in the archive name can conveniently achieve this
|
|
|
|
# by defining a shell alias in ~/.bashrc:
|
|
|
|
#
|
|
|
|
# alias submit='fg-submit "${PWD/#*\/}-$(date +%Y-%m-%d)"'
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# If the script finds an application named "fg-upload", then it calls
|
|
|
|
# this at the end with three arguments:
|
|
|
|
#
|
|
|
|
# $1 ... working directory ($PWD)
|
|
|
|
# $2 ... archive or compressed diff for submission
|
|
|
|
# $3 ... accessory diff, *NOT* for submission!
|
|
|
|
#
|
|
|
|
# $2 and $3 are guaranteed not to contain spaces, only $1 is guaranteed
|
|
|
|
# to actually exist. Such as script can be used to upload the file to an
|
|
|
|
# ftp-/webserver, and/or to remove one or both files. Example using
|
|
|
|
# KDE's kfmclient for upload (alternatives: ncftpput, gnomevfs-copy, ...):
|
|
|
|
#
|
|
|
|
# $ cat ~/bin/fg-upload
|
|
|
|
# #!/bin/bash
|
|
|
|
# echo "uploading $2"
|
|
|
|
# if kfmclient copy $2 ftp://user:password@server.com; then
|
|
|
|
# echo "deleting $2 $3"
|
|
|
|
# rm -rf $2 $3
|
|
|
|
#
|
|
|
|
# echo "Done. URL: ftp://server.com/$2"
|
|
|
|
# else
|
|
|
|
# echo "arghh ... HELP! HELP!"
|
|
|
|
# fi
|
|
|
|
|
2007-03-06 19:23:36 +00:00
|
|
|
|
2007-03-07 16:26:33 +00:00
|
|
|
SELF=${0/#*\/}
|
2007-03-08 16:45:48 +00:00
|
|
|
DIR=${PWD/#*\/}
|
|
|
|
BASE=${1:-$DIR}
|
|
|
|
BASE=${BASE// /%20}
|
|
|
|
|
|
|
|
CVS=/usr/bin/cvs # avoid colorcvs wrapper from
|
|
|
|
[ -x $CVS ] || CVS=cvs # http://www.hakubi.us/colorcvs/
|
|
|
|
UPLOAD=$(which fg-upload 2>/dev/null)
|
2007-03-06 19:23:36 +00:00
|
|
|
|
2007-03-08 16:45:48 +00:00
|
|
|
ARCHIVE=$BASE.tar.bz2
|
|
|
|
DIFF=$BASE.diff
|
2007-03-07 16:26:33 +00:00
|
|
|
CDIFF=$DIFF.bz2
|
2007-03-06 19:23:36 +00:00
|
|
|
|
|
|
|
|
2007-03-07 16:26:33 +00:00
|
|
|
function ERROR { echo -e "\e[31;1m$*\e[m"; }
|
|
|
|
function LOG { echo -e "\e[35m$*\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"; }
|
2007-03-06 19:23:36 +00:00
|
|
|
|
|
|
|
function diffstat {
|
|
|
|
# output diff statistics, similar to the "diffstat" utility
|
|
|
|
awk '
|
2007-03-07 16:26:33 +00:00
|
|
|
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
|
|
|
|
}
|
2007-03-06 21:23:26 +00:00
|
|
|
function dofile() {
|
|
|
|
if (!file) {
|
2007-03-07 16:26:33 +00:00
|
|
|
return
|
2007-03-06 21:23:26 +00:00
|
|
|
}
|
2007-03-06 19:23:36 +00:00
|
|
|
if (bin) {
|
2007-03-08 16:45:48 +00:00
|
|
|
print "\t. . . . binary . . . . \033[36m"file"\033[m"
|
2007-03-06 19:23:36 +00:00
|
|
|
} else {
|
2007-03-07 16:26:33 +00:00
|
|
|
line(a, r, c, file)
|
2007-03-08 16:45:48 +00:00
|
|
|
at += a; rt += r; ct += c
|
2007-03-06 19:23:36 +00:00
|
|
|
}
|
2007-03-07 16:26:33 +00:00
|
|
|
a = r = c = 0
|
2007-03-06 19:23:36 +00:00
|
|
|
}
|
|
|
|
BEGIN {
|
2007-03-07 16:26:33 +00:00
|
|
|
print "\tadded---removed-changed----------------------------------------"
|
|
|
|
a = r = c = at = rt = ct = n = bin = 0
|
2007-03-06 19:23:36 +00:00
|
|
|
}
|
2007-03-08 16:45:48 +00:00
|
|
|
/^Index: / { dofile(); scan = bin = 0; file = $2; n++; next }
|
2007-03-06 21:23:26 +00:00
|
|
|
/^@@/ { scan = 1; next }
|
2007-03-08 16:45:48 +00:00
|
|
|
/^Binary/ { if (!scan) bin = 1; next }
|
|
|
|
/^+/ { if (scan) a++; next }
|
|
|
|
/^-/ { if (scan) r++; next }
|
|
|
|
/^!/ { if (scan) c++; next }
|
2007-03-06 19:23:36 +00:00
|
|
|
END {
|
2007-03-07 16:26:33 +00:00
|
|
|
dofile()
|
|
|
|
print "\t----------------------------------------total------------------"
|
|
|
|
line(at, rt, ct, "\033[min "n" files")
|
2007-03-06 19:23:36 +00:00
|
|
|
}
|
2007-03-07 16:26:33 +00:00
|
|
|
' <$1
|
2007-03-06 19:23:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# create temporary dir that's automatcally removed on exit
|
2007-03-08 16:45:48 +00:00
|
|
|
TMP=$(mktemp -d -t $SELF.$BASE.XXX) || (echo "$0: can't create temporary dir"; exit 1)
|
2007-03-06 19:23:36 +00:00
|
|
|
trap "rm -rf $TMP" 0 1 2 3 13 15
|
|
|
|
|
|
|
|
|
2007-03-08 16:45:48 +00:00
|
|
|
# move old files out of the way
|
|
|
|
for i in $DIFF $CDIFF $ARCHIVE; do
|
|
|
|
[ -f $i ] && mv $i $(mktemp $i.X)
|
|
|
|
done
|
2007-03-06 19:23:36 +00:00
|
|
|
|
|
|
|
|
2007-03-07 16:26:33 +00:00
|
|
|
LOG "updating and checking for new files ..."
|
2007-03-06 19:23:36 +00:00
|
|
|
$CVS -q up -dP >$TMP/up
|
|
|
|
|
|
|
|
|
|
|
|
if grep "^C " $TMP/up &>/dev/null; then
|
|
|
|
ERROR "there are conflicts with the following files:"
|
|
|
|
grep "^C " $TMP/up
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
LOG "making diff ..."
|
2007-03-06 20:35:28 +00:00
|
|
|
if ! $CVS -q diff -up >$DIFF; then
|
2007-03-06 19:23:36 +00:00
|
|
|
LOG "diff statistics:"
|
|
|
|
diffstat $DIFF
|
2007-03-07 16:26:33 +00:00
|
|
|
echo
|
2007-03-06 19:23:36 +00:00
|
|
|
|
|
|
|
# add diff file itself
|
2007-03-07 16:26:33 +00:00
|
|
|
echo $DIFF >>$TMP/files
|
2007-03-06 19:23:36 +00:00
|
|
|
|
|
|
|
# add changed binary files
|
|
|
|
awk '
|
2007-03-07 16:26:33 +00:00
|
|
|
/^Index: / { scan = 1; file = $2; next }
|
|
|
|
/^@@/ { scan = 0; next }
|
2007-03-06 19:23:36 +00:00
|
|
|
/^Binary/ { if (scan) { print file } }
|
2007-03-07 16:26:33 +00:00
|
|
|
' <$DIFF >>$TMP/files
|
2007-03-06 19:23:36 +00:00
|
|
|
else
|
|
|
|
rm -f $DIFF
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2007-03-07 16:26:33 +00:00
|
|
|
LOG "checking for files to submit ..."
|
|
|
|
if [ -f $TMP/files ]; then
|
|
|
|
cat $TMP/files|while read i; do
|
|
|
|
CHANGED "$i"
|
2007-03-06 19:23:36 +00:00
|
|
|
done
|
|
|
|
fi
|
2007-03-08 16:45:48 +00:00
|
|
|
|
2007-03-06 19:23:36 +00:00
|
|
|
grep "^? " $TMP/up|while read i; do
|
2007-03-07 16:26:33 +00:00
|
|
|
find ${i#? } -type f >>$TMP/check
|
2007-03-06 19:23:36 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# classify and filter files
|
2007-03-07 16:26:33 +00:00
|
|
|
if [ -f $TMP/check ]; then
|
|
|
|
for i in $(cat $TMP/check); do
|
2007-03-06 21:23:26 +00:00
|
|
|
case "$i" in
|
2007-03-06 19:23:36 +00:00
|
|
|
$ARCHIVE*|$DIFF*) # don't add files generated by the script
|
|
|
|
;;
|
|
|
|
*/.*|.*) # silently drop hidden files
|
|
|
|
;;
|
2007-03-06 21:23:26 +00:00
|
|
|
*~|*.|*.bak|*.orig)
|
|
|
|
REJECT "$i\t\t(backup file)"
|
2007-03-06 19:23:36 +00:00
|
|
|
;;
|
2007-03-06 21:23:26 +00:00
|
|
|
CVS/*|*/CVS/*)
|
|
|
|
REJECT "$i\t\t(CVS file)"
|
2007-03-06 19:23:36 +00:00
|
|
|
;;
|
|
|
|
*.blend|*.blend[0-9]|*.blend[0-9][0-9])
|
2007-03-06 21:23:26 +00:00
|
|
|
REJECT "$i\t\t(blender file)"
|
2007-03-06 19:23:36 +00:00
|
|
|
;;
|
|
|
|
*.xcf|*.tga|*.bmp|*.BMP|*.png)
|
2007-03-06 21:23:26 +00:00
|
|
|
REJECT "$i\t\t(graphics file)"
|
2007-03-06 19:23:36 +00:00
|
|
|
;;
|
|
|
|
*)
|
2007-03-07 16:26:33 +00:00
|
|
|
NEW "$i"
|
|
|
|
echo "$i" >>$TMP/files
|
2007-03-06 19:23:36 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2007-03-07 16:26:33 +00:00
|
|
|
if ! [ -f $TMP/files ]; then
|
|
|
|
LOG "no changed or new files found"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
2007-03-08 16:45:48 +00:00
|
|
|
numfiles=$(awk '//{n++}END{print n}' <$TMP/files)
|
2007-03-07 16:26:33 +00:00
|
|
|
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
|
2007-03-08 16:45:48 +00:00
|
|
|
RESULT=$CDIFF
|
2007-03-06 19:23:36 +00:00
|
|
|
else
|
2007-03-07 16:26:33 +00:00
|
|
|
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
|
2007-03-08 16:45:48 +00:00
|
|
|
RESULT=$ARCHIVE
|
2007-03-06 19:23:36 +00:00
|
|
|
fi
|
2007-03-08 16:45:48 +00:00
|
|
|
|
|
|
|
[ -x "$UPLOAD" -a -f $RESULT ] && $UPLOAD "$PWD" $RESULT $DIFF
|
|
|
|
|
2007-03-06 19:23:36 +00:00
|
|
|
exit 0
|
|
|
|
|