1 m4_define([_m4_divert(SCRIPT)], 100)
2 m4_divert_push([SCRIPT])#!/bin/sh
5 # clcommit (GNU @PACKAGE@) version 0.16
6 # Written by Gary V. Vaughan <gary@gnu.org>
7 # and Alexandre Oliva <aoliva@redhat.com>
9 # Copyright (C) 1999, 2000, 2004, 2006 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 # Clcommit 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 # Clcommit 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
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with clcommit; see the file COPYING. If not, a copy
25 # can be downloaded from http://www.gnu.org/licenses/gpl.html,
26 # or obtained by writing to the Free Software Foundation, Inc.,
27 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 # -r [FILE] --rcfile[=FILE] read default option from FILE [./.clcommitrc]
45 # -q --quiet run cvs in quiet mode
46 # -s addr --sendmail=addr send a commit email of the differences to ADDR
47 # --signature[=FILE] add FILE to the end of the email [~/.signature]
48 # -S TEXT --summary=TEXT specify a TEXT subject line for the commit email
49 # -t --tla use tla as the scm (and cvs in a dual tree)
50 # -v --verbose run in verbose mode
51 # --version print version information
52 # -h,-? --help print short or long help message
54 # This script eases checking in changes to CVS-maintained projects
55 # with ChangeLog files. It will check that there have been no
56 # conflicting commits in the CVS repository and print which files it
57 # is going to commit to stderr. A list of files to compare and to
58 # check in can be given in the command line. If it is not given, all
59 # files in the current directory (and below, unless `-l' is given) are
60 # considered for check in.
62 # The commit message will be extracted from the differences between a
63 # file named ChangeLog* in the commit list, or named after -C, and the
64 # one in the repository (unless a message was specified with `-m' or
65 # `-F'). An empty message is not accepted (but a blank line is). If
66 # the message is acceptable, it will be presented for verification
67 # (and possible edition) using the $PAGER environment variable (or
68 # `more', if it is not set, or `cat', if the `-f' switch is given).
69 # If $PAGER exits successfully, the modified files (at that moment)
70 # are checked in, unless `-n' was specified, in which case nothing is
73 # Report bugs to <gary@gnu.org>
77 : ${MAILNOTIFY="mailnotify"}
78 : ${MKSTAMP="mkstamp"}
80 test -f "libltdl/config/$MAILNOTIFY" && MAILNOTIFY="libltdl/config/$MAILNOTIFY"
81 test -f "libltdl/config/$MKSTAMP" && MKSTAMP="libltdl/config/$MKSTAMP"
88 m4_include([getopt.m4sh])
105 # try to find out whether read supports -r
106 if echo bt | tr b '\\' | { read -r line; test "X$line" = 'X\t'; } 2>/dev/null
113 # Locations for important files:
115 log_dir="`func_mktempdir`"
116 log_file="$log_dir/log"
118 trap '$RM -r "$log_dir"; exit $EXIT_FAILURE' 1 2 15
122 # Parse options once, thoroughly. This comes as soon as possible in
123 # the script to make things like `clcommit --version' happen quickly.
126 my_sed_single_opt='1s/^\(..\).*$/\1/;q'
127 my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
128 my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
129 my_sed_long_arg='1s/^--[^=]*=//'
131 # this just eases exit handling
132 while test $# -gt 0; do
137 --debug) func_echo "enabling shell trace mode"
138 mailnotify_flags="$mailnotify_flags --debug"
142 --fast) set dummy --force --first ${1+"$@"}; shift ;;
144 -f|--force) opt_update=false; PAGER=cat ;;
146 --from) test $# = 0 && func_missing_arg $opt && break
147 func_quote_for_eval "$1"
148 mailnotify_flags="$mailnotify_flags --from=$func_quote_for_eval_result"
152 -l|--local) update_flags="$update_flags -l"
153 commit_flags="$commit_flags -l"
157 test $# = 0 && func_missing_arg $opt && break
158 if $opt_first || test -f "$log_file"; then
159 func_error "you can have at most one of -m, -F and -1"
162 echo "$1" > "$log_file"
166 -F|--file) test $# = 0 && func_missing_arg $opt && break
167 if $opt_first || test -f "$log_file"; then
168 func_error "you can have at most one of -m, -F and -1"
171 if cat < "$1" > "$log_file"; then :; else
177 -1|--first) if test -f "$log_File"; then
178 func_error "you can have at most one of -m, -F and -1"
184 -C|--[cC]hange[lL]og)
185 test $# = 0 && func_missing_arg $opt && break
186 if test -f "$1"; then :; else
187 func_error "ChangeLog file \`$1' does not exist"
194 -n|--dry-run) opt_commit=false; opt_update=: ;;
196 -q|--quiet) cvs_flags="$cvs_flags -q" ;;
198 -r|--rcfile) rc_file="./.clcommitrc"
199 if test $# -gt 0; then
202 *) rc_file="$1"; shift ;;
205 if test -f "$rc_file"; then :; else
206 func_error "rcfile \`$rc_file' does not exist"
210 # The funny quoting allows keeping one option per
212 eval set dummy `echo \`cat $rc_file\` \\\${1+\"\\\$@\"}`
216 -s|--sendmail) test $# = 0 && func_missing_arg $opt && break
217 func_quote_for_eval "$1"
218 sendmail_to="$func_quote_for_eval_result"
222 --signature) test $# = 0 && func_missing_arg $opt && break
223 signature_file="$HOME/.signature"
226 *) signature_file="$1"; shift ;;
228 if test -f "$signature_file"; then :; else
229 func_error "\`$signature_file': file not found"
234 -S|--summary) test $# = 0 && func_missing_arg $opt && break
239 -t|--tla) opt_tla=: ;;
241 -v|--verbose) opt_verbose=: ;;
244 test $# = 0 && func_missing_arg $opt && break
247 *) func_error "invalid argument for $opt"
251 cvs_flags="$cvs_flags -z$1"
255 # Separate optargs to long options:
257 arg=`echo "$opt" | $SED "$my_sed_long_arg"`
258 opt=`echo "$opt" | $SED "$my_sed_long_opt"`
259 set dummy "$opt" "$arg" ${1+"$@"}
263 # Separate optargs to short options:
264 -m*|-F*|-C*|-S*|-s*|-z*)
265 arg=`echo "$opt" |$SED "$my_sed_single_rest"`
266 opt=`echo "$opt" |$SED "$my_sed_single_opt"`
267 set dummy "$opt" "$arg" ${1+"$@"}
271 # Separate non-argument short options:
273 rest=`echo "$opt" |$SED "$my_sed_single_rest"`
274 opt=`echo "$opt" |$SED "$my_sed_single_opt"`
275 set dummy "$opt" "-$rest" ${1+"$@"}
279 -\?|-h) func_usage ;;
281 --version) func_version ;;
283 -*) func_fatal_help "unrecognized option \`$opt'" ;;
284 *) set dummy "$opt" ${1+"$@"}; shift; break ;;
288 if test -z "$sendmail_to"; then
290 # can't have a from address without a destination address
291 test -n "$sendmail_from" &&
292 func_error "can't use --from without --sendmail." && exit_cmd=exit
294 # can't use a signature file without a destination address
295 test -n "$signature_file" &&
296 func_error "can't use --signature without --sendmail." && exit_cmd=exit
299 # Bail if the options were screwed
300 $exit_cmd $EXIT_FAILURE
303 # func_check_conflicts
304 func_check_conflicts ()
306 func_verbose "$progname: checking for conflicts..."
309 while $read_r line; do
313 ) 3>&1 >/dev/null; then
314 func_fatal_error "some conflicts were found with arch archive, aborting..."
318 if test -f CVS/Entries; then
319 if ( $CVS $cvs_flags -q -n update $update_flags ${1+"$@"} |
320 while $read_r line; do
324 ) 3>&1 >/dev/null; then
325 func_fatal_error "some conflicts were found with CVS repository, aborting..."
331 # func_check_commit_msg
332 func_check_commit_msg ()
334 if test -z "$ChangeLog"; then
335 for f in ${1+"$@"}; do
337 ChangeLog* | */ChangeLog*)
338 if test -z "$ChangeLog"; then
341 func_fatal_error "multiple ChangeLog files: $ChangeLog and $f"
348 func_verbose "$progname: checking commit message..."
351 $SED 's,^,+,' < ${ChangeLog-ChangeLog} |
352 while $read_r line; do
354 "+") if $skipping; then skipping=false; else break; fi;;
356 func_error "*** Warning: lines should start with tabs, not spaces; ignoring line:"
357 echo "$line" | $SED 's/^.//' >&2;;
359 $skipping || echo "$line" ;;
362 $SED 's,^\+ ,,' > "$log_file" || exit $EXIT_FAILURE
365 cmd="$TLA file-diffs"
367 cmd="$CVS $cvs_flags diff -u"
369 $cmd ${ChangeLog-ChangeLog} |
370 while $read_r line; do
374 func_error "*** Warning: the following line in ChangeLog diff is suspicious:"
375 echo "$line" | $SED 's/^.//' >&2;;
377 func_error "*** Warning: lines should start with tabs, not spaces; ignoring line:"
378 echo "$line" | $SED 's/^.//' >&2;;
380 "+ "*) echo "$line";;
383 $SED -e 's,\+ ,,' -e '/./p' -e '/./d' -e '1d' -e '$d' > "$log_file" \
384 || exit $EXIT_FAILURE
386 # The sed script above removes "+TAB" from the beginning of a line, then
387 # deletes the first and/or the last line, when they happen to be empty
395 tla_log=`$TLA make-log`
396 test -n "$summary" || summary=`$SED -e '
401 echo "Summary: $summary" > "$tla_log$$T" &&
402 $SED 1d "$tla_log" >> "$tla_log$$T" &&
403 cat < "$log_file" >> "$tla_log$$T" &&
404 mv "$tla_log$$T" "$tla_log"
405 ${PAGER-more} "$tla_log" || exit $EXIT_FAILURE
407 sleep 1 # give the user some time for a ^C
409 # Propagate any user edits back to the cvs log message
410 $SED -e '/^[A-Z][-a-zA-Z]*:/d' -e '1d' < $tla_log > $log_file
413 ${PAGER-more} "$log_file" || exit $EXIT_FAILURE
415 sleep 1 # give the user some time for a ^C
417 subject=`cvs -nq up 2>/dev/null | $SED -n 's/^[MAD] //p'`
418 test $# -gt 0 && subject="$@"
421 if test -f CVS/Entries; then
422 func_verbose "$CVS $cvs_flags commit $commit_flags -F $log_file ${1+$@}"
423 $CVS $cvs_flags commit $commit_flags -F $log_file ${1+"$@"} || exit $EXIT_FAILURE
426 # Need to do the tla commit *after* cvs commit to make sure the
427 # ChangeLog timestamps stay in synch.
428 $opt_tla && $TLA commit
437 notify_file="${log_dir}/notify"
438 func_verbose "Mailing commit notification to $sendmail_to"
441 echo Subject: $subject
442 test -f '{arch}/=tagging-method' &&
443 echo "Tree version: `$TLA tree-version`"
445 echo "CVSROOT: `$SED -e 's,.*:,,g' CVS/Root`"
447 echo "TIMESTAMP: `$SHELL $MKSTAMP .`"
448 test -f CVS/Repository &&
449 echo "Module name: `cat CVS/Repository`"
451 echo "Branch: `$SED -e 's,^T,,;1q' CVS/Tag`"
453 echo "Changes by: `$SED -e 's,^:[a-z]*:,,;s,:.*$,,g' CVS/Root`"
456 $SED -e 's,^, ,' "$log_file"
457 test -f "$signature_file" && {
459 cat "$signature_file"
463 ${PAGER-more} "$notify_file" || break
465 # Break out the subject line again
466 my_mail_subject=`$SED -e '
471 my_mail_body=`$SED -e '2,$p;d' "$notify_file"`
472 echo "$my_mail_body" > "$notify_file"
474 func_verbose "mailing commit notification to \"$sendmail_to\""
475 func_quote_for_eval "$my_mail_subject"
476 func_show_eval "$MAILNOTIFY $mailnotify_flags \
477 -s $func_quote_for_eval_result -m 'text/plain' -f '$notify_file' \
488 $opt_update && func_check_conflicts
490 test -f "$log_file" || func_check_commit_msg
492 grep '[^ ]' < "$log_file" > /dev/null ||
493 func_fatal_error "empty commit message, aborting"
495 if grep '^$' < "$log_file" > /dev/null; then
496 func_error "*** Warning: blank lines should not appear within commit messages."
497 func_error "*** They should be used to separate distinct commits."
500 # Do not check for empty $log_file again, even though the user might have
501 # zeroed it out. If s/he did, it was probably intentional.
503 func_commit ${1+"$@"}
506 # Need to set the subject line *after* tla commit, or the
507 # patch revision changes underneath us!
510 subject="$subject ["`$TLA tree-version|$SED $basename`--`$TLA revisions|$SED -e '$p;d'`"]"
512 # Send a copy of the log_file if sendmail_to was set:
513 if test -n "$sendmail_to"; then