#!/bin/bash # Copyright 2003,2004 # by Jim Radford # and David Caldwell # This code can be distributed under the terms of the GNU Public License # Version: 1.1 set -e eval set -- "`getopt -o m: -- "$@"`" while true; do case "$1" in -m) message="$2" ; shift 2 ;; --) shift ; break ;; esac done patch=$1 if [ -z "$patch" -o -n "$2" ]; then echo "usage: $0 [-m ] " exit 1 fi IFS=' ' \ lsdiff=`lsdiff $patch|sort|uniq` #[ $? != 0 ] && exit $?; if [ "x${lsdiff[@]}" = "x" ]; then echo "No files in the patch" exit 1 fi if cvs status ${lsdiff[@]} | grep "Status: Needs" 2>/dev/null; then echo "The above files need to be updated first!" exit 1 fi function clean () { for f in ${clean[@]}; do mv -vfb "$f.orig.$$" "$f" done trap "" INT EXIT echo "$0: failed" exit 1 } trap clean INT EXIT for f in ${lsdiff[@]}; do mv -f "$f" "$f.orig.$$" clean=("${clean[@]}" "$f") done cvs update -C ${lsdiff[@]} # coarse timestamps can keep cvs diff from noticing a patch immediately after and update : $(( i=0 )); touch .a$$ .b$$; until [ .a$$ -nt .b$$ ]; do : $(( i++ )); touch .a$$; done; rm -f .a$$ .b$$; echo $((i)) patch --dry-run -sp0 < $patch patch -p0 < $patch cvs add ${lsdiff[@]} 2>/dev/null || true cvs rm ${lsdiff[@]} 2>/dev/null || true rest=rest.$$.patch > $rest for f in ${lsdiff[@]}; do diff -u "$f" "$f.orig.$$" >> $rest || [ $? = 1 ] done if [ -n "$message" ]; then cvs commit -m "$message" ${lsdiff[@]} else cvs commit ${lsdiff[@]} fi patch -p0 < $rest rm $rest trap "" INT EXIT for f in ${clean[@]}; do rm "$f.orig.$$" done