Wednesday, August 17, 2011

How to change all svn:user entry in one go

Over the years, our username has changed. Like over the years I have been avenardj, jyavenard, jeanyves_avenard and finally jean-yves.avenard

In the 7 years I've been using our SVN repository, looking at the history, it's now all over the place.

So I wanted to make my username consistent...

Preliminary steps: allow changing property in the svn repository by adding a hooks/pre-revprop-change file.

it woud contain only one thing:
exit 0

Because in our setup we use ViewVC, we also needed a hooks/post-revprop-change with:


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

/var/www/viewvc/bin/svndbadmin update "$REPOS" "$REV"


I didn't feel like writing much code do to what seemed to be a trivial task.

Looking at various solutions I found this interesting project: XMLSH. Alas, it's quite poorly documented.

After going through the examples, I came up with:



svn log --xml | xread logs
entries=<[ $logs/log/logentry ]>
for entry in $entries; do
rev=<[$entry/@revision]>
echo "entry: " $rev
author=<[$entry/author/string()]>
echo $author
author2=$(echo $author | sed -e 's/(avenardj|jeanyves_avenard|jyavenard)$/jean-yves.avenard/g')
if [ "$author" != "$author2" ]; then
echo " -> $author2"
svn propset --revprop -r $rev svn:author $author2
fi
done


Obviously, replace the regex with the one suitable for you.

No comments:

Post a Comment