Categories
Posts

Setting up SVNSync and SVN-Notify

Long story short, I wanted to get commit emails for a Subversion repo. I don’t have any admin rights to the repo so I figured the easiest way was to just setup a local repo, keep up to date with the live repo with svnsync and then configure svn-notify on my local repo. The local repo is only used for svn-notify, I’m not using it to checkout copies of the code or anything else.

A good resource to getting started with svnsync is http://svn.apache.org/repos/asf/subversion/trunk/notes/svnsync.txt. Go take a look at that first, should make the rest of this easy to follow.

I assume that you already have subversion/svnsync and svn-notify installed and ready to go. I’m not going to cover installing those.

Here are the steps I followed to put this all together, first svnsync:

  1. Create local svn repo: svnadmin create /home/svn/repo-name
  2. Edit /home/svn/repo-name/hooks/pre-revprop-change so that it looks like:

    [sourcecode]
    #!/bin/sh
    USER="$3"

    if [ "$USER" = "svnsync" ]; then exit 0; fi

    echo "Only the svnsync user can change revprops" >&2
    exit 1
    [/sourcecode]

    This limits changes to the local repo to only the ‘svnsync’ user.

  3. Make it executable: chmod +x /home/svn/repo-name/hooks/pre-revprop-change
  4. Initialize the sync between repos: svnsync init – username svnsync file:///home/svn/repo-name http://svn.example.com/repo-name
  5. Run the first sync: svnsync sync file:///home/svn/repo-name
  6. Schedule a cron job to run the sync periodically, say once every hour (on a nice odd number like 17 after the hour): 17 * * * * /usr/local/bin/svnsync – non-interactive sync file:///home/svn/repo-name

With svnsync in place adding svn-notify for our locally synced repo is pretty easy. Edit /home/svn/repo-name/hooks/post-commit to look like:

[sourcecode]
#!/bin/sh

REPOS="$1"
REV="$2"

delayed_notify( ) {
sleep 10

/usr/local/bin/svnnotify –repos-path "$1" –revision "$2"
–to commit-list@example.com
–from commit-list@example.com
–with-diff
–subject-cx
–subject-prefix ‘REPO-NAME ‘
–handler HTML::ColorDiff
}

delayed_notify $1 $2 > /dev/null 2>&1 &
[/sourcecode]

Then make that hook executable: chmod +x /home/svn/repo-name/hooks/post-commit

There are two downsides to this approach. First, the commit emails don’t go out right away after a commit, svnsync has to be run first. In my example above that means it could be an hour after the commit before the email goes out. I don’t consider this a big deal and the gap can be reduced by syncing more often. The second problem bugs me, the user listed for all of the commits is the svnsync user, instead of the actual user that committed the change to the master repo. Since all of the commits are replayed as the svnsync user there doesn’t appear to be an easy way to fix this. If you know of one let me know.

And there we go, now you can get commit emails for a repo that you don’t have any admin rights to. Not glamorous or ideal, but better than nothing.

Update: A big thank you Peter Westwood (a.k.a westi) for suggesting a technique to delay svn-notify long enough for svnsync to finish replaying the rev-prop changes. I tried it out and it solved the problem where all commit emails showed the ‘svnsync’ user for every commit.