user475108
user475108

Reputation: 31

Read file content directly from SVN repository

I want to write an application which looking from a string token in all of the text files under a specific path of SVN repository, and returns all the files that contain this token. I use sharpsvn for this application. I know how I can get the paths of all files under the root SVN repository path (and its sub folders of course), but I wonder if there is way to read the content of each file directly from the SVN repository without checkout or export them to the computer on which my application run? If there is no such way of reading the content directly from the repository, how do you recommend me to do checkout or export the files smoothly for the purpose of find a specific token in all the files?

Upvotes: 1

Views: 3247

Answers (1)

Patrick Quirk
Patrick Quirk

Reputation: 23747

Use SvnClient.Write with the URL target and read the string from a MemoryStream:

using (var stream = new MemoryStream())
using (SvnClient client = new SvnClient())
{
    string yourUrl = "http://svn.apache.org/repos/asf/subversion/trunk/CHANGES";
    if (client.Write(new SvnUriTarget(yourUrl), stream))
    {
        // reset the position to read from the beginning
        stream.Position = 0;
        using (var reader = new StreamReader(stream))
        {
            string contents = reader.ReadToEnd();

            // find your token
        }
    }
}

Note that this will not be terribly fast as it opens a new connection to the server for each file.

Upvotes: 1

Related Questions