April 06, 2006

How to Quickly Deploy Upgrades Using Subversion

Posted at April 6, 2006 03:32 PM in .

If you have ever maintained an application based on open-source software (OSS) or software for which you have the source code available, you have probably performed software upgrades as they become available. This can be a somewhat daunting task, especially if you have made modifications to the source code. However, this can be reduced to a trivial task just by using a code versioning system, such as Subversion (SVN), and employing a logical code tree layout.

In this post, I will demonstrate how to set up a SVN repository to make upgrades a painless task. For sake of a concrete demonstration, I will be using MediaWiki for the example.

We start with a blank SVN root. We issue the following commands:

svn mkdir branches tags
svn commit -m "project layout"
This creates two directories in the project layout and saves the changes to the repository.

Next, we obtain the software distribution.

cd branches
wget http://easynews.dl.sourceforge.net/sourceforge/wikipedia/mediawiki-1.6.0.tar.gz

And uncompress it

tar xvzf mediawiki-1.6.0.tar.gz

You now have the 'mediawiki-1.6.0' directory in your branches directory. Now, let's give it a generic name:

mv mediawiki-1.6.0 vanilla

And add it to the repository:

svn add vanilla

Then commit it:

svn commit -m "Committed 1.6.0 to vanilla branch"

You now have MediaWiki 1.6.0 committed to the repository! We should probably tag it:

svn cp vanilla ../tags/vanilla-1.6.0
svn commit -m "vanilla-1.6.0 tag"

Now, we want to make local modifications to the code to suit our needs. We create a copy of the untouched (vanilla) sources.

svn cp vanilla local

And commit the copy

svn commit -m "copied vanilla branch to local branch"

Now, when you want to make a customization, you just edit the files in the 'local' branch. You NEVER manually edit files in the vanilla branch.

Now comes the fun part, upgrading. We go to the /branches/ directory and obtain MediaWiki 1.6.1:

wget http://easynews.dl.sourceforge.net/sourceforge/wikipedia/mediawiki-1.6.0.tar.gz
tar xvzf mediawiki-1.6.1.tar.gz

We now have MediaWiki 1.6.1 in the mediawiki-1.6.1 directory.

We go into the 'vanilla' branch and issue the following command:

find ./ | grep -v .svn | xargs rm
This deletes all files in this branch that don't describe Subversion state.

Next, we copy all the files from the 1.6.1 vanilla distribution into the vanilla branch:

cp -Rv ../mediawiki-1.6.1/* .

Now, we see what has changed since the last source release:

svn status

Go through the output of `svn status`. The first column describes the state of all files in the vanilla branch. An 'M' means the file has been modified. A '?' means the file is not in the repository. A '!' means the file is in the repository, but not in the local filesystem.

For every file with a '?', you need to run `svn add FILE` where 'FILE' is the filename. For every file with a '!', you need to run 'svn rm FILE`.

Run `svn status` again. The first column should be only the letters 'A', 'M', and 'D'. Once this is done, commit the changes:

svn commit -m "1.6.1 to vanilla branch"
svn cp vanilla ../tags/vanilla-1.6.1
svn commit -m "created vanilla-1.6.1 tag"

Now, the process that took you forever before (upgrading your local version) is going to take a few seconds.

cd local
svn merge ../../tags/vanilla-1.6.0 ../../tags/vanilla-1.6.1
This tells Subversion to look at the changes between the vanilla-1.6.0 and vanilla-1.6.1 tags and apply them to the current repository. Any files added between the two versions will be added to your local branch. Any files deleted, deleted, modified, modified, etc. If you have made significant modifications to your local branch, then Subversion may not be able to apply the changes between versions. In this case, the output of the `svn merge` command will have a 'C' in the first column. This is a change conflict, and you will need to fix these manually.

Once everything in your local branch is set, commit it!

svn commit -m "Applied 1.6.0->1.6.1 vanilla upgrade to local branch"

Congratulations, you have just upgraded your software application in record time!

It is worth noting that if the software application you are upgrading has a Subversion repository itself, then it is even easier to manage your vanilla branch.

Initially, export their code:

svn export http://svn.wikimedia.org/svnroot/mediawiki/tags/REL1_6_0/ vanilla

And import it into your repository:
svn import vanilla
svn commit -m "Imported 1.6.0 into vanilla branch"

For upgrades, do something like the following:


cd vanilla
svn merge http://svn.wikimedia.org/svnroot/mediawiki/tags/REL1_6_0/ http://svn.wikimedia.org/svnroot/mediawiki/tags/REL1_6_1/
svn commit -m "Applied 1.6.0->1.6.1 from upstream svn"

Trackback

You can ping this entry by using http://blog.case.edu/gps10/mt-tb.cgi/7182 .

Comments

Not much on my mind. I don't care. I've just been letting everything happen without me , but shrug. Whatever. I feel like a void.

Posted by Sten8355 at December 27, 2006 02:24 AM

I can't be bothered with anything these days, but such is life. I don't care. So it goes. More or less nothing seems worth thinking about. I've just been hanging out waiting for something to happen, but that's how it is.

Posted by Sten45966 at December 28, 2006 06:48 AM

I haven't been up to much these days. Today was a loss. Nothing seems important. I've just been letting everything happen without me these days.

Posted by Sten30981 at January 8, 2007 06:45 AM

Post a comment










Remember personal info?