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 # 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., 51 Franklin Street, Fifth Floor, 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 # -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 "config/$MAILNOTIFY" && MAILNOTIFY="config/$MAILNOTIFY"
81 test -f "config/$MKSTAMP" && MKSTAMP="config/$MKSTAMP"
88 m4_include([getopt.m4sh])
104 # try to find out whether read supports -r
105 if echo bt | tr b '\\' | { read -r line; test "X$line" = 'X\t'; } 2>/dev/null
112 # Locations for important files:
114 log_dir="`func_mktempdir`"
115 log_file="$log_dir/log"
117 trap '$RM -r "$log_dir"; exit $EXIT_FAILURE' 1 2 15
121 # Parse options once, thoroughly. This comes as soon as possible in
122 # the script to make things like `clcommit --version' happen quickly.
125 my_sed_single_opt='1s/^\(..\).*$/\1/;q'
126 my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
127 my_sed_long_opt='1s/^\(--[[^=]]*\)=.*/\1/;q'
128 my_sed_long_arg='1s/^--[[^=]]*=//'
130 # this just eases exit handling
131 while test $# -gt 0; do
136 --debug) func_echo "enabling shell trace mode"
137 mailnotify_flags="$mailnotify_flags --debug"
141 --fast) set dummy --force --first ${1+"$@"}; shift ;;
143 -f|--force) opt_update=false; PAGER=cat ;;
145 --from) test $# = 0 && func_missing_arg $opt && break
146 func_quote_for_eval "$1"
147 mailnotify_flags="$mailnotify_flags --from=$func_quote_for_eval_result"
151 -l|--local) update_flags="$update_flags -l"
152 commit_flags="$commit_flags -l"
156 test $# = 0 && func_missing_arg $opt && break
157 if $opt_first || test -f "$log_file"; then
158 func_error "you can have at most one of -m, -F and -1"
161 echo "$1" > "$log_file"
165 -F|--file) test $# = 0 && func_missing_arg $opt && break
166 if $opt_first || test -f "$log_file"; then
167 func_error "you can have at most one of -m, -F and -1"
170 if cat < "$1" > "$log_file"; then :; else
176 -1|--first) if test -f "$log_File"; then
177 func_error "you can have at most one of -m, -F and -1"
183 -C|--[[cC]]hange[[lL]]og)
184 test $# = 0 && func_missing_arg $opt && break
185 if test -f "$1"; then :; else
186 func_error "ChangeLog file \`$1' does not exist"
193 -n|--dry-run) opt_commit=false; opt_update=: ;;
195 -q|--quiet) cvs_flags="$cvs_flags -q" ;;
197 -r|--rcfile) rc_file="./.clcommitrc"
198 if test $# -gt 0; then
201 *) rc_file="$1"; shift ;;
204 if test -f "$rc_file"; then :; else
205 func_error "rcfile \`$rc_file' does not exist"
209 # The funny quoting allows keeping one option per
211 eval set dummy `echo \`cat $rc_file\` \\\${1+\"\\\$@\"}`
215 -s|--sendmail) test $# = 0 && func_missing_arg $opt && break
216 func_quote_for_eval "$1"
217 sendmail_to="$func_quote_for_eval_result"
221 --signature) test $# = 0 && func_missing_arg $opt && break
222 signature_file="$HOME/.signature"
225 *) signature_file="$1"; shift ;;
227 if test -f "$signature_file"; then :; else
228 func_error "\`$signature_file': file not found"
233 -S|--summary) test $# = 0 && func_missing_arg $opt && break
238 -t|--tla) opt_tla=: ;;
240 -v|--verbose) opt_verbose=: ;;
243 test $# = 0 && func_missing_arg $opt && break
246 *) func_error "invalid argument for $opt"
250 cvs_flags="$cvs_flags -z$1"
254 # Separate optargs to long options:
256 arg=`echo "$opt" | $SED "$my_sed_long_arg"`
257 opt=`echo "$opt" | $SED "$my_sed_long_opt"`
258 set dummy "$opt" "$arg" ${1+"$@"}
262 # Separate optargs to short options:
263 -m*|-F*|-C*|-S*|-s*|-z*)
264 arg=`echo "$opt" |$SED "$my_sed_single_rest"`
265 opt=`echo "$opt" |$SED "$my_sed_single_opt"`
266 set dummy "$opt" "$arg" ${1+"$@"}
270 # Separate non-argument short options:
272 rest=`echo "$opt" |$SED "$my_sed_single_rest"`
273 opt=`echo "$opt" |$SED "$my_sed_single_opt"`
274 set dummy "$opt" "-$rest" ${1+"$@"}
278 -\?|-h) func_usage ;;
280 --version) func_version ;;
282 -*) func_fatal_help "unrecognized option \`$opt'" ;;
283 *) set dummy "$opt" ${1+"$@"}; shift; break ;;
287 if test -z "$sendmail_to"; then
289 # can't have a from address without a destination address
290 test -n "$sendmail_from" &&
291 func_error "can't use --from without --sendmail." && exit_cmd=exit
293 # can't use a signature file without a destination address
294 test -n "$signature_file" &&
295 func_error "can't use --signature without --sendmail." && exit_cmd=exit
298 # Bail if the options were screwed
299 $exit_cmd $EXIT_FAILURE
302 # func_check_conflicts
303 func_check_conflicts ()
305 func_verbose "$progname: checking for conflicts..."
308 while $read_r line; do
312 ) 3>&1 >/dev/null; then
313 func_fatal_error "some conflicts were found with arch archive, aborting..."
317 if test -f CVS/Entries; then
318 if ( $CVS $cvs_flags -q -n update $update_flags ${1+"$@"} |
319 while $read_r line; do
323 ) 3>&1 >/dev/null; then
324 func_fatal_error "some conflicts were found with CVS repository, aborting..."
330 # func_check_commit_msg
331 func_check_commit_msg ()
333 if test -z "$ChangeLog"; then
334 for f in ${1+"$@"}; do
336 ChangeLog* | */ChangeLog*)
337 if test -z "$ChangeLog"; then
340 func_fatal_error "multiple ChangeLog files: $ChangeLog and $f"
347 func_verbose "$progname: checking commit message..."
350 $SED 's,^,+,' < ${ChangeLog-ChangeLog} |
351 while $read_r line; do
353 "+") if $skipping; then skipping=false; else break; fi;;
355 func_error "*** Warning: lines should start with tabs, not spaces; ignoring line:"
356 echo "$line" | $SED 's/^.//' >&2;;
358 $skipping || echo "$line" ;;
361 $SED 's,^\+ ,,' > "$log_file" || exit $EXIT_FAILURE
364 cmd="$TLA file-diffs"
366 cmd="$CVS $cvs_flags diff -u"
368 $cmd ${ChangeLog-ChangeLog} |
369 while $read_r line; do
373 func_error "*** Warning: the following line in ChangeLog diff is suspicious:"
374 echo "$line" | $SED 's/^.//' >&2;;
376 func_error "*** Warning: lines should start with tabs, not spaces; ignoring line:"
377 echo "$line" | $SED 's/^.//' >&2;;
379 "+ "*) echo "$line";;
382 $SED -e 's,\+ ,,' -e '/./p' -e '/./d' -e '1d' -e '$d' > "$log_file" \
383 || exit $EXIT_FAILURE
385 # The sed script above removes "+TAB" from the beginning of a line, then
386 # deletes the first and/or the last line, when they happen to be empty
394 tla_log=`$TLA make-log`
395 test -n "$summary" || summary=`$SED -e '
400 echo "Summary: $summary" > "$tla_log$$T" &&
401 $SED 1d "$tla_log" >> "$tla_log$$T" &&
402 cat < "$log_file" >> "$tla_log$$T" &&
403 mv "$tla_log$$T" "$tla_log"
404 ${PAGER-more} "$tla_log" || exit $EXIT_FAILURE
406 sleep 1 # give the user some time for a ^C
408 # Propagate any user edits back to the cvs log message
409 $SED -e '/^[[A-Z]][[-a-zA-Z]]*:/d' -e '1d' < $tla_log > $log_file
412 ${PAGER-more} "$log_file" || exit $EXIT_FAILURE
414 sleep 1 # give the user some time for a ^C
416 subject=`cvs -nq up 2>/dev/null | $SED -n 's/^[[MAD]] //p'`
417 test $# -gt 0 && subject="$@"
420 if test -f CVS/Entries; then
421 func_verbose "$CVS $cvs_flags commit $commit_flags -F $log_file ${1+$@}"
422 $CVS $cvs_flags commit $commit_flags -F $log_file ${1+"$@"} || exit $EXIT_FAILURE
425 # Need to do the tla commit *after* cvs commit to make sure the
426 # ChangeLog timestamps stay in synch.
427 $opt_tla && $TLA commit
436 notify_file="${log_dir}/notify"
437 func_verbose "Mailing commit notification to $sendmail_to"
440 echo Subject: $subject
441 test -f '{arch}/=tagging-method' &&
442 echo "Tree version: `$TLA tree-version`"
444 echo "CVSROOT: `$SED -e 's,.*:,,g' CVS/Root`"
446 echo "TIMESTAMP: `$SHELL $MKSTAMP < ./ChangeLog`"
447 test -f CVS/Repository &&
448 echo "Module name: `cat CVS/Repository`"
450 echo "Branch: `$SED -e 's,^T,,;1q' CVS/Tag`"
452 echo "Changes by: `$SED -e 's,^:[[a-z]]*:,,;s,:.*$,,g' CVS/Root`"
455 $SED -e 's,^, ,' "$log_file"
456 test -f "$signature_file" && {
458 cat "$signature_file"
462 ${PAGER-more} "$notify_file" || break
464 # Break out the subject line again
465 my_mail_subject=`$SED -e '
470 my_mail_body=`$SED -e '2,$p;d' "$notify_file"`
471 echo "$my_mail_body" > "$notify_file"
473 func_verbose "mailing commit notification to \"$sendmail_to\""
474 func_quote_for_eval "$my_mail_subject"
475 func_show_eval "$MAILNOTIFY $mailnotify_flags \
476 -s $func_quote_for_eval_result -m 'text/plain' -f '$notify_file' \
487 $opt_update && func_check_conflicts
489 test -f "$log_file" || func_check_commit_msg
491 grep '[[^ ]]' < "$log_file" > /dev/null ||
492 func_fatal_error "empty commit message, aborting"
494 if grep '^$' < "$log_file" > /dev/null; then
495 func_error "*** Warning: blank lines should not appear within commit messages."
496 func_error "*** They should be used to separate distinct commits."
499 # Do not check for empty $log_file again, even though the user might have
500 # zeroed it out. If s/he did, it was probably intentional.
502 func_commit ${1+"$@"}
505 # Need to set the subject line *after* tla commit, or the
506 # patch revision changes underneath us!
509 subject="$subject [["`$TLA tree-version|$SED $basename`--`$TLA revisions|$SED -e '$p;d'`"]]"
511 # Send a copy of the log_file if sendmail_to was set:
512 if test -n "$sendmail_to"; then