#!/bin/sh
#
# VisIt pre-commit hook script.
#
# Subversion requires a specific name for hook scripts.  To avoid getting us in
# a situation where we want to add a pre-commit script, but we've already
# implemented one, this script is a `meta-script' which simply runs others.  To
# add a new hook script, you should add a `runhook' line before the `exit 0' at
# the bottom of this file.  The argument to runhook is a script which must
# reside in the `hooks' directory of our repository.
# All pre-commit scripts take REPOSITORY_PATH and TRANSACTION_ID as arguments,
# in that order.  See the subversion redbook for more information.
#
# Modifications:
#   Mark C. Miller, Tue Dec  9 17:44:24 PST 2008
#   Removed AWK for $2 from svnlook changed output in FLIST
#   Added code to remove FLIST file in case of early exit
#
#   Mark C. Miller, Tue Dec  9 23:03:23 PST 2008
#   Re-factored a lot of code common to hooks to hook_common.sh
#   Re-organized this file a bit. Changed initial svnlook changed
#   command here, to output BOTH file status chars and file names
#   to the FLIST file. Removed check_gpl.sh hook.
#

#
# Set input parameters
#
REPOS="$1"
TXN="$2"

#
# Construct temp. file name to be populated with information
# from this commit.
#
FLIST=/tmp/visit_svn_pre_commit_changed_files_${TXN}.txt
if test -n "$TMPDIR"; then
    FLIST=$TMPDIR/visit_svn_pre_commit_changed_files_${TXN}.txt
fi

#
# Setup variables/functions common to many hook scripts
#
source ${REPOS}/hooks/hook_common.sh

#
# Check that we have valid input parameters
#
if [ -z "${REPOS}" ]; then
    log "Repository path not given, bailing out."
    exit 1
fi
if [ -z "${TXN}" ]; then
    log "Transaction ID not given, bailing out."
    exit 1
fi

function runhook_sh()
{
   TEST="$@"
   sh ${REPOS}/hooks/${TEST} ${REPOS} ${TXN} ${FLIST}
   if [ $? != 0 ]; then
      rm -f ${FLIST}
      exit 1
   fi
}
function runhook_py()
{
   TEST="$@"
   python ${REPOS}/hooks/${TEST} ${REPOS} ${TXN} ${FLIST}
   if [ $? != 0 ]; then
      rm -f ${FLIST}
      exit 1
   fi
}
function runhook_pl()
{
   TEST="$@"
   perl ${REPOS}/hooks/${TEST} ${REPOS} ${TXN} ${FLIST}
   if [ $? != 0 ]; then
      exit 1
   fi
}

#
# Populate ${FLIST} file with list of files being changed (and
# their status chars) in this commit.
#
svnlook changed -t $TXN $REPOS > ${FLIST}

# Unfortunately we want something more warning-esque, which isn't quite
# possible with subversion's hooks.
#runhook_sh "verify_versioning.sh"

# Cyrus says the TRY/ENDTRY test is rejecting too much valid code right now.
# Until we have time to make it a bit smarter, we're disabling that test.
#runhook_py "exceptions.py"

# Check that we're not adding tabs to files
runhook_sh "count_tabs.sh"

# Check for possible dos file format
runhook_sh "check_dos.sh"

# Check for #warning compiler directives
runhook_sh "check_pound_warning.sh"

# Check for abort/exit calls 
runhook_sh "check_abort_calls.sh"

# Check for using statements in header files
runhook_sh "check_using_stmts.sh"

# Check for clases in filename case
runhook_pl "check-case-clashes.pl"

# Clean up
rm -f ${FLIST}

# All checks passed, so allow the commit.
exit 0
