#!/bin/sh
# Name : /public/scripts/rollback_chg
# Purpose : rollback from a submitted changelist script
# Arguments: : 1 - a given submitted changelist number.
# By : Yariv Sheizaf
# Date : 21-Jan-2002
echo ""
echo "Submitted changelist number ?"
echo ""
read ANS
CHG=$ANS
p4 change -o $CHG 1>/dev/null 2>&1
if [ "$?" != "0" ]
then
echo ""
echo "Changelist No. "$CHG" is not exist. Exit..."
echo ""
exit 1
fi
ISSUBMITTED=`p4 describe $CHG | /usr/bin/head -1 | awk '{print $NF}'`
if [ "$ISSUBMITTED" = "*pending*" ]
then
echo ""
echo "Changelist No. "$CHG" is still pending. Exit..."
echo ""
exit 1
fi
## Create new pending changelist
p4 change -o $CHG | sed 's/'$CHG'/new/' | p4 change -i > $$.newchg
NEWCHG=`awk '{print $2}' $$.newchg`
for i in `p4 describe -s $CHG | grep "^... //" | awk -F# '{print $1}' | sed 's/... //'`
do
echo ""
echo ""
PREVREV=`p4 describe -s $CHG | grep $i | awk -F# '{print $2}' | awk '{print $1-1}'`
p4 sync $i#$PREVREV
if [ "$PREVREV" = "0" ]
then
p4 sync $i
p4 delete -c $NEWCHG $i
else
p4 edit -c $NEWCHG $i
p4 sync $i
p4 resolve -ay -af $i
fi
done
echo ""
echo "Press any key to continue"
read ANS
p4 submit -c $NEWCHG
rm -f $$.*
exit 0