tags:

views:

364

answers:

1

I'm looking for a faster way to retrieve files from SVN than svn cat in .NET.

Currently I'm running a svn cat process for each revision, but it's extremely slow.

Then I've tried with SvnClient:

    Stream st = Console.OpenStandardOutput();

    SvnWriteArgs wargs = new SvnWriteArgs();

    for (int i = 3140; i < 3155; ++i)
    {
        wargs.Revision = i;

        client.Write(new SvnUriTarget("http://filezilla.svn.sourceforge.net/svnroot/filezilla/FileZilla3/trunk/README"), st, wargs);
    }
    st.Flush();

But each iteration is even slower than svn cat.

Is there a way in SvnClient to "reuse" a previously opened connection to the SVN server so that a multiple cat operation can be run faster?

+3  A: 

You can use the FileVersions command to do this. This fetches one complete file, and all other files using the differences between each revision in a single connection. This should give a nice performance boost.

public void WriteRevisions(SvnTarget target, SvnRevision from, SvnRevision to)
{
    using(SvnClient client = new SvnClient())
    {
        SvnFileVersionsArgs ea = new SvnFileVersionsArgs 
            {
                Start = from,
                End = to
            };

        client.FileVersions(target, ea,
            delegate(object sender2, SvnFileVersionEventArgs e)
                {
                    Debug.WriteLine(e.Revision);
                    e2.WriteTo(...);
                 });
    }
}

This requires a server that supports this feature. I'm not quite sure when it was introduced, but Codeplex running SvnBridge for instance doesn't support it. If I remember correctly the delegate is called only once in that case, in that case you'll have to revert to you first solution. Under normal circumstance the delegate is called for each revision between Start and End.

See method WalkMe (and others) in this testcase to see more details about its usage (Username guest, no password).

Sander Rijken