Skip to content

Release Branches and Bugfixes with Subversion

I’ve finally taken out the time to properly learn about the subversion “trunk, branches, and tags” structure. So while its fresh in my head I thought I’d blog about a common scenario with an extremely contrived example. New to Subversion? Here’s the links that got me started:

  1. Version Control with Subversion – a free book about Subversion.
  2. VisualSVN Server – a simple to use (and free!) Subverion server for Windows.
  3. CollabNet Subversion Downloads – a command line server and client.
  4. TortoiseSVN – a Subversion client, implemented as a windows shell extension.

This is the scenario: You’ve deployed an application to production. A few weeks later development work is continuing on the source tree, when someone finds a bug in production. The development code isn’t ready for production, and hasn’t been tested. So we want to pull out the production version of the source code, apply a bugfix, reapply the fix to the development tree, and roll out the updated production build. This is a very common scenario outlined in the “Version Control with Subversion” book here: Release Branches.

The fix? In short terms Subversion makes this possible with the following steps. Once code is ready for a production deploy we create a production branch “/TurtlesApp/branches/Production”. Any production bugfixes can be carried out in this location and, with the help of Subversion, merged back into the developement tree “/TurtlesApp/trunk”

Step by step: Here’s the extremely contrived application ready to go to production. We’ve created a simple application which reads in an XML file, populates a collection of business objects, and binds this to a GridView.


View Code

Ready for production – create a branch:

Now we have a something that looks like this in the repository:

Work continues in the development trunk, with new features are being added.


View Code

But in production someone has discovered a bug. They’ve attempted to add this line to the XML file:

<Turtle Name="Splinter"/>

The code is crashing out attempting to read the ‘null’ weapon. The development tree hasn’t been tested, and isn’t ready for production (contrived, I tell you!). So the changes can be made in the ‘Production’ branch and merged back into the trunk.

Let’s say we are doing our dev on the “C:\VS2008\TurtlesApp\trunk” folder. We’ve got IIS vdirs pointing at this app, and a number of build scripts expect things to be in this location. This is where the svn switch command comes in handy. Using this command we can replace our code in “C:\VS2008\TurtlesApp\trunk” with the production branch.

The bugfix is a simple test for null:

turtle.Name = (node.Attributes["Name"] != null) ? node.Attributes["Name"].Value : null;
turtle.Weapon = (node.Attributes["Weapon"] != null) ? node.Attributes["Weapon"].Value : null;

Let’s commit this to the “Production” branch, and we are ready to build and deploy.

The bug still exists in our development trunk. Subversion can merge the changes we’ve made in production back into development. In the real world a bugfix could impact any number of source files. I start the merge by first switching my directory back to the trunk, getting an update of the source – always a good convention if you are about change a bunch of files – then do the merge.

So what does the Turtle.cs file look like now with the changes merged in…

Turtle turtle = new Turtle();
turtle.Name = (node.Attributes["Name"] != null) ? node.Attributes["Name"].Value : null;
turtle.Weapon = (node.Attributes["Weapon"] != null) ? node.Attributes["Weapon"].Value : null;
turtle.Nickname = node.Attributes["Nickname"].Value;
turtle.Colour = node.Attributes["Colour"].Value;
results.Add(turtle);

Very cool! Subversion has automatically added our production changes to the development branch!

Amazon Elastic Compute Cloud – EC2

The Amazon Elastic Compute Cloud (EC2 for short) was recently mentioned on the IT Conversations podcast episode A Web-Scale Computing Architecture. EC2 looks very similar to a Virtual Private Server hosting service – where you rent a virtualized server. On top of this service is a webservice giving you the ability to dynamically create, stop and start multiple server instances. Which makes this service an ideal platform for an application with variable load. For example; a concert ticket website could rent an additional 40 servers when a popular concert is about to go on sale. Or dynamically ramp up the number of servers as load increases. The service bills you for hours each instance runs, plus bandwidth. Running a single small instance non stop for one year will cost you approximately $USD876 – so cheaper options exist elsewhere if you don’t need a dynamic number of servers.

Interested enough to check it out? Follow the steps in the Getting Started Guide to fire up your own instance. In the guide you communicate with the ‘cloud’ via a collection of java commandline utilities. The utilities themselves are ulitising the public webservice API. Just like Amazon’s S3, third parties are free to build applications upon the API. RightScale, mentioned in the podcast, uses the public API to deliver an automated cloud computing management system. The Firefox extension for EC2 uses the public API to offer a GUI alternative to the command line utilities.

The Getting Started Guide takes you through the steps of firing up a public instance of a Linux server, making modifications to the instance, then packaging this up as a custom Amazon Machine Image (AMI). The customised AMI is then uploaded to your S3 storage.

This is a very interesting technology from Amazon, I’m intrigued to see what services get built on top the cloud!

PropertyInfo.GetCustomAttributes() Doesn’t Return Inherited Attributes

Here’s a problem I ran into today. If you have an attribute on the property of a base class; are you able to read it via PropertyInfo.GetCustomAttributes on the properties of a subclass.

Here’s where it helps to read the fine print. PropertyInfo.GetCustomAttributes takes a parameter for ‘inherit’ – yet the reference for PropertyInfo contains some important details:

Calling ICustomAttributeProvider.GetCustomAttributes on PropertyInfo when the inherit parameter of GetCustomAttributes is true does not walk the type hierarchy. Use System.Attribute to inherit custom attributes.

The code to read the attributes ended up looking like this:

foreach (PropertyInfo property in type.GetProperties())
{
    // not this one -> property.GetCustomAttributes(true);
    Attribute[] attributes = Attribute.GetCustomAttributes(property);
}

Silverlight Animated Optical Illusion

Spotted this illusion on digg: The anatomy of an illusion — and what it tells us about the visual system. Being the skepical fellow I am – I decided to recreate this illusion.

The animation is simply cycling the colours of inner circles. From/to the frames below.

So, here’s my Silverlight version of the animated illusion. Feeling skeptical yourself? View the source!