简体   繁体   English

直接从SVN存储库读取文件内容

[英]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. 我想编写一个应用程序,该应用程序从SVN存储库的特定路径下的所有文本文件中的字符串标记中查找,并返回包含该标记的所有文件。 I use sharpsvn for this application. 我为此应用程序使用Sharpsvn。 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? 我知道如何获取根SVN存储库路径(当然还有其子文件夹)下的所有文件的路径,但是我想知道是否有办法直接从SVN存储库中读取每个文件的内容而无需检出或导出它们运行我的应用程序的计算机上? 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? 如果没有这种直接从资源库中读取内容的方法,您如何建议我顺利地结帐或导出文件,以便在所有文件中查找特定令牌?

Use SvnClient.Write with the URL target and read the string from a MemoryStream : SvnClient.Write与URL目标一起使用,并从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. 请注意,这不会很快,因为它将为每个文件打开到服务器的新连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM