#!/bin/sh -u # # Update a file, edit it, run a commit, commit the file. # - Cameron Simpson 05mar1997 # cmd=`basename "$0"` usage="Usage: $cmd [-f] [-m logmessage] [arg1-options] [--] file [command [args...]] Normally the filename will be appended as the last argument to the supplied command. The arg1-options may be used to change this. -f Command is a filter. The file will be edited with filteredit. The filename will not be attached to the command. -m logmessage Specify log message. Default from \$CVSEDIT_MSG. --log Log cvs diff to bug systems (default). --no-log Don't log the diff. --log-terse Make the diff terse (drop context lines). --diff Display cvs diff after edit (default). --no-diff No diff listing." msg=${CVSEDIT_MSG-''} if [ -n "$msg" ] then havemsg=1 else havemsg= fi dodiff=1 dolog=1 arg1opts=-end isfilter= cvsdiffgrep='' badopts= while : do case $1 in -[0-9]*|-end|-discard) arg1opts="$arg1opts $1" ;; -f) isfilter=1 ;; -m) havemsg=1 msg=$2; shift ;; --log) dolog=1 ;; --no-log) dolog= ;; --log-terse)dolog=1 cvsdiffgrep='^[^ ]' ;; --diff) dodiff=1 ;; --no-diff) dodiff= ;; -?*) echo "$cmd: unrecognised option: $1" >&2; badopts=1 ;; --) shift; break ;; *) break ;; esac shift done if [ $# = 0 ] then echo "$cmd: missing file" >&2 badopts=1 else file=$1 shift fi [ $badopts ] && { echo "$usage" >&2; exit 2; } if [ ! -f "$file" ] then echo "$cmd: $file: not a regular file" >&2 exit 1 fi ifcvs "$file" || { echo "$cmd: not a CVS file: $file" >&2 exit 1 } umask 2 dir=`dirname "$file"` base=`basename "$file"` [ $# = 0 ] && set -- "${EDITOR-vi}" ( cd "$dir" || exit 1 cvs update "$base" || exit $? cvs diff "$base" || { echo "Uncommited changes already exist in $base." >&2 echo "Please commit them before proceeding." >&2 exit 1 } [ ! -d CVS/Base ] || cvs edit "$base" || exit $? chmod +w "$base" ) || exit 1 ( set -x if [ $isfilter ] then exec filteredit $arg1opts -discard -- "$file" "$@" else exec arg1 $arg1opts -- "$file" "$@" fi ) editxit=$? [ $dodiff ] \ && ( cd "$dir" || exit 1 cvs diff "$base" ) [ $editxit = 0 ] \ || { [ -t 0 ] && ask "$* failed - really commit the file"; } \ || exit 1 [ $havemsg ] \ || { [ -t 0 ] && { msg=`readline "Log message> "` && [ -n "$msg" ]; }; } \ || { echo "$cmd: commit cancelled - file in modified state" >&2 exit 1 } # log the change and diff appropriately [ $dolog ] && cvs diff "$file" | grep "$cvsdiffgrep" | execif buglog "cvsedit $base: $msg" ( cd "$dir" || exit 1 exec cvs commit -m "$msg" "$base" )