Oct 23, 2008

Enable Edit Log Message in Subversion

In Subversion, when you commit the changeset, you're not allow to edit the log message but the SVN admin with svn-admin command.
To enable it to user, you (the SVN admin) must enable the pre-prop-change hook

pre-prop-change.bat (Windows)
Here is the content of pre-prop-change hook, just save it to pre-prop-change.bat and copy it into SVN hook folder. The content is Windows batch file and just for Windows environment

The script will enable the owner of the revision and the owner of SVN to change the log message.

The owner of SVN is get from SVN auth file (authz-svn.conf) and should be configure in the form @svn_owner = userA, userB...

You need to edit the PATH to authz-svn.conf file

@ECHO OFF
:: Set all parameters. Even though most are not used, in case you want to add
:: changes that allow, for example, editing of the author or addition of log messages.
set repository=%1
set revision=%2
set userName=%3
set propertyName=%4
set action=%5

:: Only allow the log message to be changed, but not author, etc.
if /I not "%propertyName%" == "svn:log" goto ERROR_PROPNAME

:: Only allow modification of a log message, not addition or deletion.
if /I not "%action%" == "M" goto ERROR_ACTION

:: Make sure that the new svn:log message is not empty.
set bIsEmpty=true
for /f "tokens=*" %%g in ('find /V ""') do (
set bIsEmpty=false
)
if "%bIsEmpty%" == "true" goto ERROR_EMPTY

FOR /F "tokens=*" %%a IN ('svnlook author "%repository%" -r %revision%') DO set REV_USER=%%a

FOR /F "delims== tokens=1*" %%a IN (%repository%\..\Permission\authz-svn.conf) DO if "%%a"=="svn_owner " ( set SVN_OWNER=%%b )

set bIsOK=false
FOR %%a IN (%SVN_OWNER%) DO if "%%a"=="%userName%" ( set bIsOK=true )
if "%bIsOK%"=="false" (
goto ERROR_AUTHOR
)

goto :eof

:ERROR_AUTHOR
echo You must be the author of the log message or owner of the repository %SVN_OWNER% %userName%. >&2
goto ERROR_EXIT

:ERROR_EMPTY
echo Empty svn:log messages are not allowed. >&2
goto ERROR_EXIT

:ERROR_PROPNAME
echo Only changes to svn:log messages are allowed. >&2
goto ERROR_EXIT

:ERROR_ACTION
echo Only modifications to svn:log revision properties are allowed. >&2
goto ERROR_EXIT

:ERROR_EXIT
exit /b 1

pre-prop-change (Linux)
The following is the script in Linux, it just allow the owner of the revision to change the log.

#!/bin/sh

REPOS="$1"
REV="$2"
USER="$3"
PROPNAME="$4"
ACTION="$5"

if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ];
then
REV_USER=`svnlook author "$REPOS" -r $REV`
if [ "$REV_USER" = "$USER" ];
then
exit 0;
else
echo "You must be the owner of the revision to be able to change the svn:log property" >&2
exit 1
fi
fi

echo "Changing revision properties other than svn:log is prohibited" >&2
exit 1
Post a Comment