【问题标题】:Read file content directly from SVN repository直接从 SVN 存储库读取文件内容
【发布时间】:2014-09-26 02:30:29
【问题描述】:

我想编写一个应用程序,它从 SVN 存储库的特定路径下的所有文本文件中的字符串令牌中查找,并返回包含此令牌的所有文件。我在这个应用程序中使用了 sharpsvn。我知道如何获取根 SVN 存储库路径(当然还有它的子文件夹)下所有文件的路径,但我想知道是否有办法直接从 SVN 存储库读取每个文件的内容而无需签出或导出它们到运行我的应用程序的计算机? 如果没有这种直接从存储库中读取内容的方法,您建议我如何顺利签出或导出文件,以便在所有文件中找到特定的令牌?

【问题讨论】:

标签: c# .net svn sharpsvn


【解决方案1】:

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
        }
    }
}

请注意,这不会非常快,因为它会为每个文件打开到服务器的新连接。

【讨论】:

  • 确认这仍然有效,但请注意stream.Position = 0; 是使其正常工作的关键。否则,它返回一个空字符串
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-21
  • 2017-06-18
  • 1970-01-01
相关资源
最近更新 更多