Skip to main content
Enterprise Agile Planning Image

This post is from the CollabNet VersionOne blog and has not been updated since the original publish date.

Last Updated Apr 17, 2008 — Enterprise Agile Planning expert

SharpSvn Brings Subversion to .NET

Enterprise Agile Planning

CollabNet now hosts and supports AnkhSVN, the Subversion plugin for Visual Studio. Some of our goals are to help the AnkhSVN community grow and accelerate the development of the plugin. To kickstart this, we started by collaboratively creating a roadmap for AnkhSVN. Subversion 1.5 compatibility is number one on that roadmap, including good merge support. To properly support Subversion 1.5, we either needed to update our internal C# Subversion binding (NSvn) or take advantage of SharpSvn, a .NET binding for Subversion. We chose the SharpSvn route. To understand why, let’s learn more about SharpSvn.

SharpSvn is a project started by Bert Huijben, who is also an AnkhSVN committer. The purpose of SharpSvn is not only to bring Subversion’s API to .NET but also to abstract the low-level Subversion API away from the developer while still conforming to Microsoft’s common language specification. The result is that SharpSvn is a Subversion client binding for .NET that works with a .NET 2.0 application or newer.  (Note: Since Subversion 1.5 and its final API is not yet complete, SharpSvn’s APIs can change before the final release.) 

To show the value of what SharpSvn can bring to any .NET-based Subversion application, I created a simple Subversion Log Viewer using SharpSvn.

When you download and view the Log Viewer source, you’ll see a lot of code that is primarily related to the UI and threading. I only use a few of SharpSvn’s classes:

     
  • SharpSvn.SvnTarget: Use this class as a target to run Subversion functionality against.
  •  

  • SharpSvn.UI.SharpSvnUI: This class provides access to SharpSvn’s built-in UI, for example when you are prompted for credentials or need to accept an SSL certificate.
  •  

  • SharpSvn.Client: This is the actual client abstraction that gives you access to Subversion client functionality.
  •  

  • SharpSvn.SvnLogEventArgs: Use this class to handle the events returned by SvnClient.Log().
  •  

  • SharpSvn.SvnChangeItem: Use this class for objects that hold information about changed items retrieved via SvnClient.Log().

span {
font-family: ‘Courier New’;
font-size: 10pt;
color: #000000;
}
.sc0 {
}
.sc2 {
font-family: ‘Comic Sans MS’;
font-size: 8pt;
color: #008000;
}
.sc4 {
color: #FF8000;
}
.sc5 {
font-weight: bold;
color: #0000FF;
}
.sc6 {
color: #808080;
}
.sc10 {
font-weight: bold;
color: #000080;
}
.sc11 {
}
.sc15 {
font-family: ‘Comic Sans MS’;
font-size: 8pt;
color: #008080;
}
.sc16 {
color: #8000FF;
}

And here is a major part of the SharpSvn code in the example:

/// <summary>
/// Retrieves the Subversion log entries and potentially updates the
/// DataGridView in a streaming fashion.
/// </summary>
private void retrieveAndRenderLog() {     .....     // The Subversion target to run log against     SvnTarget target;         // Attempt to create an SvnTarget by parsing the targetPath     if (string.IsNullOrEmpty(targetPath) ||         !SvnTarget.TryParse(targetPath, out target))         {             .....                 // SvnClient is disposable, using makes sure it's disposed every time         using (SvnClient client = new SvnClient())         {             // Bind the SharpSvn UI to our client for SSL certificate and credentials             SharpSvn.UI.SharpSvnUI.Bind(client, this);                          try             {                 // Run the log subcommand                 client.Log(target,                 delegate(object lSender, SvnLogEventArgs le)                 {                     .....                     // Iterate over each changed path for each log entry                     foreach (SvnChangeItem path in le.ChangedPaths)                     {                         tooltip.AppendLine("");                         tooltip.Append(path.Action + " " + path.Path);                                                  if (path.CopyFromRevision != -1)                             tooltip.Append(" (" + path.CopyFromPath +                                 "[" + path.CopyFromRevision + "])");                     }                     ..... 

SharpSvn is very performant and a simple to use API when writing .NET-based Subversion applications.  It is  easy to figure out what classes/APIs are necessary to get things done and the documentation in the SharpSvn project, and help provided on #ankhsvn (the irc.freenode.net channel for AnkhSVN), allowed me to put together the example application in less than an hour.  You will also be happy to know that SharpSvn alleviates the need for you to manually maintain the authentication callbacks, baton objects, aprpools and other low-level things that you are left dealing with while using other language bindings.

The SharpSvn’s client API is completely in sync with the Subversion 1.5 client API and is the core of the future AnkhSVN 2.0 release. The code quality and completeness of SharpSvn is impressive. If you want to get involved with the development of SharpSvn, visit the project on openCollabNet.

More from the Blog

View more
Apr 08, 2021

Making IT services more agile

Enterprise Agile Planning
The agile revolution completely transformed how we create digital prod ...
Read More
Feb 14, 2021

Reflecting on the 20th anniversary of the Agile Manifesto

Enterprise Agile Planning
Over the past 20 years, it’s been amazing to watch an idea from ...
Read More
Feb 08, 2021

How does agile apply to an entire organization?

Enterprise Agile Planning
Before we dive into the main subject of this blog post, it is importan ...
Read More
Feb 03, 2021

It took a pandemic to realize why digital transformation actually matters

Enterprise Agile Planning
Before anyone had ever heard of COVID-19, businesses across the globe ...
Read More
Contact Us