* libltdl/loaders/preopen.c: Don't allow lt_dlopen if the
[libtool.git] / clcommit.m4sh
blobe8bf3d260bb516c39800415a2f8971b9f049caf4
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 # 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,
27 # 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 "config/$MAILNOTIFY" && MAILNOTIFY="config/$MAILNOTIFY"
81 test -f "config/$MKSTAMP" && MKSTAMP="config/$MKSTAMP"
83 PROGRAM=clcommit
85 AS_SHELL_SANITIZE
86 $as_unset CDPATH
88 m4_include([getopt.m4sh])
90 # Global variables:
91 cvs_flags=
92 update_flags=
93 commit_flags=
94 opt_commit=:
95 opt_update=:
96 opt_verbose=false
97 opt_first=false
98 opt_tla=false
100 mailnotify_flags=
101 sendmail_to=
102 exit_cmd=:
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
106 then
107   read_r='read -r'
108 else
109   read_r=read
112 # Locations for important files:
113 signature_file=
114 log_dir="`func_mktempdir`"
115 log_file="$log_dir/log"
117 trap '$RM -r "$log_dir"; exit $EXIT_FAILURE' 1 2 15
119 set -e
121 # Parse options once, thoroughly.  This comes as soon as possible in
122 # the script to make things like `clcommit --version' happen quickly.
124   # sed scripts:
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
132     opt="$1"
133     shift
134     case $opt in
136       --debug)          func_echo "enabling shell trace mode"
137                         mailnotify_flags="$mailnotify_flags --debug"
138                         set -x
139                         ;;
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"
148                         shift
149                         ;;
151       -l|--local)       update_flags="$update_flags -l"
152                         commit_flags="$commit_flags -l"
153                         ;;
155       -m|--message|--msg)
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"
159                           break
160                         fi
161                         echo "$1" > "$log_file"
162                         shift
163                         ;;
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"
168                           break
169                         fi
170                         if cat < "$1" > "$log_file"; then :; else
171                           break
172                         fi
173                         shift
174                         ;;
176       -1|--first)       if test -f "$log_File"; then
177                           func_error "you can have at most one of -m, -F and -1"
178                           break
179                         fi
180                         opt_first=:
181                         ;;
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"
187                           break
188                         fi
189                         ChangeLog="$1"
190                         shift
191                         ;;
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
199                           case $1 in
200                             -*)                         ;;
201                             *)  rc_file="$1"; shift     ;;
202                           esac
203                         fi
204                         if test -f "$rc_file"; then :; else
205                           func_error "rcfile \`$rc_file' does not exist"
206                           exit_cmd=exit
207                           break
208                         fi
209                         # The funny quoting allows keeping one option per
210                         # line in $rc_file:
211                         eval set dummy `echo \`cat $rc_file\` \\\${1+\"\\\$@\"}`
212                         shift
213                         ;;
215       -s|--sendmail)    test $# = 0 && func_missing_arg $opt && break
216                         func_quote_for_eval "$1"
217                         sendmail_to="$func_quote_for_eval_result"
218                         shift
219                         ;;
221       --signature)      test $# = 0 && func_missing_arg $opt && break
222                         signature_file="$HOME/.signature"
223                         case $1 in
224                           -*) ;;
225                           *)  signature_file="$1"; shift ;;
226                         esac
227                         if test -f "$signature_file"; then :; else
228                           func_error "\`$signature_file': file not found"
229                           break
230                         fi
231                         ;;
233       -S|--summary)     test $# = 0 && func_missing_arg $opt && break
234                         summary="$1"
235                         shift
236                         ;;
238       -t|--tla)         opt_tla=:                               ;;
240       -v|--verbose)     opt_verbose=:                           ;;
242       -z|--compress)
243                         test $# = 0 && func_missing_arg $opt && break
244                         case "$1" in
245                           [[0-9]]) :;;
246                           *)  func_error "invalid argument for $opt"
247                               break
248                               ;;
249                         esac
250                         cvs_flags="$cvs_flags -z$1"
251                         shift
252                         ;;
254       # Separate optargs to long options:
255       --*=*)
256                         arg=`echo "$opt" | $SED "$my_sed_long_arg"`
257                         opt=`echo "$opt" | $SED "$my_sed_long_opt"`
258                         set dummy "$opt" "$arg" ${1+"$@"}
259                         shift
260                         ;;
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+"$@"}
267                         shift
268                         ;;
270       # Separate non-argument short options:
271       -f*|-1*|-n*|-q*)
272                         rest=`echo "$opt" |$SED "$my_sed_single_rest"`
273                         opt=`echo "$opt" |$SED "$my_sed_single_opt"`
274                         set dummy "$opt" "-$rest" ${1+"$@"}
275                         shift
276                         ;;
278       -\?|-h)           func_usage                                      ;;
279       --help)           func_help                                       ;;
280       --version)        func_version                                    ;;
281       --)               break                                           ;;
282       -*)               func_fatal_help "unrecognized option \`$opt'"   ;;
283       *)                set dummy "$opt" ${1+"$@"};     shift; break            ;;
284     esac
285   done
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
296   fi
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..."
306     if $opt_tla; then
307       if ( $TLA changes |
308             while $read_r line; do
309               echo "$line"
310               echo "$line" >&3
311             done | grep '^C'
312           ) 3>&1 >/dev/null; then
313         func_fatal_error "some conflicts were found with arch archive, aborting..."
314       fi
315     fi
317     if test -f CVS/Entries; then
318       if ( $CVS $cvs_flags -q -n update $update_flags ${1+"$@"} |
319             while $read_r line; do
320               echo "$line"
321               echo "$line" >&3
322             done | grep '^C'
323           ) 3>&1 >/dev/null; then
324         func_fatal_error "some conflicts were found with CVS repository, aborting..."
325       fi
326     fi
330 # func_check_commit_msg
331 func_check_commit_msg ()
333     if test -z "$ChangeLog"; then
334       for f in ${1+"$@"}; do
335         case "$f" in
336           ChangeLog* | */ChangeLog*)
337             if test -z "$ChangeLog"; then
338               ChangeLog="$f"
339             else
340               func_fatal_error "multiple ChangeLog files: $ChangeLog and $f"
341             fi
342           ;;
343         esac
344       done
345     fi
347     func_verbose "$progname: checking commit message..."
348     if $opt_first; then
349       skipping=:
350       $SED 's,^,+,' < ${ChangeLog-ChangeLog} |
351         while $read_r line; do
352           case "$line" in
353             "+") if $skipping; then skipping=false; else break; fi;;
354             "+ "*)
355               func_error "*** Warning: lines should start with tabs, not spaces; ignoring line:"
356               echo "$line" | $SED 's/^.//' >&2;;
357             "+  "*)
358               $skipping || echo "$line" ;;
359           esac
360         done |
361           $SED 's,^\+   ,,' > "$log_file" || exit $EXIT_FAILURE
362     else
363       if $opt_tla; then
364         cmd="$TLA file-diffs"
365       else
366         cmd="$CVS $cvs_flags diff -u"
367       fi
368       $cmd ${ChangeLog-ChangeLog} |
369         while $read_r line; do
370           case $line in
371             "--- "*) :;;
372             "-"*)
373               func_error "*** Warning: the following line in ChangeLog diff is suspicious:"
374               echo "$line" | $SED 's/^.//' >&2;;
375             "+ "*)
376               func_error "*** Warning: lines should start with tabs, not spaces; ignoring line:"
377               echo "$line" | $SED 's/^.//' >&2;;
378             "+") echo ;;
379             "+  "*) echo "$line";;
380           esac
381         done |
382           $SED -e 's,\+ ,,' -e '/./p' -e '/./d' -e '1d' -e '$d' > "$log_file" \
383       || exit $EXIT_FAILURE
384     fi
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
390 # func_commit
391 func_commit ()
393     if $opt_tla; then
394       tla_log=`$TLA make-log`
395       test -n "$summary" || summary=`$SED -e '
396           1{
397               s/^Summary: *//
398               q
399           }'`
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
411     else
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="$@"
418     fi
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
423     fi
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
429     :
433 # func_mailnotify
434 func_mailnotify ()
436     notify_file="${log_dir}/notify"
437     func_verbose "Mailing commit notification to $sendmail_to"
439     {
440       echo Subject: $subject
441       test -f '{arch}/=tagging-method' &&
442           echo "Tree version:   `$TLA tree-version`"
443       test -f CVS/Root &&
444           echo "CVSROOT:        `$SED -e 's,.*:,,g' CVS/Root`"
445       test -f $MKSTAMP &&
446           echo "TIMESTAMP:      `$SHELL $MKSTAMP < ./ChangeLog`"
447       test -f CVS/Repository &&
448           echo "Module name:    `cat CVS/Repository`"
449       test -f CVS/Tag &&
450           echo "Branch:         `$SED -e 's,^T,,;1q' CVS/Tag`"
451       test -f CVS/Root &&
452           echo "Changes by:     `$SED -e 's,^:[[a-z]]*:,,;s,:.*$,,g' CVS/Root`"
453       echo ""
454       echo "Log Message:"
455       $SED -e 's,^,     ,' "$log_file"
456       test -f "$signature_file" && {
457         echo '-- '
458         cat "$signature_file"
459       }
460     } > "$notify_file"
462     ${PAGER-more} "$notify_file" || break
464     # Break out the subject line again
465     my_mail_subject=`$SED -e '
466         1{
467             s/^Subject: *//
468             q
469         }' "$notify_file"`
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' \
477         -- $sendmail_to"
482 ## ----- ##
483 ## main. ##
484 ## ----- ##
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."
497   fi
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.
501   if $opt_commit; then
502     func_commit ${1+"$@"}
503   fi
505   # Need to set the subject line *after* tla commit, or the
506   # patch revision changes underneath us!
507   subject="$summary"
508   $opt_tla && \
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
513     func_mailnotify
514   fi
516   $RM -r "$log_dir"
519 exit $EXIT_SUCCESS
521 # Local Variables:
522 # mode:shell-script
523 # sh-indentation:2
524 # End: