#!/bin/sh

ROOT_DIR=$(cd ../../..;pwd)
ALL_COMPOS=`cat $ROOT_DIR/amit_priv/CWebUI.90.mk/mk.uicompo|awk -F'[ /]' '{print $1}'`
FILE=$ROOT_DIR/src/amit_priv/CWebUI/changelog

if [ -e $FILE ]; then
	rm $FILE
fi

k=1
for ui in $ALL_COMPOS; do
	echo "check compoment $ui ...."
	
	path_num=`cat $ROOT_DIR/amit_priv/CWebUI.90.mk/mk.uicompo |awk -F'[ /]' 'NR=='$k'{print $3}' |awk -F'-' '{print NF}'`
	if [ "$path_num" == 1 ]; then
		cd $ui;
	else
		cd $ui"_func";
	fi;
	
	chg="`svn st | awk '$1 ~/(A|D|M)/' | awk '{printf $1}'`"
	chgfiles="`svn st | awk '$1 ~/(A|D|M)/' | awk '{printf $2"  "}'`"
	if [ -z $chg ]; then
		echo "$ui: no change"
	else
		printf "\E[0;31;40m"
		echo "$ui: change!   Changed files: $chgfiles"
		printf "\E[0m"
		echo "$ui change" >> $FILE
		read -p "Commit $ui or not? (Y/N): " yn
		if [ "$yn" == "Y" -o "$yn" == "y" ]; then 
			echo "OK, you wanna commit $ui"
			read -p "You need write msg for change log: " log
		        read -p "Check again, Commit $ui? (Y/N): " again
		        if [ "$again" == "Y" -o "$again" == "y" ]; then
                	echo "svn ci -m " $ui ":"  $log
					svn ci -m  "[$ui]: $log"
				echo "$ui commit" >> $FILE
			else
				echo "Skip commit $ui"
                                echo "$ui do not commit" >> $FILE
			fi
		fi
                if [ "$yn" == "N" -o "$yn" == "n" ]; then
			echo "Skip commit $ui"
			echo "$ui do not commit" >> $FILE
		fi
	fi;
	cd ..;
	k=$k+1
done;


