【问题标题】:Best way to check SVN revision changes of directory and return if changes are found检查目录的SVN修订更改并在发现更改时返回的最佳方法
【发布时间】:2016-09-12 16:50:49
【问题描述】:

我一直在寻找有关如何检查修订并在有更改时返回的问题。我有什么工作,但我想知道是否有更好/更清洁的方法:

bool needToUpdate = false;
Process process = new Process();
var info = new ProcessStartInfo("svn", string.Format(@"status -u {0}", directoryInto.FullName));
process.StartInfo = info;
process.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
{
    if (!String.IsNullOrEmpty(e.Data))
    {
        string data = e.Data;
        //This if statement is what I have an issue with.
        if (data.Contains("!"))
            needToUpdate = true;
    }
});

如您所见,我正在检查字符串以在字符串中找到 (!)。这不是很好的做法,所以我看看是否有人能够帮助我提供更好的解决方案或更好的方法来接收来自 SVN 的标准输出(我不是在问如何去做,我是在问比我已经拥有的更好的方法)我将不胜感激!

谢谢!

编辑使用 SharpSVN


我现在正在使用 SharpSVN,但 IsRemoteUpdate 出现问题,它似乎总是返回 true:

bool needToUpdate = false;
using (SvnClient client = new SvnClient())
{
    SvnStatusArgs statusArgs = new SvnStatusArgs();
    statusArgs.RetrieveAllEntries = true;
    statusArgs.RetrieveRemoteStatus = true;
    client.GetStatus(directoryInto.FullName, statusArgs, out statuses);
    for (int i = 0; i < statuses.Count(); i++)
    {
        if (statuses[i].IsRemoteUpdated)
        {
            needToUpdate = true;
            break;
        }  
    }
}

你能告诉我为什么这总是返回 true,即使我的目录已更新?

编辑 #2 我已经添加了:

if (statuses[i].LocalContentStatus == SvnStatus.Missing || statuses[i].LocalContentStatus == SvnStatus.Modified)

有没有更好的方法来做到这一点?

【问题讨论】:

  • 与其引入外部依赖项 (svn.exe) 并产生生成外部进程的开销,不如使用SharpSVN,它通过库提供对 SVN 的支持。
  • 如果您坚持使用svn.exe,请尝试使用 XML 输出进行更确定性的解析。
  • @alroc 因为我们已经在机器上安装了 tortoise,所以我相信最好使用它而不是每个人都必须安装另一个安装。过早按下回车,感谢您的评论!
  • 您的用户不需要安装任何东西——您将 SharpSVN 构建到您的应用程序中。甚至还有一个NuGet package。
  • 如果我只是检查一个文件夹的更新(每分钟)是 SharpSVN 我在找什么?

标签: c# svn tortoisesvn


【解决方案1】:

在 SharpSVN 论坛上有一个讨论:How to check if working copy is latest version? 那里他们使用类似的解决方案,就像你一样:获取状态,遍历项目,如果有 IsRemoteUpdated,SVN 目录需要更新。

【讨论】:

    猜你喜欢
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    • 2020-04-15
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多