3 # This script called in a CVS directory compares local files with
4 # the repository, and prepares an update package containing all
5 # changes and new files for submission to a CVS maintainer. If there
6 # are only changes in text files, then a compressed unified diff is
7 # made (foo.diff.bz2). If there are also changed binary or new files,
8 # then an archive is made instead (foo.tar.bz2). The base name ("foo")
9 # can be given as command line argument. Otherwise the directory name
10 # is used. The script also leaves a diff in uncompressed/unpackaged
11 # form. This is only for developer convenience -- for a quick check
12 # of the diff correctness. It is not to be submitted. The script will
13 # not overwrite any file, but rather rename conflicting files.
15 # Usage: fg-submit [<basename>]
18 # $ cd $FG_ROOT/Aircraft/bo105
19 # $ fg-submit # -> bo105.diff.bz2 or bo105.tar.bz2
21 # $ fg-submit update # -> update.diff.bz2 or update.tar.bz2
24 # Spaces in the basename are replaced with "%20". People who prefer
25 # to have the date in the archive name can conveniently achieve this
26 # by defining a shell alias in ~/.bashrc:
28 # alias submit='fg-submit "${PWD/#*\/}-$(date +%Y-%m-%d)"'
31 # If the script finds an application named "fg-upload", then it calls
32 # this at the end with two arguments:
34 # $1 ... archive or compressed diff for submission
35 # $2 ... accessory diff, *NOT* for submission!
37 # $1 and $2 are guaranteed not to contain spaces, only $1 is guaranteed
38 # to actually exist. Such as script can be used to upload the file to an
39 # ftp-/webserver, and/or to remove one or both files. Example using
40 # KDE's kfmclient for upload (alternatives: ncftpput, gnomevfs-copy, wput):
42 # $ cat ~/bin/fg-upload
45 # if kfmclient copy $1 ftp://user:password@server.com; then
46 # echo "deleting $1 $2"
49 # echo "Done. URL: ftp://server.com/$1"
51 # echo "arghh ... HELP! HELP!"
60 CVS=/usr/bin/cvs # avoid colorcvs wrapper from
61 [ -x $CVS ] || CVS=cvs # http://www.hakubi.us/colorcvs/
62 UPLOAD=$(which fg-upload 2>/dev/null)
69 function ERROR { echo -e "\e[31;1m$*\e[m"; }
70 function LOG { echo -e "\e[35m$*\e[m"; }
71 function NEW { echo -e "\e[32m\t+ $*\e[m"; }
72 function CHANGED { echo -e "\e[36m\t+ $*\e[m"; }
73 function REJECT { echo -e "\e[31m\t- $*\e[m"; }
76 # output diff statistics, similar to the "diffstat" utility
78 function line(a, r, c, f) {
79 print "\t\033[32m"a"\033[m\t\033[31m"r"\033[m\t\033[34m"c"\033[m\t"f
86 print "\t. . . . binary . . . . \033[36m"file"\033[m"
89 at += a; rt += r; ct += c
94 print "\tadded---removed-changed----------------------------------------"
95 a = r = c = at = rt = ct = n = bin = 0
97 /^Index: / { dofile(); scan = bin = 0; file = $2; n++; next }
98 /^@@/ { scan = 1; next }
99 /^Binary/ { if (!scan) bin = 1; next }
100 /^\+/ { if (scan) a++; next }
101 /^-/ { if (scan) r++; next }
102 /^!/ { if (scan) c++; next }
105 print "\t----------------------------------------total------------------"
106 line(at, rt, ct, "\033[min "n" files")
112 # create temporary dir that's automatically removed on exit
113 TMP=$(mktemp -d /tmp/$SELF.$BASE.XXXXXX) || (echo "$0: can't create temporary dir"; exit 1)
114 trap "rm -rf $TMP" 0 1 2 3 13 15
117 # move old files out of the way
118 for i in $DIFF $CDIFF $ARCHIVE; do
119 [ -f $i ] && mv $i $(mktemp $i.XXXXXX)
123 LOG "updating and checking for new files ..."
124 $CVS -q up -dP >$TMP/up
127 if grep "^C " $TMP/up &>/dev/null; then
128 ERROR "there are conflicts with the following files:"
134 LOG "making diff ..."
135 if ! $CVS -q diff -up >$DIFF; then
136 LOG "diff statistics:"
140 # add diff file itself
141 echo $DIFF >>$TMP/files
143 # add changed binary files
145 /^Index: / { scan = 1; file = $2; next }
146 /^@@/ { scan = 0; next }
147 /^Binary/ { if (scan) { print file } }
148 ' <$DIFF >>$TMP/files
154 LOG "checking for files to submit ..."
155 if [ -f $TMP/files ]; then
156 cat $TMP/files|while read i; do
161 grep "^? " $TMP/up|while read i; do
162 find ${i#? } -type f >>$TMP/check
166 # classify and filter files
167 if [ -f $TMP/check ]; then
168 for i in $(cat $TMP/check); do
170 $ARCHIVE*|$DIFF*) # don't add files generated by the script
172 */.*|.*) # silently drop hidden files
175 REJECT "$i\t\t(backup file)"
178 REJECT "$i\t\t(CVS file)"
180 *.tar.gz*|*.tar.bz2*|*.tgz|*.zip)
181 REJECT "$i\t\t(archive)"
183 *.blend|*.blend[0-9]|*.blend[0-9][0-9])
184 REJECT "$i\t\t(blender file)"
186 *.xcf|*.tga|*.bmp|*.BMP|*.png)
187 REJECT "$i\t\t(graphics file)"
191 echo "$i" >>$TMP/files
198 if ! [ -f $TMP/files ]; then
199 LOG "no changed or new files found"
204 numfiles=$(awk '//{n++}END{print n}' <$TMP/files)
205 if [ -f $DIFF -a $numfiles == 1 ]; then
206 LOG "only changed non-binary files found"
207 LOG "creating compressed diff \e[1;37;40m$CDIFF\e[m\e[35m ..."
211 LOG "changed and/or new files found"
212 LOG "creating archive \e[1;37;40m$ARCHIVE\e[m\e[35m ..."
213 tar -cjf $ARCHIVE --files-from $TMP/files
217 [ -x "$UPLOAD" -a -f $RESULT ] && $UPLOAD "$PWD" $RESULT $DIFF