* libltdl/m4/libtool.m4 (_LT_SYS_HIDDEN_LIBDEPS): Fix typo.
[libtool.git] / clcommit.m4sh
blob3439dae481fba086ae7c5c60c0f9537c689fbadb
1 m4_define([_m4_divert(SCRIPT)], 100)
2 m4_divert_push([SCRIPT])#!/bin/sh
3 # @configure_input@
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
71 # checked in.
73 # Report bugs to <gary@gnu.org>
75 : ${CVS="cvs"}
76 : ${TLA="tla"}
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"
83 PROGRAM=clcommit
85 AS_SHELL_SANITIZE
86 $as_unset CDPATH
88 m4_include([getopt.m4sh])
90 M4SH_VERBATIM([[
91 # Global variables:
92 cvs_flags=
93 update_flags=
94 commit_flags=
95 opt_commit=:
96 opt_update=:
97 opt_verbose=false
98 opt_first=false
99 opt_tla=false
101 mailnotify_flags=
102 sendmail_to=
103 exit_cmd=:
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
107 then
108   read_r='read -r'
109 else
110   read_r=read
113 # Locations for important files:
114 signature_file=
115 log_dir="`func_mktempdir`"
116 log_file="$log_dir/log"
118 trap '$RM -r "$log_dir"; exit $EXIT_FAILURE' 1 2 15
120 set -e
122 # Parse options once, thoroughly.  This comes as soon as possible in
123 # the script to make things like `clcommit --version' happen quickly.
125   # sed scripts:
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
133     opt="$1"
134     shift
135     case $opt in
137       --debug)          func_echo "enabling shell trace mode"
138                         mailnotify_flags="$mailnotify_flags --debug"
139                         set -x
140                         ;;
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"
149                         shift
150                         ;;
152       -l|--local)       update_flags="$update_flags -l"
153                         commit_flags="$commit_flags -l"
154                         ;;
156       -m|--message|--msg)
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"
160                           break
161                         fi
162                         echo "$1" > "$log_file"
163                         shift
164                         ;;
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"
169                           break
170                         fi
171                         if cat < "$1" > "$log_file"; then :; else
172                           break
173                         fi
174                         shift
175                         ;;
177       -1|--first)       if test -f "$log_File"; then
178                           func_error "you can have at most one of -m, -F and -1"
179                           break
180                         fi
181                         opt_first=:
182                         ;;
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"
188                           break
189                         fi
190                         ChangeLog="$1"
191                         shift
192                         ;;
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
200                           case $1 in
201                             -*)                         ;;
202                             *)  rc_file="$1"; shift     ;;
203                           esac
204                         fi
205                         if test -f "$rc_file"; then :; else
206                           func_error "rcfile \`$rc_file' does not exist"
207                           exit_cmd=exit
208                           break
209                         fi
210                         # The funny quoting allows keeping one option per
211                         # line in $rc_file:
212                         eval set dummy `echo \`cat $rc_file\` \\\${1+\"\\\$@\"}`
213                         shift
214                         ;;
216       -s|--sendmail)    test $# = 0 && func_missing_arg $opt && break
217                         func_quote_for_eval "$1"
218                         sendmail_to="$func_quote_for_eval_result"
219                         shift
220                         ;;
222       --signature)      test $# = 0 && func_missing_arg $opt && break
223                         signature_file="$HOME/.signature"
224                         case $1 in
225                           -*) ;;
226                           *)  signature_file="$1"; shift ;;
227                         esac
228                         if test -f "$signature_file"; then :; else
229                           func_error "\`$signature_file': file not found"
230                           break
231                         fi
232                         ;;
234       -S|--summary)     test $# = 0 && func_missing_arg $opt && break
235                         summary="$1"
236                         shift
237                         ;;
239       -t|--tla)         opt_tla=:                               ;;
241       -v|--verbose)     opt_verbose=:                           ;;
243       -z|--compress)
244                         test $# = 0 && func_missing_arg $opt && break
245                         case "$1" in
246                           [0-9]) :;;
247                           *)  func_error "invalid argument for $opt"
248                               break
249                               ;;
250                         esac
251                         cvs_flags="$cvs_flags -z$1"
252                         shift
253                         ;;
255       # Separate optargs to long options:
256       --*=*)
257                         arg=`echo "$opt" | $SED "$my_sed_long_arg"`
258                         opt=`echo "$opt" | $SED "$my_sed_long_opt"`
259                         set dummy "$opt" "$arg" ${1+"$@"}
260                         shift
261                         ;;
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+"$@"}
268                         shift
269                         ;;
271       # Separate non-argument short options:
272       -f*|-1*|-n*|-q*)
273                         rest=`echo "$opt" |$SED "$my_sed_single_rest"`
274                         opt=`echo "$opt" |$SED "$my_sed_single_opt"`
275                         set dummy "$opt" "-$rest" ${1+"$@"}
276                         shift
277                         ;;
279       -\?|-h)           func_usage                                      ;;
280       --help)           func_help                                       ;;
281       --version)        func_version                                    ;;
282       --)               break                                           ;;
283       -*)               func_fatal_help "unrecognized option \`$opt'"   ;;
284       *)                set dummy "$opt" ${1+"$@"};     shift; break            ;;
285     esac
286   done
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
297   fi
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..."
307     if $opt_tla; then
308       if ( $TLA changes |
309             while $read_r line; do
310               echo "$line"
311               echo "$line" >&3
312             done | grep '^C'
313           ) 3>&1 >/dev/null; then
314         func_fatal_error "some conflicts were found with arch archive, aborting..."
315       fi
316     fi
318     if test -f CVS/Entries; then
319       if ( $CVS $cvs_flags -q -n update $update_flags ${1+"$@"} |
320             while $read_r line; do
321               echo "$line"
322               echo "$line" >&3
323             done | grep '^C'
324           ) 3>&1 >/dev/null; then
325         func_fatal_error "some conflicts were found with CVS repository, aborting..."
326       fi
327     fi
331 # func_check_commit_msg
332 func_check_commit_msg ()
334     if test -z "$ChangeLog"; then
335       for f in ${1+"$@"}; do
336         case "$f" in
337           ChangeLog* | */ChangeLog*)
338             if test -z "$ChangeLog"; then
339               ChangeLog="$f"
340             else
341               func_fatal_error "multiple ChangeLog files: $ChangeLog and $f"
342             fi
343           ;;
344         esac
345       done
346     fi
348     func_verbose "$progname: checking commit message..."
349     if $opt_first; then
350       skipping=:
351       $SED 's,^,+,' < ${ChangeLog-ChangeLog} |
352         while $read_r line; do
353           case "$line" in
354             "+") if $skipping; then skipping=false; else break; fi;;
355             "+ "*)
356               func_error "*** Warning: lines should start with tabs, not spaces; ignoring line:"
357               echo "$line" | $SED 's/^.//' >&2;;
358             "+  "*)
359               $skipping || echo "$line" ;;
360           esac
361         done |
362           $SED 's,^\+   ,,' > "$log_file" || exit $EXIT_FAILURE
363     else
364       if $opt_tla; then
365         cmd="$TLA file-diffs"
366       else
367         cmd="$CVS $cvs_flags diff -u"
368       fi
369       $cmd ${ChangeLog-ChangeLog} |
370         while $read_r line; do
371           case $line in
372             "--- "*) :;;
373             "-"*)
374               func_error "*** Warning: the following line in ChangeLog diff is suspicious:"
375               echo "$line" | $SED 's/^.//' >&2;;
376             "+ "*)
377               func_error "*** Warning: lines should start with tabs, not spaces; ignoring line:"
378               echo "$line" | $SED 's/^.//' >&2;;
379             "+") echo ;;
380             "+  "*) echo "$line";;
381           esac
382         done |
383           $SED -e 's,\+ ,,' -e '/./p' -e '/./d' -e '1d' -e '$d' > "$log_file" \
384       || exit $EXIT_FAILURE
385     fi
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
391 # func_commit
392 func_commit ()
394     if $opt_tla; then
395       tla_log=`$TLA make-log`
396       test -n "$summary" || summary=`$SED -e '
397           1{
398               s/^Summary: *//
399               q
400           }'`
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
412     else
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="$@"
419     fi
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
424     fi
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
430     :
434 # func_mailnotify
435 func_mailnotify ()
437     notify_file="${log_dir}/notify"
438     func_verbose "Mailing commit notification to $sendmail_to"
440     {
441       echo Subject: $subject
442       test -f '{arch}/=tagging-method' &&
443           echo "Tree version:   `$TLA tree-version`"
444       test -f CVS/Root &&
445           echo "CVSROOT:        `$SED -e 's,.*:,,g' CVS/Root`"
446       test -f $MKSTAMP &&
447           echo "TIMESTAMP:      `$SHELL $MKSTAMP < ./ChangeLog`"
448       test -f CVS/Repository &&
449           echo "Module name:    `cat CVS/Repository`"
450       test -f CVS/Tag &&
451           echo "Branch:         `$SED -e 's,^T,,;1q' CVS/Tag`"
452       test -f CVS/Root &&
453           echo "Changes by:     `$SED -e 's,^:[a-z]*:,,;s,:.*$,,g' CVS/Root`"
454       echo ""
455       echo "Log Message:"
456       $SED -e 's,^,     ,' "$log_file"
457       test -f "$signature_file" && {
458         echo '-- '
459         cat "$signature_file"
460       }
461     } > "$notify_file"
463     ${PAGER-more} "$notify_file" || break
465     # Break out the subject line again
466     my_mail_subject=`$SED -e '
467         1{
468             s/^Subject: *//
469             q
470         }' "$notify_file"`
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' \
478         -- $sendmail_to"
483 ## ----- ##
484 ## main. ##
485 ## ----- ##
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."
498   fi
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.
502   if $opt_commit; then
503     func_commit ${1+"$@"}
504   fi
506   # Need to set the subject line *after* tla commit, or the
507   # patch revision changes underneath us!
508   subject="$summary"
509   $opt_tla && \
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
514     func_mailnotify
515   fi
517   $RM -r "$log_dir"
520 exit $EXIT_SUCCESS
522 # Local Variables:
523 # mode:shell-script
524 # sh-indentation:2
525 # End: