]> git.saurik.com Git - bison.git/blame - etc/clcommit
src/scan-gram.l (<SC_BRACED_CODE>"}"): Append ";" only in braced code,
[bison.git] / etc / clcommit
CommitLineData
aefb051c
JT
1#! /bin/sh
2
4e8ef709 3# clcommit version 0.9.5
aefb051c
JT
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>
4e8ef709 12# Pretty much rewritten by Alexandre Oliva <aoliva@redhat.com>
aefb051c
JT
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
4e8ef709
AD
33# usage: clcommit [-v] [-h] [-f] [-l] [-n] [-q] [-z N] [-C ChangeLog_file]
34# [-m msg|-F msg_file|-1] [--] [file|dir ...]
aefb051c 35
4e8ef709
AD
36# -f --force don't check (unless *followed* by -n), and just
37# display commit message instead of running $PAGER
aefb051c
JT
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
4e8ef709 42# -1 --first extract first entry from ChangeLog, no cvs diff
aefb051c 43# -C file --changelog=file extract commit message from specified ChangeLog
4e8ef709 44# --fast same as --force --first
aefb051c
JT
45# -n --dry-run don't commit anything
46# -q --quiet run cvs in quiet mode
47# -zN --compress=N set compression level (0-9, 0=none, 9=max)
48# -v --version print version information
49# -h,-? --help print short or long help message
50
4e8ef709 51name=clcommit
bbb5bcc6 52: ${CVS=cvs}
aefb051c
JT
53cvsopt=
54updateopt=
55commitopt=
56dry_run=false
57commit=:
58update=:
59log_file="${TMPDIR-/tmp}/commitlog.$$"
4e8ef709 60first=false
aefb051c
JT
61
62rm -f "$log_file"
63trap 'rm -f "$log_file"; exit 1' 1 2 15
64
65# this just eases exit handling
66main_repeat=":"
67while $main_repeat; do
68
69repeat="test $# -gt 0"
70while $repeat; do
71 case "$1" in
4e8ef709
AD
72 --fast)
73 shift
74 set fnord --force --first ${1+"$@"}
75 shift
76 ;;
77 -f|--force)
aefb051c
JT
78 update=false
79 PAGER=cat
80 shift
81 ;;
82 -l|--local)
83 updateopt="$updateopt -l"
84 commitopt="$commitopt -l"
85 shift
86 ;;
87 -m|--message|--msg)
88 if test $# = 1; then
89 echo "$name: missing argument for $1" >&2
90 break
91 fi
4e8ef709
AD
92 if $first || test -f "$log_file"; then
93 echo "$name: you can have at most one of -m, -F and -1" >&2
aefb051c
JT
94 break
95 fi
96 shift
97 echo "$1" > "$log_file"
98 shift
99 ;;
100 -F|--file)
4e8ef709
AD
101 if $first || test -f "$log_file"; then
102 echo "$name: you can have at most one of -m, -F and -1" >&2
aefb051c
JT
103 break
104 fi
105 if test $# = 1; then
106 echo "$name: missing argument for $1" >&2
107 break
108 fi
109 shift
110 if cat < "$1" > "$log_file"; then :; else
111 break
112 fi
113 shift
114 ;;
4e8ef709
AD
115 -1|--first)
116 if test -f "$log_File"; then
117 echo "$name: you can have at most one of -m, -F and -1" >&2
118 break
119 fi
120 first=:
121 shift
122 ;;
aefb051c
JT
123 -C|--[cC]hange[lL]og)
124 if test $# = 1; then
125 echo "$name: missing argument for $1" >&2
126 break
127 fi
128 shift
129 if test ! -f "$1"; then
130 echo "$name: ChangeLog file \`$1' does not exist" >&2
131 break
132 fi
133 ChangeLog="$1"
4e8ef709 134 shift
aefb051c
JT
135 ;;
136 -n|--dry-run)
137 commit=false
138 update=true
139 shift
140 ;;
141 -q|--quiet)
142 cvsopt="$cvsopt -q"
143 shift
144 ;;
4e8ef709
AD
145 -v|--verbose)
146 cvsopt="$cvsopt -t"
147 shift
148 ;;
aefb051c
JT
149 -z|--compress)
150 if test $# = 1; then
151 echo "$name: missing argument for $1" >&2
152 break
153 fi
154 case "$2" in
155 [0-9]) :;;
156 *) echo "$name: invalid argument for $1" >&2
157 break
158 ;;
159 esac
160 cvsopt="$cvsopt -z$2"
161 shift
162 shift
163 ;;
164
165 -m*|-F*|-C*|-z*)
166 opt=`echo "$1" | sed '1s/^\(..\).*$/\1/;q'`
167 arg=`echo "$1" | sed '1s/^-[a-zA-Z0-9]//'`
168 shift
169 set -- "$opt" "$arg" ${1+"$@"}
170 ;;
171 --message=*|--msg=*|--file=*|--[Cc]hange[Ll]og=*|--compress=*)
172 opt=`echo "$1" | sed '1s/^\(--[^=]*\)=.*/\1/;q'`
173 arg=`echo "$1" | sed '1s/^--[^=]*=//'`
174 shift
175 set -- "$opt" "$arg" ${1+"$@"}
176 ;;
177
178 -v|--version)
179 sed '/^# '$name' version /,/^# Heavily modified by/ { s/^# //; p; }; d' < $0
180 exit 0
181 ;;
182 -\?|-h)
183 sed '/^# usage:/,/# -h/ { s/^# //; p; }; d' < $0 &&
184 echo
185 echo "run \`$name --help | more' for full usage"
186 exit 0
187 ;;
188 --help)
189 sed '/^# '$name' version /,/^[^#]/ { /^[^#]/ d; s/^# //; p; }; d' < $0
190 exit 0
191 ;;
192 --)
193 shift
194 repeat=false
195 ;;
196 -*)
197 echo "$name: invalid flag $1" >&2
198 break
199 ;;
200 *)
201 repeat=false
202 ;;
203 esac
204done
205# might have used break 2 within the previous loop, but so what
206$repeat && break
207
208$update && \
209if echo "$name: checking for conflicts..." >&2
4e8ef709 210 ($CVS $cvsopt -q -n update $updateopt ${1+"$@"} 2>/dev/null \
aefb051c
JT
211 | while read line; do
212 echo "$line"
213 echo "$line" >&3
214 done | grep '^C') 3>&1 >/dev/null; then
215 echo "$name: some conflicts were found, aborting..." >&2
216 break
217fi
218
219if test ! -f "$log_file"; then
220 if test -z "$ChangeLog"; then
221 for f in ${1+"$@"}; do
222 case "$f" in
223 ChangeLog* | */ChangeLog*)
224 if test -z "$ChangeLog"; then
225 ChangeLog="$f"
226 else
227 echo "$name: multiple ChangeLog files: $ChangeLog and $f" >&2
228 break
229 fi
230 ;;
231 esac
232 done
233 fi
234
235 echo "$name: checking commit message..." >&2
4e8ef709
AD
236 if $first; then
237 skipping=:
238 sed 's,^,+,' < ${ChangeLog-ChangeLog} |
239 while read line; do
aefb051c 240 case "$line" in
4e8ef709
AD
241 "+2"*) if $skipping; then skipping=false; else break; fi;;
242 "+ "*)
243 echo "$name: *** Warning: lines should start with tabs, not spaces; ignoring line:" >&2
244 echo "$line" | sed 's/^.//' >&2;;
245 "+ "*)
246 $skipping || echo "$line" ;;
247 esac
248 done |
249 sed 's,^\+ ,,' > "$log_file" || break
250 else
251 $CVS $cvsopt diff -u ${ChangeLog-ChangeLog} |
252 while read line; do
253 case $line in
aefb051c
JT
254 "--- "*) :;;
255 "-"*)
256 echo "$name: *** Warning: the following line in ChangeLog diff is suspicious:" >&2
257 echo "$line" | sed 's/^.//' >&2;;
258 "+ "*)
259 echo "$name: *** Warning: lines should start with tabs, not spaces; ignoring line:" >&2
260 echo "$line" | sed 's/^.//' >&2;;
261 "+") echo;;
262 "+ "*) echo "$line";;
263 esac
4e8ef709
AD
264 done |
265 sed -e 's,\+ ,,' -e '/./p' -e '/./d' -e '1d' -e '$d' > "$log_file" \
266 || break
267 fi
aefb051c
JT
268# The sed script above removes "+TAB" from the beginning of a line, then
269# deletes the first and/or the last line, when they happen to be empty
270fi
271
272if grep '[^ ]' < "$log_file" > /dev/null; then :; else
273 echo "$name: empty commit message, aborting" >&2
274 break
275fi
276
277if grep '^$' < "$log_file" > /dev/null; then
4e8ef709 278 echo "$name: *** Warning: blank lines should not appear within commit messages." >&2
aefb051c
JT
279 echo "$name: *** They should be used to separate distinct commits." >&2
280fi
281
282${PAGER-more} "$log_file" || break
283
284sleep 1 # give the user some time for a ^C
285
286# Do not check for empty $log_file again, even though the user might have
287# zeroed it out. If s/he did, it was probably intentional.
288
289if $commit; then
4e8ef709 290 $CVS $cvsopt commit $commitopt -F $log_file ${1+"$@"} || break
aefb051c
JT
291fi
292
293main_repeat=false
294done
295
296rm -f "$log_file"
297
298# if main_repeat was not set to `false', we failed
299$main_repeat && exit 1
300exit 0