Wednesday 8 July 2009

Subversion Log Queries

I want to show off how good Subversion is as a source control system, and one of it's strengths is the vast amount of information you can get about the code that is in your repository. At a previous employer we had a very cool set of old style ASP pages that tied our source repository to our timesheet system to make some extremely useful reports. To make a start at trying to recreate these reports in subversion, I needed to be able to query the subversion logs.

Rather than relying on having the svn command line client installed, or using SharpSVN which I found a bit unsatisfactory for querying logs I thought I'd have a bash at writing a standalone HTTP client in .Net. After a bit of searching for some documentation, I came up with the following fairly simple code:
static void Main(string[] args)
var sandpiperUri = new Uri(@"");
var request = WebRequest.Create(sandpiperUri + "/!svn/vcc/default");
request.Method = "REPORT";
request.ContentType = "text/xml";
var requestbody = "<S:log-report xmlns:S=\"svn:\"><S:start-revision>2</S:start-revision>" +
request.ContentLength = requestbody.Length;
using (var requestStream = request.GetRequestStream())
using (var writer = new StreamWriter(requestStream))
using (var response = request.GetResponse())
using (var responseStream = response.GetResponseStream())
using (var reader = new StreamReader(response.GetResponseStream()))
This code queries the log of my rarely updated sourceforge project and produces the following results:
<?xml version="1.0" encoding="utf-8"?>
<S:log-report xmlns:S="svn:" xmlns:D="DAV:">
<D:comment>Initial Commit of Pre-Alpha Code</D:comment>
Now all I have to do is parse the ouput and create a nice interface to call the code. Oh yes, and implement some more of the subversion report features.

For information on the subversion http interface see this file:

No comments:

Post a Comment