]> git.mxchange.org Git - flightgear.git/blob - scripts/tools/fg-submit
f113f6b6db811356041d43fb54b62d0237214c5b
[flightgear.git] / scripts / tools / fg-submit
1 #!/bin/bash
2 #
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
7 # committing.
8 #
9 # Usage:
10 #         $ cd $FG_ROOT/Aircraft/foo
11 #         $ fg-submit      # generates foo.tar.bz2 and foo.diff
12 #
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.
15
16 SELF=$(basename $0)
17 AIRCRAFT=$(basename $PWD)
18
19 CVS=/usr/bin/cvs
20 ARCHIVE=$AIRCRAFT.tar.bz2
21 DIFF=$AIRCRAFT.diff
22
23
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"; }
28
29 function diffstat {
30         # output diff statistics, similar to the "diffstat" utility
31         awk '
32                 function dofile() {
33                         if (!file) {
34                                 return;
35                         }
36                         if (bin) {
37                                 print "\t\tbinary\t\t"file;
38                         } else {
39                                 print "\t+"a"\t-"r"\t!"c"\t"file
40                                 at += a; rt += r; ct += c;
41                         }
42                         a = r = c = 0;
43                 }
44                 BEGIN      {
45                         print "\tadded___removed_changed___________________________________";
46                         a = r = c = at = rt = ct = n = bin = 0;
47                 }
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 }
54                 END        {
55                         dofile();
56                         print "\t-----------------------------------total------------------";
57                         print "\t+"at"\t-"rt"\t!"ct"\tin "n" files"
58                 }
59         ' < $1
60 }
61
62
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
66
67
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)
71
72
73 LOG "updating and checking for changed and new files ..."
74 $CVS -q up -dP >$TMP/up
75
76
77 if grep "^C " $TMP/up &>/dev/null; then
78         ERROR "there are conflicts with the following files:"
79         grep "^C " $TMP/up
80         exit 1
81 fi
82
83
84 LOG "making diff ..."
85 if ! $CVS -q diff -up >$DIFF; then
86         LOG "diff statistics:"
87         diffstat $DIFF
88
89         # add diff file itself
90         echo $DIFF >>$TMP/include
91
92         # add changed binary files
93         awk '
94                 /^Index: / { scan = 1; file = $2 }
95                 /^@@/      { scan = 0 }
96                 /^Binary/  { if (scan) { print file } }
97         ' <$DIFF >>$TMP/include
98 else
99         rm -f $DIFF
100 fi
101
102
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
107                 ADD "$i"
108                 echo $i >>$TMP/files
109         done
110 fi
111 grep "^? " $TMP/up|while read i; do
112         find ${i#? } -type f >>$TMP/files
113 done
114
115
116 # classify and filter files
117 if [ -f $TMP/files ]; then
118         for i in $(cat $TMP/files); do
119                 case "$i" in
120                 $ARCHIVE*|$DIFF*) # don't add files generated by the script
121                         ;;
122                 */.*|.*)          # silently drop hidden files
123                         ;;
124                 *~|*.|*.bak|*.orig)
125                         REJECT "$i\t\t(backup file)"
126                         ;;
127                 CVS/*|*/CVS/*)
128                         REJECT "$i\t\t(CVS file)"
129                         ;;
130                 *.blend|*.blend[0-9]|*.blend[0-9][0-9])
131                         REJECT "$i\t\t(blender file)"
132                         ;;
133                 *.xcf|*.tga|*.bmp|*.BMP|*.png)
134                         REJECT "$i\t\t(graphics file)"
135                         ;;
136                 *)
137                         ADD "$i"
138                         echo "$i" >>$TMP/include
139                         ;;
140                 esac
141         done
142 fi
143
144
145 if [ -f $TMP/include ]; then
146         LOG "creating archive $ARCHIVE"
147         tar -cjf $ARCHIVE --files-from $TMP/include
148 else
149         LOG "no changed or new files detected"
150 fi
151 exit 0
152