Renaming the SVN Author

The following Script helps to rename an author in the Subversion log. All operations are done over the SVN protocol so no direct access to the actual repository is needed. The repository must, however, be set up to handle revprop changes. Revprop changes are accepted if the hooks/pre-revprop-change script returns success. This can be simply achieved by putting a "exit 0" as the first code line in the script. Don't forget to delete this statement after the renaming, as it is not a good idea to let users rename the author of commits at their will.

It is called simply like this:

sh svn-rename old_name new_name

And here comes the actual script:

#!/bin/sh
set -e

function usage {
    echo >&2 "usage: $0 old_name new_name"
}


if [ $# -ne 2 ]; then
    usage
    exit 1;
fi
old_name="$1"
new_name="$2"

#change the following variables
svn_url=https://svn.example.come/repo
svn_user=SecretUser
svn_pass=SecretPass
svn_last_rev=`svn log -q -rHEAD "$svn_url" | sed -ne '/^r[0-9]/{ s/^r//; s/ .*//; p; q; }'`


for r in `seq 1 $svn_last_rev`; do
        u=`svn pg svn:author --revprop -r$r "$svn_url"`
        if [ "$u" == "$old_name" ]; then
                svn ps svn:author "$new_name" --revprop -r$r "$svn_url" \
                    --no-auth-cache --username "$svn_user" --password "$svn_pass"
        fi
done

Update 27 July 2008: Fixed a bug in the script. Thanks to Jose Pedro Oliveira.