3 # This script called in a CVS directory generates an archive in that
4 # same directory, which contains all locally added new files (except
5 # those rejected by the script) and a diff with all local changes.
6 # This archive can then be offered to one of the CVS maintainers for
10 # $ cd $FG_ROOT/Aircraft/foo
11 # $ fg-submit # generates foo.tar.bz2 and foo.diff
13 # The archive contains a copy of the diff, so the extra diff file
14 # shouldn't be submitted. It's only left for (in?)convenience.
20 ARCHIVE=$AIRCRAFT.tar.bz2
25 function ERROR { echo -e "\e[31;1m$*\e[m"; }
26 function LOG { echo -e "\e[35m$*\e[m"; }
27 function NEW { echo -e "\e[32m\t+ $*\e[m"; }
28 function CHANGED { echo -e "\e[36m\t+ $*\e[m"; }
29 function REJECT { echo -e "\e[31m\t- $*\e[m"; }
32 # output diff statistics, similar to the "diffstat" utility
34 function line(a, r, c, f) {
35 print "\t\033[32m"a"\033[m\t\033[31m"r"\033[m\t\033[34m"c"\033[m\t"f
42 line("\033[m. . . .", "\033[mbinary", "\033[m. . . .", file)
45 at += a; rt += r; ct += c;
50 print "\tadded---removed-changed----------------------------------------"
51 a = r = c = at = rt = ct = n = bin = 0
53 /^Index: / { dofile(); scan = bin = 0; file = $2; n += 1; next }
54 /^@@/ { scan = 1; next }
55 /^Binary/ { if (!scan) { bin = 1 } next }
56 /^+/ { if (scan) { a += 1 } next }
57 /^-/ { if (scan) { r += 1 } next }
58 /^!/ { if (scan) { c += 1 } next }
61 print "\t----------------------------------------total------------------"
62 line(at, rt, ct, "\033[min "n" files")
68 # create temporary dir that's automatcally removed on exit
69 TMP=$(mktemp -d -t $SELF.$AIRCRAFT.XXX) || (echo "$0: can't create temporary dir"; exit 1)
70 trap "rm -rf $TMP" 0 1 2 3 13 15
73 # move older archive or diff files out of the way
74 [ -f $DIFF ] && mv $DIFF $(mktemp $DIFF.X)
75 [ -f $CDIFF ] && mv $CDIFF $(mktemp $CDIFF.X)
76 [ -f $ARCHIVE ] && mv $ARCHIVE $(mktemp $ARCHIVE.X)
79 LOG "updating and checking for new files ..."
80 $CVS -q up -dP >$TMP/up
83 if grep "^C " $TMP/up &>/dev/null; then
84 ERROR "there are conflicts with the following files:"
91 if ! $CVS -q diff -up >$DIFF; then
92 LOG "diff statistics:"
96 # add diff file itself
97 echo $DIFF >>$TMP/files
99 # add changed binary files
101 /^Index: / { scan = 1; file = $2; next }
102 /^@@/ { scan = 0; next }
103 /^Binary/ { if (scan) { print file } }
104 ' <$DIFF >>$TMP/files
110 LOG "checking for files to submit ..."
111 if [ -f $TMP/files ]; then
112 cat $TMP/files|while read i; do
116 grep "^? " $TMP/up|while read i; do
117 find ${i#? } -type f >>$TMP/check
121 # classify and filter files
122 if [ -f $TMP/check ]; then
123 for i in $(cat $TMP/check); do
125 $ARCHIVE*|$DIFF*) # don't add files generated by the script
127 */.*|.*) # silently drop hidden files
130 REJECT "$i\t\t(backup file)"
133 REJECT "$i\t\t(CVS file)"
135 *.blend|*.blend[0-9]|*.blend[0-9][0-9])
136 REJECT "$i\t\t(blender file)"
138 *.xcf|*.tga|*.bmp|*.BMP|*.png)
139 REJECT "$i\t\t(graphics file)"
143 echo "$i" >>$TMP/files
150 if ! [ -f $TMP/files ]; then
151 LOG "no changed or new files found"
156 numfiles=$(awk '//{n+=1}END{print n}' <$TMP/files)
157 if [ -f $DIFF -a $numfiles == 1 ]; then
158 LOG "only changed non-binary files found"
159 LOG "creating compressed diff \e[1;37;40m$CDIFF\e[m\e[35m ..."
162 LOG "changed and/or new files found"
163 LOG "creating archive \e[1;37;40m$ARCHIVE\e[m\e[35m ..."
164 tar -cjf $ARCHIVE --files-from $TMP/files