]> git.saurik.com Git - bison.git/blob - etc/clcommit
* src/reader.c (reader): #define YYLSP_NEEDED to 1 instead of just
[bison.git] / etc / clcommit
1 #! /bin/sh
2
3 # commit version 0.9.3
4
5 # Copyright (C) 1999, 2000, Free Software Foundation
6
7 # This script is Free Software, and it can be copied, distributed and
8 # modified as defined in the GNU General Public License. A copy of
9 # its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
10
11 # Originally by Gary V. Vaughan <gvaughan@oranda.demon.co.uk>
12 # Heavily modified by Alexandre Oliva <oliva@dcc.unicamp.br>
13
14 # This scripts eases checking in changes to CVS-maintained projects
15 # with ChangeLog files. It will check that there have been no
16 # conflicting commits in the CVS repository and print which files it
17 # is going to commit to stderr. A list of files to compare and to
18 # check in can be given in the command line. If it is not given, all
19 # files in the current directory (and below, unless `-l' is given) are
20 # considered for check in.
21
22 # The commit message will be extracted from the differences between a
23 # file named ChangeLog* in the commit list, or named after -C, and the
24 # one in the repository (unless a message was specified with `-m' or
25 # `-F'). An empty message is not accepted (but a blank line is). If
26 # the message is acceptable, it will be presented for verification
27 # (and possible edition) using the $PAGER environment variable (or
28 # `more', if it is not set, or `cat', if the `-f' switch is given).
29 # If $PAGER exits successfully, the modified files (at that moment)
30 # are checked in, unless `-n' was specified, in which case nothing is
31 # checked in.
32
33 # usage: commit [-v] [-h] [-f] [-l] [-n] [-q] [-z N] [-C ChangeLog_file]
34 # [-m msg|-F msg_file] [--] [file|dir ...]
35
36 # -f --fast don't check (unless *followed* by -n), and just
37 # --force display commit message instead of running $PAGER
38 # -l --local don't descend into subdirectories
39 # -m msg --message=msg set commit message
40 # --msg=msg same as -m
41 # -F file --file=file read commit message from file
42 # -C file --changelog=file extract commit message from specified ChangeLog
43 # -n --dry-run don't commit anything
44 # -q --quiet run cvs in quiet mode
45 # -zN --compress=N set compression level (0-9, 0=none, 9=max)
46 # -v --version print version information
47 # -h,-? --help print short or long help message
48
49 name=commit
50 cvsopt=
51 updateopt=
52 commitopt=
53 dry_run=false
54 commit=:
55 update=:
56 log_file="${TMPDIR-/tmp}/commitlog.$$"
57
58 rm -f "$log_file"
59 trap 'rm -f "$log_file"; exit 1' 1 2 15
60
61 # this just eases exit handling
62 main_repeat=":"
63 while $main_repeat; do
64
65 repeat="test $# -gt 0"
66 while $repeat; do
67 case "$1" in
68 -f|--force|--fast)
69 update=false
70 PAGER=cat
71 shift
72 ;;
73 -l|--local)
74 updateopt="$updateopt -l"
75 commitopt="$commitopt -l"
76 shift
77 ;;
78 -m|--message|--msg)
79 if test $# = 1; then
80 echo "$name: missing argument for $1" >&2
81 break
82 fi
83 if test -f "$log_file"; then
84 echo "$name: you can have at most one of -m and -F" >&2
85 break
86 fi
87 shift
88 echo "$1" > "$log_file"
89 shift
90 ;;
91 -F|--file)
92 if test -f "$log_file"; then
93 echo "$name: you can have at most one of -m and -F" >&2
94 break
95 fi
96 if test $# = 1; then
97 echo "$name: missing argument for $1" >&2
98 break
99 fi
100 shift
101 if cat < "$1" > "$log_file"; then :; else
102 break
103 fi
104 shift
105 ;;
106 -C|--[cC]hange[lL]og)
107 if test $# = 1; then
108 echo "$name: missing argument for $1" >&2
109 break
110 fi
111 shift
112 if test ! -f "$1"; then
113 echo "$name: ChangeLog file \`$1' does not exist" >&2
114 break
115 fi
116 ChangeLog="$1"
117 ;;
118 -n|--dry-run)
119 commit=false
120 update=true
121 shift
122 ;;
123 -q|--quiet)
124 cvsopt="$cvsopt -q"
125 shift
126 ;;
127 -z|--compress)
128 if test $# = 1; then
129 echo "$name: missing argument for $1" >&2
130 break
131 fi
132 case "$2" in
133 [0-9]) :;;
134 *) echo "$name: invalid argument for $1" >&2
135 break
136 ;;
137 esac
138 cvsopt="$cvsopt -z$2"
139 shift
140 shift
141 ;;
142
143 -m*|-F*|-C*|-z*)
144 opt=`echo "$1" | sed '1s/^\(..\).*$/\1/;q'`
145 arg=`echo "$1" | sed '1s/^-[a-zA-Z0-9]//'`
146 shift
147 set -- "$opt" "$arg" ${1+"$@"}
148 ;;
149 --message=*|--msg=*|--file=*|--[Cc]hange[Ll]og=*|--compress=*)
150 opt=`echo "$1" | sed '1s/^\(--[^=]*\)=.*/\1/;q'`
151 arg=`echo "$1" | sed '1s/^--[^=]*=//'`
152 shift
153 set -- "$opt" "$arg" ${1+"$@"}
154 ;;
155
156 -v|--version)
157 sed '/^# '$name' version /,/^# Heavily modified by/ { s/^# //; p; }; d' < $0
158 exit 0
159 ;;
160 -\?|-h)
161 sed '/^# usage:/,/# -h/ { s/^# //; p; }; d' < $0 &&
162 echo
163 echo "run \`$name --help | more' for full usage"
164 exit 0
165 ;;
166 --help)
167 sed '/^# '$name' version /,/^[^#]/ { /^[^#]/ d; s/^# //; p; }; d' < $0
168 exit 0
169 ;;
170 --)
171 shift
172 repeat=false
173 ;;
174 -*)
175 echo "$name: invalid flag $1" >&2
176 break
177 ;;
178 *)
179 repeat=false
180 ;;
181 esac
182 done
183 # might have used break 2 within the previous loop, but so what
184 $repeat && break
185
186 $update && \
187 if echo "$name: checking for conflicts..." >&2
188 (cvs $cvsopt -q -n update $updateopt ${1+"$@"} 2>/dev/null \
189 | while read line; do
190 echo "$line"
191 echo "$line" >&3
192 done | grep '^C') 3>&1 >/dev/null; then
193 echo "$name: some conflicts were found, aborting..." >&2
194 break
195 fi
196
197 if test ! -f "$log_file"; then
198 if test -z "$ChangeLog"; then
199 for f in ${1+"$@"}; do
200 case "$f" in
201 ChangeLog* | */ChangeLog*)
202 if test -z "$ChangeLog"; then
203 ChangeLog="$f"
204 else
205 echo "$name: multiple ChangeLog files: $ChangeLog and $f" >&2
206 break
207 fi
208 ;;
209 esac
210 done
211 fi
212
213 echo "$name: checking commit message..." >&2
214 cvs $cvsopt diff -u $ChangeLog \
215 | while read line; do
216 case "$line" in
217 "--- "*) :;;
218 "-"*)
219 echo "$name: *** Warning: the following line in ChangeLog diff is suspicious:" >&2
220 echo "$line" | sed 's/^.//' >&2;;
221 "+ "*)
222 echo "$name: *** Warning: lines should start with tabs, not spaces; ignoring line:" >&2
223 echo "$line" | sed 's/^.//' >&2;;
224 "+") echo;;
225 "+ "*) echo "$line";;
226 esac
227 done \
228 | sed -e 's,\+ ,,' -e '/./p' -e '/./d' -e '1d' -e '$d' > "$log_file" \
229 || break
230 # The sed script above removes "+TAB" from the beginning of a line, then
231 # deletes the first and/or the last line, when they happen to be empty
232 fi
233
234 if grep '[^ ]' < "$log_file" > /dev/null; then :; else
235 echo "$name: empty commit message, aborting" >&2
236 break
237 fi
238
239 if grep '^$' < "$log_file" > /dev/null; then
240 echo "$name: *** Warning: blank lines should not appear within a commit messages." >&2
241 echo "$name: *** They should be used to separate distinct commits." >&2
242 fi
243
244 ${PAGER-more} "$log_file" || break
245
246 sleep 1 # give the user some time for a ^C
247
248 # Do not check for empty $log_file again, even though the user might have
249 # zeroed it out. If s/he did, it was probably intentional.
250
251 if $commit; then
252 cvs $cvsopt commit $commitopt -F $log_file ${1+"$@"} || break
253 fi
254
255 main_repeat=false
256 done
257
258 rm -f "$log_file"
259
260 # if main_repeat was not set to `false', we failed
261 $main_repeat && exit 1
262 exit 0