SRCS – log

I am writing a script to simulate a Version Control System.
In SRCS – Check in file – It implements the initial and check in a file.
In SRCS – check out file – It implements check out a file with a specified version.

In this post I will implement a ‘log’ command to allow user to print all the metadata for a file, including a complete version history and the checkin comments.


_PROD="/u01/camel/12.0"
_DEBUG="on"
_LOG="_srcs.log"

fname_srcs="$_PROD/$2"
fname=$(basename "${fname_srcs}")
fdir=`echo "${fname_srcs}" | sed 's/'"$fname"'$//'`
fver="$fdir/RCS/${fname},v"

function DEBUG()
{
	[ "$_DEBUG" == "on" ] && $@ || :
}

if [ $1 == "log" ]; then
	echo "Log for $2 from SRCS..." | tee -a $_LOG
	if [ ! -f "$fver" ]; then
		echo "$fname doesn't exist in SRCS...<FAILED>" | tee -a $_LOG
		exit 1
	else
		if egrep -v "^\s*$" $fver | wc -l | egrep "^0" > /dev/null ; then
			echo "$fname is just initialled in SRCS and has no revision...<FAILED>" | tee -a $_LOG
		else
			logs=`cat $fver | egrep "^version#|comment"`
			echo "$logs" | tee -a $_LOG
		fi
	fi
fi

Test result:

-bash-3.2$ sh srcs.sh log admin/sql/test2.sql
Log for admin/sql/test2.sql from SRCS...
test2.sql is just initialled in SRCS and has no revision...<FAILED>
-bash-3.2$ sh srcs.sh log admin/sql/test3.sql
Log for admin/sql/test3.sql from SRCS...
test3.sql doesn't exist in SRCS...<FAILED>
-bash-3.2$ sh srcs.sh log admin/sql/test1.sql
Log for admin/sql/test1.sql from SRCS...
comment#initial checkin for test1.sql
version#1
comment#hello version 2
version#2
comment#okie, version 3
version#3
comment#i am version 4.
version#4
comment#hello hello version 5
version#5
comment#version 6 here...
version#6
-bash-3.2$