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 sumitted. It's only left for convenience.
17 AIRCRAFT=$(basename $PWD)
20 ARCHIVE=$AIRCRAFT.tar.bz2
24 function ERROR { echo -e "\e[31;1m$*\e[m"; }
25 function LOG { echo -e "\e[35m$*\e[m"; }
26 function ADD { echo -e "\e[32m\t+ $*\e[m"; }
27 function REJECT { echo -e "\e[31m\t- $*\e[m"; }
30 # output diff statistics, similar to the "diffstat" utility
37 print "\t\tbinary\t\t"file;
39 print "\t+"a"\t-"r"\t!"c"\t"file
40 at += a; rt += r; ct += c;
45 print "\tadded___removed_changed___________________________________";
46 a = r = c = at = rt = ct = n = bin = 0;
48 /^Index: / { dofile(); scan = bin = 0; file = $2; n += 1; next }
49 /^@@/ { scan = 1; next }
50 /^Binary/ { if (!scan) { bin = 1 } next }
51 /^+/ { if (scan) { a += 1 } next }
52 /^-/ { if (scan) { r += 1 } next }
53 /^!/ { if (scan) { c += 1 } next }
56 print "\t-----------------------------------total------------------";
57 print "\t+"at"\t-"rt"\t!"ct"\tin "n" files"
63 # create temporary dir that's automatcally removed on exit
64 TMP=$(mktemp -d -t $SELF.$AIRCRAFT.XXX) || (echo "$0: can't create temporary dir"; exit 1)
65 trap "rm -rf $TMP" 0 1 2 3 13 15
68 # move older archive or diff file out of the way
69 [ -f $DIFF ] && mv $DIFF $(mktemp $DIFF.X)
70 [ -f $ARCHIVE ] && mv $ARCHIVE $(mktemp $ARCHIVE.X)
73 LOG "updating and checking for changed and new files ..."
74 $CVS -q up -dP >$TMP/up
77 if grep "^C " $TMP/up &>/dev/null; then
78 ERROR "there are conflicts with the following files:"
85 if ! $CVS -q diff -up >$DIFF; then
86 LOG "diff statistics:"
89 # add diff file itself
90 echo $DIFF >>$TMP/include
92 # add changed binary files
94 /^Index: / { scan = 1; file = $2 }
96 /^Binary/ { if (scan) { print file } }
97 ' <$DIFF >>$TMP/include
103 # write list of all files to add
104 LOG "adding to archive ..."
105 if [ -f $TMP/include ]; then
106 cat $TMP/include|while read i; do
111 grep "^? " $TMP/up|while read i; do
112 find ${i#? } -type f >>$TMP/files
116 # classify and filter files
117 if [ -f $TMP/files ]; then
118 for i in $(cat $TMP/files); do
120 $ARCHIVE*|$DIFF*) # don't add files generated by the script
122 */.*|.*) # silently drop hidden files
125 REJECT "$i\t\t(backup file)"
128 REJECT "$i\t\t(CVS file)"
130 *.blend|*.blend[0-9]|*.blend[0-9][0-9])
131 REJECT "$i\t\t(blender file)"
133 *.xcf|*.tga|*.bmp|*.BMP|*.png)
134 REJECT "$i\t\t(graphics file)"
138 echo "$i" >>$TMP/include
145 if [ -f $TMP/include ]; then
146 LOG "creating archive $ARCHIVE"
147 tar -cjf $ARCHIVE --files-from $TMP/include
149 LOG "no changed or new files detected"