Saturday, December 15, 2007

Controlling Subversion Post-Commit Email Size

First off, if that subject line makes no sense to you, you can probably stop reading. This post has no entertainment value whatsoever -- it is entirely practical. It's for people administering the subversion version control system.

Still reading? Okay, here's the problem: like many users of subversion (svn for short) I like getting e-mail diffs from svn after each commit, but sometimes, like after a move, copy, or vendor drop, they are too big. Way too big: they have even caused out of memory conditions on my subversion server. They have sent emails on the order of 12 megs, and that was only limited by the emailer, not by any part of subversion so far as I know.

Why? by default, subversion ships with some hook script templates that you can configure. The templates point to some simple, easy to use perl scripts, so you'd think that's what the subversion developers are endorsing. When I asked about this on the mailing list, I got two responses, both suggested I use something else, and one even used the phrase "bit rot". The take-home message: don't use those perl scripts! Instead, here's a more modern way to get your emails and limit the diff sizes while your at it:


  • Download and unzip the patched mailer script.

  • Check the first line of the script and make sure that it matches the path to python on your system. If not, modify the scrpt, so that it does.

  • As it is, the script omits diffs if they are larger than 50k. If you want to change that, look for and modify the line: MAX_DIFF_SIZE = 50000.

  • Put the patched mailer script somewhere sensible. /usr/local/bin is not bad. ~/bin/ is sensible as well, if your repo is installed somewhere in your home dir.

  • Edit your post-commit hook (in your repository's hooks directory) so that it looks like this:

    /full/path/to/svn-mailer.py commit "$REPOS" "$REV"

  • Now the last step is the tricky one: Somewhere on your system there is a mailer.conf.example file. You can usually find it using "locate mailer.conf.example". Copy that to your subversion repo's conf directory and call it mailer.conf. It is well commented and you should be able to go through and make changes logically, but it pays to be careful. I recommend setting generate_diffs to modify, as that prevents diffs from being generated on files that are simply copied, added or deleted, but people's preferences vary on this one.

  • To test the configuration, run the post-commit script with complete path to the repository and the last revision number as arguments. That should send an email for the last commit.



If you like everything about this except the bit about limiting the diff sizes, you can, of course, use the mailer.py that came with subversion instead of the patched version, just use locate to find it on your system. Everything else stays the same.

For even more control, you can also look into SVN::Notify.

2 comments:

  1. If you are running your SVN install on a windows machine, I have written a tool called Subversion Notify that is an advanced replacement for the SVN:Notify perl script. It is a windows executable that gives you granular control of your repository, not only for e-mails (including limiting the size) but also other pre- and post-commit checks and tasks. Check it out at http://www.SubversionNotify.com

    ReplyDelete
  2. Given link in previous comment is dead.

    ReplyDelete