Archive for the ‘Subversion’ Category

Setting Up Local Source Control With Subversion

Saturday, December 19th, 2009

I love source control, but I tend not to use it for my “at-home” development for the simple fact that setting up a separate server is overkill, and I don’t like to have random server processes running on my personal machine.  Unfortunately, this means that I lose out on my favorite use for source control – the ability to test and try out new code and features without worrying about screwing up the “main” development.

However, after recently spending a fair amount of time undoing and redoing some changes to a website I am working on, I have decided that enough is enough, and I set out to install a local source control system on my development computer.

Initially I decided to look into Git.  It certainly seemed to fit my need, so I began to look into using it.  It wasn’t long before I realized that I had to get a “special” version of git to run on my windows box.  This was less than ideal for me, especially when  began reading about how much work was left to be done on the Windows version.  The last thing I need is an unstable version control system.

After having experienced a failure in my attempt to use the new and exciting tools (and yes, I am aware of Mercurial – it certainly seemed like a better fit for me), I decided to try to see if I could get the tried and true Subversion to do what I wanted.  It took me all of about 5 minutes of searching to determine that I could in fact use subversion to access a local repository, with no need for for a server or network access.

This was perfect.  I downloaded the Tortoise-SVN client, and sure enough there was an option right there in the client to create a local repository.

Context menu for Tortoise SVN

So I created a folder (“c:\svn”) off my root and created a repository there.  All that was left was to import my existing files into the repository.  Again, tortoise-svn made it simple.  I navigated to the root of the project I wanted to add, selected the root folder, and chose the “import” item.

Tortoise-SVN Import Dialog

Unfortunately, this is where I hit my first snag.  According to the documentation, to connect to a local repository, you simply use the “file://” protocol, followed by the full path to the desired repository directory (in my case, “c:\svn”).  So, I attempted the url “file://c:\svn\”, but received an error:

Unable to open an ra_local session to URL
Unable to open repository ‘file://c:/svn/’

This was not a very helpful error.  I knew the repository existed at the location “c:\svn”, but how could I connect to it?  Looking online for the error message did not seem to provide much in the way of resolution for me, so I began to try various combinations of the protocol and the path.  Finally, I found that “file://” plus “/svn/” successfully connected.  In hind-sight it seemed obvious subversion would expect a linux-style notation, but the examples I found online all used a windows-style volume and path notation.

Once I had imported my existing data into the repository, all that remained was for me to check out a copy back into my original directory.

Tortoise-SVN Checkout

Clicking OK popped up a warning that the directory was not empty, which I accepted, and the files were all “checked out” from the repository and were ready to be worked on.

That’s all there was to it.  I now have a fully working local source control client without the need for a server.

Working on a few things

Thursday, January 15th, 2009

So I’m going to go dark for a few days here.? There are a couple of reasons – one is that I want to take the time to put together a first cut at the estimation tool.? Don’t worry, I’ll post the updates for everyone to see, but I want to set aside the next few days to iron out the details of the design and put together a mock-up of how I want it to work.

I have also decided that I need to generalize the Subversion Hook I wrote for work.? A few more situations have come up that are demanding a more flexible solution than I threw together the other night, so I’m going to work on a generic solution in my own time and post it on here when its complete.

So, I’ll be back on Monday or Tuesday, hopefully with some new goodies to play with.

Subversion, Command Line, and Redirecting the Standard Output

Tuesday, January 13th, 2009

I'm going to interrupt my estimation tool project in order to comment about an interesting mini-project that I finished last night.? Being a big fan of code reviews, I have recently managed to convince my team at work to require reviews for all code checked into the main repository.? Once I had everyone on board, I used a handy subversion hook provided by our review tool to enforce our new review policy.? This has worked well for the past month or two, until just recently when our project began to move into the pre-release testing phase.

The problem is that we have a large number of test models and the inability to commit new models without a review was beginning to hold up our progress on testing.? So it was requested that I exclude the test model directory from the review requirement.? It sounded pretty simple, so the first thing I tried was to look at the hook provided by our review tool to determine if I could have it exclude files or directories.? Unfortunately, it couldn't.? A quick web search turned up nothing resembling the hook I needed, so this left me with only one basic recourse – write my own.? Besides, it was an interesting diversion from my usual responsibilities.

Since we use subversion, setting up the hook was simple.? Essentially, I edited the pre-commit template to first call my own custom application that would determine if the changes being committed could be excluded from the review requirement.? If they could not be excluded, I called the review hook.? Simple, except I still had to figure out how to find out which files were being changed and figure out how to access that information programmatically.

The first problem was easy – SVNLook was made for just this occurrence.? With it you can discover a wealth of information about a given transaction.? The problem is that it is a command-line application that writes its output to Standard Out.? Of course, I know all about the theory of redirecting the standard output and so forth, but having spent my entire career doing graphical desktop and web-based applications, I had never had the chance to actually attempt it.

Fortunately, C# makes the entire process ridiculously easy:

????? System.Diagnostics.Process svnLook = new System.Diagnostics.Process();
????? svnLook.StartInfo.FileName = "svnlook.exe";
????? svnLook.StartInfo.UseShellExecute = false;
????? svnLook.StartInfo.RedirectStandardOutput = true;
????? svnLook.Start();
????? string output = svnLook.StandardOutput.ReadToEnd();

?

That's all there is to it.? The local variable “output” holds the entire output of the svnlook program.? The ReadToEnd method is useful because it blocks until the stream is closed, allowing you to block until the execution is complete.

There are other ways to do this (such as using the System.Console.SetOut method), but this was by far the easiest method I found.? Note that you must set the UseShellExecute property to false if you redirect the standard output, otherwise you will get an invalid operation exception (according to the documentation).

All things told, it was a refreshing change of pace for me, and a fun way to spend an hour or so at work.? I may even write and post a full-featured hook one of these days (of course, I'd probably use a different language to make it as portable as possible). In the meantime, I guess I should get back to my own mini-project…