]> git.mxchange.org Git - flightgear.git/blob - scripts/tools/fg-submit
- add fg-check script; Can be used to check source/data before committing or
[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 submitted. It's only left for (in?)convenience.
15
16 SELF=${0/#*\/}
17 AIRCRAFT=${PWD/#*\/}
18
19 CVS=/usr/bin/cvs
20 ARCHIVE=$AIRCRAFT.tar.bz2
21 DIFF=$AIRCRAFT.diff
22 CDIFF=$DIFF.bz2
23
24
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"; }
30
31 function diffstat {
32         # output diff statistics, similar to the "diffstat" utility
33         awk '
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
36                 }
37                 function dofile() {
38                         if (!file) {
39                                 return
40                         }
41                         if (bin) {
42                                 line("\033[m. . . .", "\033[mbinary", "\033[m. . . .", file)
43                         } else {
44                                 line(a, r, c, file)
45                                 at += a; rt += r; ct += c;
46                         }
47                         a = r = c = 0
48                 }
49                 BEGIN      {
50                         print "\tadded---removed-changed----------------------------------------"
51                         a = r = c = at = rt = ct = n = bin = 0
52                 }
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 }
59                 END        {
60                         dofile()
61                         print "\t----------------------------------------total------------------"
62                         line(at, rt, ct, "\033[min "n" files")
63                 }
64         ' <$1
65 }
66
67
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
71
72
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)
77
78
79 LOG "updating and checking for new files ..."
80 $CVS -q up -dP >$TMP/up
81
82
83 if grep "^C " $TMP/up &>/dev/null; then
84         ERROR "there are conflicts with the following files:"
85         grep "^C " $TMP/up
86         exit 1
87 fi
88
89
90 LOG "making diff ..."
91 if ! $CVS -q diff -up >$DIFF; then
92         LOG "diff statistics:"
93         diffstat $DIFF
94         echo
95
96         # add diff file itself
97         echo $DIFF >>$TMP/files
98
99         # add changed binary files
100         awk '
101                 /^Index: / { scan = 1; file = $2; next }
102                 /^@@/      { scan = 0; next }
103                 /^Binary/  { if (scan) { print file } }
104         ' <$DIFF >>$TMP/files
105 else
106         rm -f $DIFF
107 fi
108
109
110 LOG "checking for files to submit ..."
111 if [ -f $TMP/files ]; then
112         cat $TMP/files|while read i; do
113                 CHANGED "$i"
114         done
115 fi
116 grep "^? " $TMP/up|while read i; do
117         find ${i#? } -type f >>$TMP/check
118 done
119
120
121 # classify and filter files
122 if [ -f $TMP/check ]; then
123         for i in $(cat $TMP/check); do
124                 case "$i" in
125                 $ARCHIVE*|$DIFF*) # don't add files generated by the script
126                         ;;
127                 */.*|.*)          # silently drop hidden files
128                         ;;
129                 *~|*.|*.bak|*.orig)
130                         REJECT "$i\t\t(backup file)"
131                         ;;
132                 CVS/*|*/CVS/*)
133                         REJECT "$i\t\t(CVS file)"
134                         ;;
135                 *.blend|*.blend[0-9]|*.blend[0-9][0-9])
136                         REJECT "$i\t\t(blender file)"
137                         ;;
138                 *.xcf|*.tga|*.bmp|*.BMP|*.png)
139                         REJECT "$i\t\t(graphics file)"
140                         ;;
141                 *)
142                         NEW "$i"
143                         echo "$i" >>$TMP/files
144                         ;;
145                 esac
146         done
147 fi
148
149
150 if ! [ -f $TMP/files ]; then
151         LOG "no changed or new files found"
152         exit 0
153 fi
154
155 echo
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 ..."
160         bzip2 -k $DIFF
161 else
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
165 fi
166 exit 0
167