从SVN存储库获取提交列表并将其显示在自己的应用程序中



我需要实现从SVN存储库检索提交列表并将其显示在网页上的应用程序。

我该怎么做?

我不太明白我应该使用什么。似乎可以使用一些SVN api或库来完成...

(.NET 中的应用程序)

下面是一个漂亮的函数,我用它来从.NET环境执行SVN命令:

// execute a SVN command and fetch the output as a string
private string ExecuteSVNCommandWithOutput(string SVNCommand)
{
string output = "";
try
{
using (Process p = new Process())
{
p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments = "/c " + SVNCommand;
p.StartInfo.RedirectStandardOutput = true; 
p.Start();
output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
}
// unexpected error
catch (Exception ex)
{
output = ex.ToString();
}
return output;
}

出于您的目的,我会执行以下操作来运行svn log

ExecuteSVNCommandWithOutput(@"svn log C:RepositoriesYourRepositoryName");

然后,您可以将字符串输出解析为某种数组或列表。希望这有帮助!

您可以从命令行(或使用 Process 类)调用 svn log (http://svnbook.red-bean.com/en/1.7/svn.ref.svn.c.log.html),将输出重定向到文件,然后打开并解析该文件。

解析默认文本输出并不难,但使用 --xml 选项,可以使用任何 XML 库更轻松地解析文件。

最新更新