This week I faced the need to edit commit authors. Thanks to the new LDAP authentication, I need to change the way users log on the server. The side effect is the manually declared users differ from the LDAP user names. To keep consistent, I updated the previous commit authors with their new LDAP names. For those who have the same need, I share my script below:
# # Subject: Bash script to update commit authors. # Author: Bruce BUJON (bruce.bujon@gmail.com) # Description: This script use a dictionary (AUTHORS) to replace a Subversion repository commit authors. # Usage: Edit REPOSITORY_PATH and AUTHORS variables then run the script. # # The repository path REPOSITORY_PATH="http://my-repository-url/" # Get the repository head revision HEAD=`svn info $REPOSITORY_PATH | grep Revision: | cut -c11-` # The authors (keys are original authors, values are replaced authors) declare -A AUTHORS AUTHORS=( ["olduser1"]="newuser1" ["olduser2"]="newuser2") # Process each revision up to head for revision in $(seq 1 $HEAD) do echo -n "Processing revision $revision: " # Get revision author author=`svn propget --revprop svn:author -r $revision $REPOSITORY_PATH` # Check if replacement author is available newauthor=${AUTHORS[$author]} if [[ ! -z "$newauthor" ]]; then # Update commit author output=$(svn propset --revprop svn:author $newauthor -r $revision $REPOSITORY_PATH 2>&1) result=$? # Check update status if [ $result != 0 ]; then # An error occurred echo "an error occurred!" echo $output exit -1 else # Author replaced echo "author replaced ($author > $newauthor)." fi else # Author kept echo "author kept." fi done # End of script echo "$HEAD revisions successfully proceed."
Note that you will the server allows revision property changes. To do that, ensure the pre-revprop-change hook return 0, at least the time of the maintenance. You don’t want your users editing the commit authors and logs to make you a joke.