1 m4_define([_m4_divert(SCRIPT)], 100)
2 m4_divert_push([SCRIPT])#!/bin/sh
5 # clcommit (GNU @PACKAGE@) version 0.12
6 # Written by Gary V. Vaughan <gary@gnu.org>
7 # and Alexandre Oliva <aoliva@redhat.com>
9 # Copyright (C) 1999, 2000, 2004 Free Software Foundation, Inc.
10 # This is free software; see the source for copying conditions. There is NO
11 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
18 # This program is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, a copy can be downloaded from
25 # http://www.gnu.org/copyleft/gpl.html, or by writing to the Free
26 # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
29 # Usage: $progname [OPTION]... [--] [file|dir ...]
31 # -C file --changelog=file extract commit message from specified ChangeLog
32 # -zN --compress=N set compression level (0-9, 0=none, 9=max)
33 # --debug enable verbose shell tracing
34 # -n --dry-run don't commit anything
35 # --fast same as --force --first
36 # -F file --file=file read commit message from file
37 # -1 --first extract first entry from ChangeLog, no cvs diff
38 # -f --force don't check (unless *followed* by -n), and just
39 # display commit message instead of running $PAGER
40 # --from=addr override default from address in commit email
41 # -l --local don't descend into subdirectories
42 # -m msg --message=msg set commit message
43 # --msg=msg same as -m
44 # -q --quiet run cvs in quiet mode
45 # -s addr --sendmail=addr send a commit email of the differences to ADDR
46 # --signature[=file] add FILE to the end of the email (~/.signature)
47 # -S TEXT --summary=TEXT specify a TEXT summary for the commit (tla only)
48 # -t --tla use tla as the scm (instead of cvs)
49 # -v --verbose run in verbose mode
50 # --version print version information
51 # -h,-? --help print short or long help message
53 # This script eases checking in changes to CVS-maintained projects
54 # with ChangeLog files. It will check that there have been no
55 # conflicting commits in the CVS repository and print which files it
56 # is going to commit to stderr. A list of files to compare and to
57 # check in can be given in the command line. If it is not given, all
58 # files in the current directory (and below, unless `-l' is given) are
59 # considered for check in.
61 # The commit message will be extracted from the differences between a
62 # file named ChangeLog* in the commit list, or named after -C, and the
63 # one in the repository (unless a message was specified with `-m' or
64 # `-F'). An empty message is not accepted (but a blank line is). If
65 # the message is acceptable, it will be presented for verification
66 # (and possible edition) using the $PAGER environment variable (or
67 # `more', if it is not set, or `cat', if the `-f' switch is given).
68 # If $PAGER exits successfully, the modified files (at that moment)
69 # are checked in, unless `-n' was specified, in which case nothing is
72 # Report bugs to <gary@gnu.org>
76 : ${MAILNOTIFY="mailnotify"}
77 : ${MKSTAMP="mkstamp"}
79 test -f "config/$MAILNOTIFY" && MAILNOTIFY="config/MAILNOTIFY"
80 test -f "config/$MKSTAMP" && MKSTAMP="config/$MKSTAMP"
87 m4_include([getopt.m4sh])
103 # Locations for important files
105 log_file="${TMPDIR-/tmp}/$progname-$$"
107 $RM "${TMPDIR-/tmp}/$progname"*
108 trap '$RM "${log_file}"*; exit $EXIT_FAILURE' 1 2 15
112 # Parse options once, thoroughly. This comes as soon as possible in
113 # the script to make things like `clcommit --version' happen quickly.
116 my_sed_single_opt='1s/^\(..\).*$/\1/;q'
117 my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
118 my_sed_long_opt='1s/^\(--[[^=]]*\)=.*/\1/;q'
119 my_sed_long_arg='1s/^--[[^=]]*=//'
121 # this just eases exit handling
122 while test $# -gt 0; do
127 --debug) func_echo "enabling shell trace mode"
128 mailnotify_flags="$mailnotify_flags --debug"
132 --fast) set -- --force --first ${1+"$@"} ;;
134 -f|--force) opt_update=false; PAGER=cat ;;
136 --from) test $# = 0 && func_missing_arg $opt && break
137 mailnotify_flags="$mailnotify_flags --from '"$1"'"
141 -l|--local) update_flags="$update_flags -l"
142 commit_flags="$commit_flags -l"
146 test $# = 0 && func_missing_arg $opt && break
147 if $opt_first || test -f "$log_file"; then
148 func_error "you can have at most one of -m, -F and -1"
151 echo "$1" > "$log_file"
155 -F|--file) test $# = 0 && func_missing_arg $opt && break
156 if $opt_first || test -f "$log_file"; then
157 func_error "you can have at most one of -m, -F and -1"
160 if cat < "$1" > "$log_file"; then :; else
166 -1|--first) if test -f "$log_File"; then
167 func_error "you can have at most one of -m, -F and -1"
173 -C|--[[cC]]hange[[lL]]og)
174 test $# = 0 && func_missing_arg $opt && break
175 if test -f "$1"; then :; else
176 func_error "ChangeLog file \`$1' does not exist"
183 -n|--dry-run) opt_commit=false; opt_update=: ;;
185 -q|--quiet) cvs_flags="$cvs_flags -q" ;;
187 -s|--sendmail) test $# = 0 && func_missing_arg $opt && break
192 --signature) test $# = 0 && func_missing_arg $opt && break
193 signature_file="$HOME/.signature"
196 *) signature_file="$1"; shift ;;
198 if test -f "$signature_file"; then :; else
199 func_error "\`$signature_file': file not found"
204 -S|--summary) test $# = 0 && func_missing_arg $opt && break
209 -t|--tla) opt_tla=: ;;
211 -v|--verbose) opt_verbose=: ;;
214 test $# = 0 && func_missing_arg $opt && break
217 *) func_error "invalid argument for $opt"
221 cvs_flags="$cvs_flags -z$1"
225 # Separate optargs to long options:
226 --message=*|--msg=*|--from=*|--file=*|--[[Cc]]hange[[Ll]]og=*|--compress=*|--summary=*|--sendmail=*|--signature=*)
227 arg=`echo "$opt" | $SED "$my_sed_long_arg"`
228 opt=`echo "$opt" | $SED "$my_sed_long_opt"`
229 set -- "$opt" "$arg" ${1+"$@"}
232 # Separate optargs to short options:
233 -m*|-F*|-C*|-S*|-s*|-z*)
234 arg=`echo "$opt" |$SED "$my_sed_single_rest"`
235 opt=`echo "$opt" |$SED "$my_sed_single_opt"`
236 set -- "$opt" "$arg" ${1+"$@"}
239 # Separate non-argument short options:
241 rest=`echo "$opt" |$SED "$my_sed_single_rest"`
242 opt=`echo "$opt" |$SED "$my_sed_single_opt"`
243 set -- "$opt" "-$rest" ${1+"$@"}
246 -\?|-h) func_usage ;;
248 --version) func_version ;;
250 -*) func_fatal_help "unrecognized option \`$opt'" ;;
251 *) set -- "$opt" ${1+"$@"}; break ;;
255 if test -z "$sendmail_to"; then
257 # can't have a from address without a destination address
258 test -n "$sendmail_from" &&
259 func_error "can't use --from without --sendmail." && exit_cmd=exit
261 # can't use a signature file without a destination address
262 test -n "$signature_file" &&
263 func_error "can't use --signature without --sendmail." && exit_cmd=exit
266 # Bail if the options were screwed
267 $exit_cmd $EXIT_FAILURE
270 # func_check_conflicts
271 func_check_conflicts ()
273 func_verbose "$progname: checking for conflicts..."
280 ) 3>&1 >/dev/null; then
281 func_fatal_error "some conflicts were found with arch archive, aborting..."
285 if test -f CVS/Entries; then
286 if ( $CVS $cvs_flags -q -n update $update_flags ${1+"$@"} |
291 ) 3>&1 >/dev/null; then
292 func_fatal_error "some conflicts were found with CVS repository, aborting..."
298 # func_check_commit_msg
299 func_check_commit_msg ()
301 if test -z "$ChangeLog"; then
302 for f in ${1+"$@"}; do
304 ChangeLog* | */ChangeLog*)
305 if test -z "$ChangeLog"; then
308 func_fatal_error "multiple ChangeLog files: $ChangeLog and $f"
315 func_verbose "$progname: checking commit message..."
318 $SED 's,^,+,' < ${ChangeLog-ChangeLog} |
321 "+") if $skipping; then skipping=false; else break; fi;;
323 func_error "*** Warning: lines should start with tabs, not spaces; ignoring line:"
324 echo "$line" | $SED 's/^.//' >&2;;
326 $skipping || echo "$line" ;;
329 $SED 's,^\+ ,,' > "$log_file" || exit $EXIT_FAILURE
332 cmd="$TLA file-diffs"
334 cmd="$CVS $cvs_flags diff -u"
336 $cmd ${ChangeLog-ChangeLog} |
341 func_error "*** Warning: the following line in ChangeLog diff is suspicious:"
342 echo "$line" | $SED 's/^.//' >&2;;
344 func_error "*** Warning: lines should start with tabs, not spaces; ignoring line:"
345 echo "$line" | $SED 's/^.//' >&2;;
347 "+ "*) echo "$line";;
350 $SED -e 's,\+ ,,' -e '/./p' -e '/./d' -e '1d' -e '$d' > "$log_file" \
351 || exit $EXIT_FAILURE
353 # The sed script above removes "+TAB" from the beginning of a line, then
354 # deletes the first and/or the last line, when they happen to be empty
362 tla_log=`$TLA make-log`
363 test -n "$summary" || summary=`$SED -e '1{s/^Summary: *//;q;}'`
364 echo "Summary: $summary" > "$tla_log$$T" &&
365 $SED 1d "$tla_log" >> "$tla_log$$T" &&
366 cat < "$log_file" >> "$tla_log$$T" &&
367 mv "$tla_log$$T" "$tla_log"
368 ${PAGER-more} "$tla_log" || exit $EXIT_FAILURE
370 sleep 1 # give the user some time for a ^C
372 # Propagate any user edits back to the cvs log message
373 $SED -e '/^[[A-Z]][[-a-zA-Z]]*:/d' -e '1d' < $tla_log > $log_file
376 ${PAGER-more} "$log_file" || exit $EXIT_FAILURE
378 sleep 1 # give the user some time for a ^C
380 subject=`cvs -nq up 2>/dev/null | grep '^[[MAD]] ' | $SED 's/^. //'`
381 test $# -gt 0 && subject="$@"
384 if test -f CVS/Entries; then
385 func_verbose "$CVS $cvs_flags commit $commit_flags -F $log_file ${1+$@}"
386 $CVS $cvs_flags commit $commit_flags -F $log_file ${1+"$@"} || exit $EXIT_FAILURE
389 # Need to do the tla commit *after* cvs commit to make sure the
390 # ChangeLog timestamps stay in synch.
391 $opt_tla && $TLA commit
398 notify_file="${log_file}.2"
399 func_verbose "Mailing commit notification to $sendmail_to"
402 echo Subject: $subject
403 test -f '{arch}/=tagging-method' &&
404 echo "Tree version: `$TLA tree-version`"
406 echo "CVSROOT: `$SED -e 's,.*:,,g' CVS/Root`"
408 echo "TIMESTAMP: `$SHELL $MKSTAMP < ./ChangeLog`"
409 test -f CVS/Repository &&
410 echo "Module name: `cat CVS/Repository`"
412 echo "Branch: `$SED -e 's,^T,,;1q' CVS/Tag`"
414 echo "Changes by: `$SED -e 's,^:[[a-z]]*:,,;s,:.*$,,g' CVS/Root`"
417 $SED -e 's,^, ,' "$log_file"
418 test -f "$signature_file" && cat "$signature_file"
421 ${PAGER-more} "$notify_file" || break
423 # Break out the subject line again
424 my_mail_subject=`$SED -e '1{s/^Subject: *//;q;}' "$notify_file"`
425 my_mail_body=`$SED -e '2,$p;d' "$notify_file"`
426 echo "$my_mail_body" > "$notify_file"
428 func_verbose "mailing commit notification to \"$sendmail_to\""
429 eval func_verbose_eval $MAILNOTIFY $mailnotify_flags -s "'$my_mail_subject'" \
430 -m "text/plain" -f "$notify_file" -- "'$sendmail_to'"
440 $opt_update && func_check_conflicts
442 test -f "$log_file" || func_check_commit_msg
444 grep '[[^ ]]' < "$log_file" > /dev/null ||
445 func_fatal_error "empty commit message, aborting"
447 if grep '^$' < "$log_file" > /dev/null; then
448 func_error "*** Warning: blank lines should not appear within commit messages."
449 func_error "*** They should be used to separate distinct commits."
452 # Do not check for empty $log_file again, even though the user might have
453 # zeroed it out. If s/he did, it was probably intentional.
458 # Need to set the subject line *after* tla commit, or the
459 # patch revision changes underneath us!
462 subject="$subject [["`$TLA tree-version|$SED $basename`--`$TLA revisions|$SED -e '$p;d'`"]]"
464 # Send a copy of the log_file if sendmail_to was set:
465 if test -n "$sendmail_to"; then