]> git.mxchange.org Git - flightgear.git/blob - scripts/tools/fg-submit
make unified diff
[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, which is only left for
14 # convenience and doesn't have to be submitted.
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 out() {
33                         if (bin) {
34                                 print "\t\tbinary\t\t"file;
35                         } else {
36                                 print "\t+"a"\t-"r"\t!"c"\t"file
37                         }
38                 }
39                 BEGIN      {
40                         print "\tadded___removed_changed___________________________________";
41                         a = r = c = at = rt = ct = n = bin = 0;
42                 }
43                 /^Index: / { if (file) { out() } a = r = c = scan = bin = 0; file = $2; n += 1 }
44                 /^@@/      { scan = 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 } }
49                 END        {
50                         if (file) { out() }
51                         print "\t-----------------------------------total------------------";
52                         print "\t+"at"\t-"rt"\t!"ct"\tin "n" files"
53                 }
54         ' < $1
55 }
56
57
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
61
62
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~
66
67
68 LOG "updating and checking for changed and new files ..."
69 $CVS -q up -dP >$TMP/up
70
71
72 if grep "^C " $TMP/up &>/dev/null; then
73         ERROR "there are conflicts with the following files:"
74         grep "^C " $TMP/up
75         exit 1
76 fi
77
78
79 LOG "making diff ..."
80 if ! $CVS -q diff -up >$DIFF; then
81         LOG "diff statistics:"
82         diffstat $DIFF
83
84         # add diff file itself
85         echo $DIFF >> $TMP/include
86
87         # add changed binary files
88         awk '
89                 /^Index: / { scan = 1; file = $2 }
90                 /^@@/      { scan = 0 }
91                 /^Binary/  { if (scan) { print file } }
92         ' < $DIFF >>$TMP/include
93 else
94         rm -f $DIFF
95 fi
96
97
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
102                 ADD "$i"
103                 echo $i >> $TMP/files
104         done
105 fi
106 grep "^? " $TMP/up|while read i; do
107         FILE=${i#? }
108         find $FILE -type f >> $TMP/files
109 done
110
111
112 # classify and filter files
113 if [ -f $TMP/files ]; then
114         for FILE in $(cat $TMP/files); do
115                 case "$FILE" in
116                 $ARCHIVE*|$DIFF*) # don't add files generated by the script
117                         ;;
118                 */.*|.*)          # silently drop hidden files
119                         ;;
120                 *~|*.bak|*.orig|*..)
121                         REJECT "$FILE\t\t(backup file)"
122                         ;;
123                 *CVS/*)
124                         REJECT "$FILE\t\t(CVS file)"
125                         ;;
126                 *.blend|*.blend[0-9]|*.blend[0-9][0-9])
127                         REJECT "$FILE\t\t(blender file)"
128                         ;;
129                 *.xcf|*.tga|*.bmp|*.BMP|*.png)
130                         REJECT "$FILE\t\t(graphics file)"
131                         ;;
132                 *)
133                         ADD "$FILE"
134                         echo "$FILE" >> $TMP/include
135                         ;;
136                 esac
137         done
138 fi
139
140
141 if [ -f $TMP/include ]; then
142         LOG "creating archive $ARCHIVE"
143         tar -cjf $ARCHIVE --files-from $TMP/include
144 else
145         LOG "no changes or new files detected"
146 fi
147 exit 0
148