2009-08-11 105 views
3

我想弄清楚如何获取特定修订的提交消息。它看起来像SvnLookClient可能是我所需要的SharpSVN与'SvnLookClient'获得提交后挂钩

我发现这里的一些代码上,以便看起来像什么,我需要,但我似乎失去了一些东西..

代码,我发现(在这里如此):

using (SvnLookClient cl = new SvnLookClient()) 
{ 
    SvnChangeInfoEventArgs ci; 

    //******what is lookorigin? do I pass the revision here?? 
    cl.GetChangeInfo(ha.LookOrigin, out ci); 


    // ci contains information on the commit e.g. 
    Console.WriteLine(ci.LogMessage); // Has log message 

    foreach (SvnChangeItem i in ci.ChangedPaths) 
    { 

    } 
} 

回答

3

SvnLook客户端专门针对在存储库挂钩中使用。它允许访问无限制的修订,因此需要其他参数。 (这是'svnlook'命令的SharpSvn等价物,如果你需要'svn'等价物,你应该看看SvnClient)。

一看产地可以是: * A库路径和事务名 *或库路径和版本号

例如在预提交钩子中,修订版尚未提交,因此您无法通过公开网址访问它,就像您通常所做的那样。

文档说(预commit.tmpl):

# The pre-commit hook is invoked before a Subversion txn is 
# committed. Subversion runs this hook by invoking a program 
# (script, executable, binary, etc.) named 'pre-commit' (for which 
# this file is a template), with the following ordered arguments: 
# 
# [1] REPOS-PATH (the path to this repository) 
# [2] TXN-NAME  (the name of the txn about to be committed) 

SharpSvn通过提供可帮助您:

SvnHookArguments ha; 
if (!SvnHookArguments.ParseHookArguments(args, SvnHookType.PostCommit, false, out ha)) 
{ 
    Console.Error.WriteLine("Invalid arguments"); 
    Environment.Exit(1); 
} 

,它解析这些参数为您服务。 (在这种情况下,它非常简单,但有更高级的钩子。钩子可以在更新的Subversion版本中接收新的参数)。您需要的值在ha的.LookOrigin属性中。

如果您只想拥有特定修订范围(1234-4567)的日志消息,则不应该查看SvnLookClient。

using(SvnClient cl = new SvnClient()) 
{ 
    SvnLogArgs la = new SvnLogArgs(); 
    Collection<SvnLogEventArgs> col; 
    la.Start = 1234; 
    la.End = 4567; 
    cl.GetLog(new Uri("http://svn.collab.net/repos/svn"), la, out col)) 
} 
0

是的不,我想我有这个代码,我会在稍后发布。 SharpSVN有一个可以说是(恕我直言)令人困惑的API。

我想你想要.log(的SvnClient)或类似的,传入你所修改的版本。

+0

SvnLookClient是相当于'svnlook'应用程序的库。这个类被设计用于使用仓库钩子(就像svnlook一样)。 – 2009-08-11 09:03:13

1

仅供参考,我根据Bert的回应做了一个C#函数。谢谢Bert!

public static string GetLogMessage(string uri, int revision) 
{ 
    string message = null; 

    using (SvnClient cl = new SvnClient()) 
    { 
     SvnLogArgs la = new SvnLogArgs(); 
     Collection<SvnLogEventArgs> col; 
     la.Start = revision; 
     la.End = revision; 
     bool gotLog = cl.GetLog(new Uri(uri), la, out col); 

     if (gotLog) 
     { 
      message = col[0].LogMessage; 
     } 
    } 

    return message; 
}