#! /bin/sh # # Recurse from current directory assisting in generating ChangeLog entries # and committing files to the Source Code Repository. # # TODO: # + Currently supports CVS and git. Could add svn # progname=${0##*/} usage() { echo "$progname [-dlq] [-e editor] [-u user] [-m message] [-M msgfile]" echo "options:" echo " -d .. debug, don't delete change files"; echo " -q .. quiet, don't display directories"; echo " -l .. local directory only"; echo " -m message .. text to use for modified files"; echo " -M msgfile .. file containing to use for modified files"; echo " -u user .. use user instead of LOGNAME"; echo " -U user .. use explicit user info -- not from passwd"; echo " -p PR .. PR info"; echo " -c CID .. Coverity Id number"; echo exit 1 } # Determine VCS in use isgit() { depth=0 dir=.git while [ $depth -lt 10 ] do if [ -d ${dir} ] ; then return 1 fi dir=../${dir} depth=`expr ${depth} + 1` done return 0 } isgit if [ $? -eq 1 ] ; then VCS=git elif [ -d CVS ] ; then VCS=cvs else echo "This does not look like a checkout from a VCS I understand." exit 1 fi editor="vim" changefile="changes-xxx" rem_changes="yes" quiet="no" user=$LOGNAME mkchoptions="-n" message= localdir="no" while getopts dlqe:M:m:u:U:p:c: OPT do case "$OPT" in d) rem_changes="yes" ;; e) editor=$OPTARG ;; l) localdir="yes" ;; m) message=$OPTARG ;; M) message=`cat $OPTARG` ;; q) quiet="yes" ;; u) user=$OPTARG ; mkchoptions=${mkchoptions}" -u ${user}" ;; U) userArg="-U" userInfo=$OPTARG ;; p) PrInfo=$OPTARG ; mkchoptions=${mkchoptions}" -p ${PrInfo}" ;; c) CoverityInfo=$OPTARG ; mkchoptions=${mkchoptions}" -c ${CoverityInfo}" ;; *) usage ;; esac done export message let $((shiftcount = $OPTIND - 1)) shift #shiftcount args=$* # find ChangeLogs and print them by depth get_subdirs() { find . -name ChangeLog | while read f do case $1 in */*/*/*/*/*/*/*/*/*) d=9 ;; */*/*/*/*/*/*/*/*) d=8 ;; */*/*/*/*/*/*/*) d=7 ;; */*/*/*/*/*/*) d=6 ;; */*/*/*/*/*) d=5 ;; */*/*/*/*) d=4 ;; */*/*/*) d=3 ;; */*/*) d=2 ;; */*) d=1 ;; *) d=0 ;; esac echo ${d} ${f} done | sort -n -r | cut -d' ' -f2- | while read f do dirname $f done } if [ ${localdir} = "yes" ] ; then subdirs="." else subdirs=`get_subdirs` fi # Make sure we have user information if test "X${userInfo}" = "X" ; then user_name=`grep ^${user} /etc/passwd | cut -d':' -f5 | cut -d',' -f1` if test "X${user_name}" = "X" ; then echo "User information not set" usage fi fi commit_helper() { if [ $? -ne 0 ] ; then return fi prepend ${changefile} # Specify VCS support directory case ${VCS} in cvs) ${CVS} up ChangeLog cvs commit -F ${changefile} ;; git) echo "git commit -F ${changefile}" git add ${changefile} git commit -F ${changefile} ;; *) echo "${VCS} to be implemented" ; exit 1 ;; esac } # Specify VCS support directory case ${VCS} in cvs) VCSDIR=CVS ;; git) VCSDIR=.git ;; *) echo "${VCS} to be implemented" exit 1 ;; esac for ddir in ${subdirs} ; do test "${ddir}" = "${VCSDIR}" && continue test "${ddir}" = "autom4te.cache" && continue test "${ddir}" = "install" && continue if [ -d "${ddir}" ]; then case ${VCS} in cvs) if [ ! -d "${ddir}/${VCSDIR}" ] ; then echo "WARNING - ${ddir} is not in .git" continue fi ;; git) ;; *) echo "${VCS} to be implemented" exit 1 ;; esac test -f "${ddir}/ChangeLog" || continue cd "$ddir" >/dev/null mkChangeLogList ${mkchoptions} ${userArg} "${userInfo}" \ -m "${message}" >${changefile} test $? -ne 0 && continue while test -s ${changefile} ; do fullpath=`pwd` test "$quiet" = "no" && echo "** directory: $fullpath **" cat ${changefile} response="n" read -p "Commit changes? [y/n/e(edit)]: " response case ${response} in y) commit_helper; break ;; n) break ;; e) ${editor} ${changefile} ;; *) echo "*** enter y,n, or e ***" ;; esac done test $rem_changes = "yes" && rm -rf $changefile cd - >/dev/null fi done