By default all hook scripts are disabled. In order to enable any of them, we have to create an executable file in hooks subdirectory of the repository named after the event. In our case, the name if the file will be pre-commit and will execute a Python script:
#!/bin/sh REPO="$1" TXN="$2" /usr/local/bin/python `dirname $0`/vania_logcheck.py \ -r $REPO -t $TXN || exit 1 exit 0
The location of the repository and the name of the transaction are passed to the scrip as parameters.
All hooks script are executed with and empty environment for security reasons, so all external programs must be specified with their absolute names.
The Python script uses svn, svn.core, svn.fs and svn.repos Python modules, which are provided by Subversion. It works in the following way: first, it extracts the log message for the transaction, next, it reads the regular expression from a file, and third, it checks if the message matches the regular expression. If it does not match, the script terminates with error code bigger than zero. The log message for the transaction is executed in the following way:
def get_log_message(repository_path, transaction_name): repository = svn.repos.open(repository_path) repository_fs = svn.repos.fs(repository) transaction = svn.fs.open_txn(repository_fs, transaction_name) return svn.fs.txn_prop(transaction, svn.core.SVN_PROP_REVISION_LOG)