CollabNet
Submerged - CollabNet's Subversion Blog
CollabNet Community

CollabNet Blogs

  • Submerged Home
  • CollabNet Home
  • openCollabNet

Categories

  • Administration (8)
  • Client Tools (9)
  • General (30)
  • Subversion Client (23)
  • Subversion Events (2)
  • Subversion in the Enterprise (26)
  • Subversion Server (14)

Past 6 Months

  • May 2008 (2)
  • April 2008 (2)
  • March 2008 (3)
  • February 2008 (3)
  • January 2008 (4)
  • December 2007 (2)

Archives

All Archives...
RSS Syndicate this blog

SharpSvn Brings Subversion to .NET

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().

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.

Jeremy Whitlock

About the Author

Jeremy Whitlock is a sofware developer in CollabNet's Subversion Engineering team. He is also an open source advocate who contributes to many projects. Jeremy loves playing video games and still continues to be amazed at the personal growth of his three year old son.
Permalink
Categories: General

TrackBack

TrackBack URL for this post: http://www.typepad.com/t/trackback/2278052/28186300

Comments

Great article - I found it really helpful. Thx

Przemek | May 11, 2008 at 04:50 PM

Awesome, my c# project uses Subversion as a wiki content management system and we have always had to rely on wrapping the command line output for all svn interactions. It works fine except that the performance isn't great and you have to do all the hard work getting data into a meaningful format.

Scott | May 12, 2008 at 03:43 PM

Post a comment

  • ©2008 CollabNet Corporation
    • Site Feedback
    • Terms of Use
    • Privacy Policy
    • Copyright & Trademark