]>
git.saurik.com Git - bison.git/blob - etc/clcommit
5 # Copyright (C) 1999, 2000, Free Software Foundation
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
11 # Originally by Gary V. Vaughan <gvaughan@oranda.demon.co.uk>
12 # Heavily modified by Alexandre Oliva <oliva@dcc.unicamp.br>
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.
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
33 # usage: commit [-v] [-h] [-f] [-l] [-n] [-q] [-z N] [-C ChangeLog_file]
34 # [-m msg|-F msg_file] [--] [file|dir ...]
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
56 log_file
="${TMPDIR-/tmp}/commitlog.$$"
59 trap 'rm -f "$log_file"; exit 1' 1 2 15
61 # this just eases exit handling
63 while $main_repeat; do
65 repeat
="test $# -gt 0"
74 updateopt
="$updateopt -l"
75 commitopt
="$commitopt -l"
80 echo "$name: missing argument for $1" >&2
83 if test -f "$log_file"; then
84 echo "$name: you can have at most one of -m and -F" >&2
88 echo "$1" > "$log_file"
92 if test -f "$log_file"; then
93 echo "$name: you can have at most one of -m and -F" >&2
97 echo "$name: missing argument for $1" >&2
101 if cat < "$1" > "$log_file"; then :; else
106 -C|--[cC
]hange
[lL
]og
)
108 echo "$name: missing argument for $1" >&2
112 if test ! -f "$1"; then
113 echo "$name: ChangeLog file \`$1' does not exist" >&2
129 echo "$name: missing argument for $1" >&2
134 *) echo "$name: invalid argument for $1" >&2
138 cvsopt
="$cvsopt -z$2"
144 opt
=`echo "$1" | sed '1s/^\(..\).*$/\1/;q'`
145 arg
=`echo "$1" | sed '1s/^-[a-zA-Z0-9]//'`
147 set -- "$opt" "$arg" ${1+"$@"}
149 --message=*|--msg=*|--file=*|--[Cc
]hange
[Ll
]og
=*|--compress=*)
150 opt
=`echo "$1" | sed '1s/^\(--[^=]*\)=.*/\1/;q'`
151 arg
=`echo "$1" | sed '1s/^--[^=]*=//'`
153 set -- "$opt" "$arg" ${1+"$@"}
157 sed '/^# '$name' version /,/^# Heavily modified by/ { s/^# //; p; }; d' < $0
161 sed '/^# usage:/,/# -h/ { s/^# //; p; }; d' < $0 &&
163 echo "run \`$name --help | more' for full usage"
167 sed '/^# '$name' version /,/^[^#]/ { /^[^#]/ d; s/^# //; p; }; d' < $0
175 echo "$name: invalid flag $1" >&2
183 # might have used break 2 within the previous loop, but so what
187 if echo "$name: checking for conflicts..." >&2
188 (cvs
$cvsopt -q -n update
$updateopt ${1+"$@"} 2>/dev
/null \
189 | while read line
; do
192 done | grep '^C') 3>&1 >/dev
/null
; then
193 echo "$name: some conflicts were found, aborting..." >&2
197 if test ! -f "$log_file"; then
198 if test -z "$ChangeLog"; then
199 for f
in ${1+"$@"}; do
201 ChangeLog
* | */ChangeLog
*)
202 if test -z "$ChangeLog"; then
205 echo "$name: multiple ChangeLog files: $ChangeLog and $f" >&2
213 echo "$name: checking commit message..." >&2
214 cvs
$cvsopt diff -u $ChangeLog \
215 | while read line
; do
219 echo "$name: *** Warning: the following line in ChangeLog diff is suspicious:" >&2
220 echo "$line" | sed 's/^.//' >&2;;
222 echo "$name: *** Warning: lines should start with tabs, not spaces; ignoring line:" >&2
223 echo "$line" | sed 's/^.//' >&2;;
225 "+ "*) echo "$line";;
228 | sed -e 's,\+ ,,' -e '/./p' -e '/./d' -e '1d' -e '$d' > "$log_file" \
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
234 if grep '[^ ]' < "$log_file" > /dev
/null
; then :; else
235 echo "$name: empty commit message, aborting" >&2
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
244 ${PAGER-more} "$log_file" || break
246 sleep 1 # give the user some time for a ^C
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.
252 cvs
$cvsopt commit
$commitopt -F $log_file ${1+"$@"} || break
260 # if main_repeat was not set to `false', we failed
261 $main_repeat && exit 1