我怎样才能获得svn日志消息

时间:2011-02-21 03:00:49

标签: svn logging sharpsvn

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

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

3 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分: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重载,其out参数类型为SvnCommitResult

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));

答案 2 :(得分:-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)
    {

    }

}