1
using (SvnClient client = new SvnClient())
{
    client.Commit(_targetPath, commitArgs);

    SvnInfoEventArgs result;
    client.GetInfo(_targetPath, out result);

    SvnLogArgs args = new SvnLogArgs();
    args.Start = new SvnRevision(result.L​astChangeRevision);
    args.End = new SvnRevision(result.Revision);

    Collection<SvnLog​EventArgs> logitems;
    client.GetLog(_targetPath, args, out logitems);

    foreach (SvnLogEventArgs logentry in logitems)
    {
        string author = logentry.Author;
        string message = logentry.LogMessage;
        DateTime checkindate = logentry.Time;
        AddMessage(string.Fo​rmat("Commited successfully by {0} on {1} for message: {2}", author, checkindate, message));
    }
}

这是我的代码,但我只能得到一个日志条目,它应该是修订范围的所有日志的路径,有什么问题?

4

3 回答 3

1

我认为您要做的是在提交工作副本时列出已更改的文件,即在提交文件时显示文件通知。有比你正在做的更好的方法来做到这一点:

using (SvnClient client = new SvnClient())
{
    // Register the notify event, to get notified of any actions
    client.Notify += (sender, eventArgs) => AddMessage(
        string.Format("Changed path,{0},by action,{1}",
            eventArgs.Path,
            eventArgs.Action));

    client.Commit(_targetPath, commitArgs);
}

查看Notify活动,SvnNotifyEventArgs了解更多详情。

此外,您还可以使用具有类型参数的Commit重载:outSvnCommitResult

SvnCommitResult commitResult;
client.Commit(_targetPath, commitArgs, out commitResult);

Console.WriteLine(string.Format(
    "{0} commited revision {1} at time {2}", 
    commitResult.Author, 
    commitResult.Revision, 
    commitResult.Time));
于 2011-02-22T23:19:21.107 回答
1

我对这个 api 一无所知,但看起来您正在调用 GetLog,其范围介于上次更改修订版和当前修订版之间。本能地,我认为这只是一个定义的日志条目。

所以我的想法是你的修订范围是错误的。您为什么不尝试对预期的修订范围进行硬编码,看看结果是否符合您的期望。

于 2011-02-21T03:32:30.277 回答
-1

好的,现在我从下面的代码中得到了我想要的东西:

using (SvnClient client = new SvnClient())
{
    try
    {
        client.Commit(_targetPath, commitArgs);
        SvnLogArgs args = new SvnLogArgs();

        // get latest changed version
        SvnWorkingCopyClient workingCopyClient = new SvnWorkingCopyClient();
        SvnWorkingCopyVersion version;

        workingCopyClient.GetVersion(_targetPath, out version);
        long localRev = version.End;
        args.Start = new SvnRevision(localRev);
        args.End = new SvnRevision(localRev);

        //get latest log
        Collection<SvnLogEventArgs> logitems;
        client.GetLog(_targetPath, args, out logitems);
        if (logitems.Count > 0)
        {
            foreach (SvnChangeItem path in logitems[0].ChangedPaths)
            {
                AddMessage(string.Format("Changed path,{0},changed on,{1},by action,{2}", path.Path, logitems[0].Time, path.Action));
            }
        }

        WriteLogFile(messageLog.ToString());
    }
    catch (SvnException ex)
    {

    }

}
于 2011-02-22T04:13:01.410 回答