I’m not quite done with Subversion yet and have a few more tutorial-type entries planned over the next while provided the day-to-day comings and goings don’t get too much in the way along with finally getting an article I’ve been very, very slowly chipping away at (sorry Caroline!) for the last few months out the door and onto the editor’s desk.
That said, today I want to cover a simple nicety you can add to your Subversion install allowing you to more easily stay on top of incoming changes. This is particularly useful when more than one person has commit access to a project.
Getting Our Tools Together
To accomplish our goal of having an RSS or Atom-formatted XML file of repository changes output, the first thing we need to do is grab a copy of svn2feed.py, a hook script that will do the heavy lifting for us.
You can download svn2feed.py here (Right or Control-click and choose “Download Linked File” from the contextual menu).
Now that you have the file downloaded to your Desktop, using the Terminal, copy (or move) the file to the “hooks” directory in your repository. Using the example from the previous tutorials, let’s assume that is
Note that there’s a “hooks” directory in each versioned project, but also a global one for the repository itself which is the one we’re interested in.
sudo mv ~/Desktop/svn2feed.py /usr/local/svn/hooks/
Next, change the file permissions on the script to ensure it is executable.
sudo chmod ugo+x
Our script to do most of the work is now in place. Next we need to create a post-commit script which will be executed - you guessed it, after a user commits a change to Subversion.
In this case, we’re only interested in generating a feed for one project in the repository. Using our previous example, let’s create a new file called
/usr/local/svn/metropolis_blog/hooks/ and open it in your preferred text editor.
Take the contents below and copy/paste it into your
--feed-file "/Library/WebServer/Documents/rss/svn.xml" "$REPOS" &
You can see the full documentation for what each of these items do in the svn2feed.py script, but the gist of it is that we’re telling the script to execute
svn2feed.py using Python (which is installed by default on Mac OS X), keep the last 100 entries, use the Atom format, set the revision number based on the commit, set a permalink using the item-url, the full address of the feed itself via http, and where to actually save the XML file that gets output.
The REPOS variable is the path to your project in the repository.
Save the changes and close the file. We’re almost done.
Creating The Output Directory
Lastly, create the
rss directory on your web server (eg. in /Library/WebServer/Documents) and make sure it is writeable by the script.
You’re now ready and can easily verify that everything is functioning by committing a change to the repository. If no XML file is output, odds are that the permissions are not set correctly. Assuming everything works as it should, simply subscribe to your RSS or ATOM feed and enjoy!
Before I forget, you might want to make sure Apache is running prior to attempting to subscribe to the feed ;-)