]> Frank Brehm's Git Trees - scripts/solaris.git/commitdiff
checkin umgearbeitet
authorFrank Brehm <frank@brehm-online.com>
Thu, 15 Jul 2010 11:24:36 +0000 (11:24 +0000)
committerFrank Brehm <frank@brehm-online.com>
Thu, 15 Jul 2010 11:24:36 +0000 (11:24 +0000)
checkin

diff --git a/checkin b/checkin
index d58868c7ed21b19e95753a09dfaf95f0a379f010..498046dd3a65659b5b54ec62ce1d4ece79baaeb6 100755 (executable)
--- a/checkin
+++ b/checkin
@@ -3,7 +3,7 @@
 # $Id$
 # $URL$
 
-for p in ci rcs rcsdiff stat chmod ; do
+for p in dirname ci rcs rcsdiff stat chmod ; do
        type -p ${p} >/dev/null 
        if [ "$?" != "0" ] ; then
                echo "Command '${p}' not found." >&2
@@ -11,50 +11,184 @@ for p in ci rcs rcsdiff stat chmod ; do
        fi
 done
 
+MSG=
+ALLWAYS_YES=
+VERBOSE=
+
+while getopts ":m:yv" opt; do
+       case $opt in
+               v)
+                       VERBOSE=y
+                       ;;
+               y)
+                       ALLWAYS_YES=y
+                       ;;
+               m)
+                       MSG="$OPTARG"
+                       ;;
+               \?)
+                       echo "Invalid option: -$OPTARG" >&2
+                       exit 1
+                       ;;
+               :)
+                       echo "Option -$OPTARG requires an argument." >&2
+                       exit 1
+                       ;;
+       esac
+done
+
+shift $((OPTIND-1))
+
+#echo "Noch vorhandene Parameter: $@"
+#echo "Zu nehmende Botschaft: '${MSG}'"
+
 for FILE in "$@"; do
 
        if [ ! -e "${FILE}" ] ; then
-               echo
+               if [ -n "${VERBOSE}" ] ; then
+                       echo
+               fi
                echo "File '${FILE}' doesn't exists." >&2
                continue
        fi
 
        if [ ! -f "${FILE}" ] ; then
-               echo
+               if [ -n "${VERBOSE}" ] ; then
+                       echo
+               fi
                echo "File '${FILE}' isn't a normal file." >&2
                continue
        fi
 
        case "${FILE}" in
                *,v)
-                       #echo "File '${FILE}' is a RCS repository." >&2
+                       if [ -n "${VERBOSE}" ] ; then
+                               echo "File '${FILE}' is a RCS repository." >&2
+                       fi
                        continue
                        ;;
        esac
 
-       MSG="Initial"
-       if [ -f "${FILE},v" ] ; then
-               MSG="Checked in."
-               rcsdiff -q "${FILE}" >/dev/null
-               RES="$?"
+       if [ -n "${VERBOSE}" ] ; then
+               echo
+       fi
+
+       CURDIR=$( dirname "${FILE}" )
+       RCS_DIR="${CURDIR}"/.rcs
+       FILE_COPY="${RCS_DIR}"/"$( basename "${FILE}" )"
+       RCS_FILE="${RCS_DIR}"/"$( basename "${FILE}" ),v"
+       RCS_FILE_OLD="${FILE}",v
+
+       if [ -e "${RCS_DIR}" ] ; then
+               if [ ! -d "${RCS_DIR}" ] ; then
+                       echo "Object '${RCS_DIR}' isn't a directory." >&2
+                       continue
+               fi
+       else
+               echo "Creating directory '${RCS_DIR}' ..."
+               mkdir -p "${RCS_DIR}"
+               chmod 700 "${RCS_DIR}"
+       fi
+
+       if [ -f "${RCS_FILE_OLD}" ] ; then
+               if [ -n "${VERBOSE}" ] ; then
+                       echo "Old RCS file '${RCS_FILE_OLD}' exists." >&2
+               fi
+               if [ -f "${RCS_FILE}" ] ; then
+                       echo "Removing old RCS file '${RCS_FILE_OLD}' ..." >&2
+                       rm -f "${RCS_FILE_OLD}"
+               else
+                       echo "Moving '${RCS_FILE_OLD}' to '${RCS_DIR}' ..." >&2
+                       mv -vi "${RCS_FILE_OLD}" "${RCS_FILE}"
+               fi
+       fi
+
+       if [ -n "${VERBOSE}" ] ; then
+               cp -pv "${FILE}" "${FILE_COPY}"
+       else
+               cp -p "${FILE}" "${FILE_COPY}"
+       fi
+
+       USE_MSG="Initial"
+       if [ -f "${RCS_FILE}" ] ; then
+               USE_MSG="Checked in."
+       fi
+       if [ -n "${MSG}" ] ; then
+               USE_MSG="${MSG}"
+       fi
+
+       IS_NEW=
+       if [ -f "${RCS_FILE}" ] ; then
+               if [ -n "${VERBOSE}" ] ; then
+                       echo "rcsdiff \"${FILE_COPY}\""
+                       rcsdiff -q "${FILE_COPY}" >/dev/null
+                       RES="$?"
+               else
+                       rcsdiff -q "${FILE_COPY}" >/dev/null
+                       RES="$?"
+               fi
                if [ "${RES}" = "0" ] ; then
-                       echo
-                       echo "File '${FILE}' wasn't changed." >&2
+                       REVISION=$( rlog -h "${FILE_COPY}" | grep '^head:' | awk '{ print $2}' )
+                       echo "File '${FILE}' wasn't changed, Revision ${REVISION}." >&2
+                       if [ -n "${VERBOSE}" ] ; then
+                               rm -v "${FILE_COPY}"
+                       else
+                               rm "${FILE_COPY}"
+                       fi
                        continue
                fi
+       else
+               if [ -n "${VERBOSE}" ] ; then
+                       echo "Creating new '${RCS_FILE}' ..."
+                       echo "Initialising repository" | rcs -i "${FILE_COPY}"
+               else
+                       echo "Initialising repository" | rcs -i -q "${FILE_COPY}"
+               fi
+               IS_NEW=y
+       fi
+
+       if [ -n "${VERBOSE}" ] ; then
+               echo "Checking in '${FILE}' to '${RCS_FILE}' ..."
+       else
+               echo -n "Checking in '${FILE}' to '${RCS_FILE}' ... "
+       fi
+       PERM=$( stat -c "%a" "${FILE}" )
+       if [ -z "${IS_NEW}" ] ; then
+               if [ -n "${VERBOSE}" ] ; then
+                       echo "    rcs -l \"${FILE_COPY}\""
+                       rcs -l "${FILE_COPY}"
+               else
+                       rcs -q -l "${FILE_COPY}" >/dev/null
+               fi
+       fi
+       if [ -n "${VERBOSE}" ] ; then
+               echo "    echo \"${USE_MSG}\" | ci -u -d \"${FILE_COPY}\""
+               echo "${USE_MSG}" | ci -u -d "${FILE_COPY}"
+       else
+               echo "${USE_MSG}" | ci -u -d -q "${FILE_COPY}"
        fi
 
-       echo
-       echo "Checking in '${FILE}' ..."
-       PERM=`stat -c "%a" "${FILE}"`
-       echo "    rcs -q -l \"${FILE}\""
-       rcs -q -l "${FILE}" >/dev/null
-       echo "    echo \"${MSG}\" | ci -l -d \"${FILE}\""
-       echo "${MSG}" | ci -u -d "${FILE}"
-       echo "    rcs -q -u \"${FILE}\""
-       rcs -q -u "${FILE}" >/dev/null
-       echo "    chmod ${PERM} \"${FILE}\""
-       chmod "${PERM}" "${FILE}"
+       if [ -n "${VERBOSE}" ] ; then
+               echo "    rcs -u \"${FILE_COPY}\""
+               rcs -u "${FILE_COPY}"
+       else
+               rcs -q -u "${FILE_COPY}" >/dev/null
+       fi
+
+       if [ -n "${VERBOSE}" ] ; then
+               echo "    chmod ${PERM} \"${FILE_COPY}\""
+               chmod -v "${PERM}" "${FILE_COPY}"
+               cp -pv "${FILE_COPY}" "${FILE}"
+               rm -v -f "${FILE_COPY}"
+       else
+               chmod "${PERM}" "${FILE_COPY}"
+               cp -p "${FILE_COPY}" "${FILE}"
+               rm -f "${FILE_COPY}"
+       fi
+
+
+       REVISION=$( rlog -h "${FILE_COPY}" | grep '^head:' | awk '{ print $2}' )
+       echo "New Revision: '${REVISION}'"
 
 done