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, which is only left for
14 # convenience and doesn't have to be submitted.
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
34 print "\t\tbinary\t\t"file;
36 print "\t+"a"\t-"r"\t!"c"\t"file
40 print "\tadded___removed_changed___________________________________";
41 a = r = c = at = rt = ct = n = bin = 0;
43 /^Index: / { if (file) { out() } a = r = c = scan = bin = 0; file = $2; n += 1 }
45 /^Binary/ { if (!scan) { bin = 1 } }
46 /^+/ { if (scan) { a += 1; at += 1 } }
47 /^-/ { if (scan) { r += 1; rt += 1 } }
48 /^!/ { if (scan) { c += 1; ct += 1 } }
51 print "\t-----------------------------------total------------------";
52 print "\t+"at"\t-"rt"\t!"ct"\tin "n" files"
58 # create temporary dir that's automatcally removed on exit
59 TMP=$(mktemp -d /tmp/$SELF.$AIRCRAFT.XXXXXX) || (echo "$0: can't create temporary dir"; exit 1)
60 trap "rm -rf $TMP" 0 1 2 3 13 15
63 # move older archive or diff file out of the way
64 [ -f $DIFF ] && mv -i $DIFF $DIFF~
65 [ -f $ARCHIVE ] && mv -i $ARCHIVE $ARCHIVE~
68 LOG "updating and checking for changed and new files ..."
69 $CVS -q up -dP >$TMP/up
72 if grep "^C " $TMP/up &>/dev/null; then
73 ERROR "there are conflicts with the following files:"
80 if ! $CVS -q diff -up >$DIFF; then
81 LOG "diff statistics:"
84 # add diff file itself
85 echo $DIFF >> $TMP/include
87 # add changed binary files
89 /^Index: / { scan = 1; file = $2 }
91 /^Binary/ { if (scan) { print file } }
92 ' < $DIFF >>$TMP/include
98 # write list of all files to add
99 LOG "adding to archive ..."
100 if [ -f $TMP/include ]; then
101 cat $TMP/include|while read i; do
103 echo $i >> $TMP/files
106 grep "^? " $TMP/up|while read i; do
108 find $FILE -type f >> $TMP/files
112 # classify and filter files
113 if [ -f $TMP/files ]; then
114 for FILE in $(cat $TMP/files); do
116 $ARCHIVE*|$DIFF*) # don't add files generated by the script
118 */.*|.*) # silently drop hidden files
121 REJECT "$FILE\t\t(backup file)"
124 REJECT "$FILE\t\t(CVS file)"
126 *.blend|*.blend[0-9]|*.blend[0-9][0-9])
127 REJECT "$FILE\t\t(blender file)"
129 *.xcf|*.tga|*.bmp|*.BMP|*.png)
130 REJECT "$FILE\t\t(graphics file)"
134 echo "$FILE" >> $TMP/include
141 if [ -f $TMP/include ]; then
142 LOG "creating archive $ARCHIVE"
143 tar -cjf $ARCHIVE --files-from $TMP/include
145 LOG "no changes or new files detected"