SharpSVN使用’SvnLookClient’获得post-commit-hook

我正在试图弄清楚如何获取特定修订的提交消息。 看起来SvnLookClient可能就是我需要的东西

我在SO上发现了一些看起来像我需要的代码,但我似乎错过了一些东西……

我找到的代码(在这里):

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 eg Console.WriteLine(ci.LogMessage); // Has log message foreach (SvnChangeItem i in ci.ChangedPaths) { } } 

SvnLook客户端专门用于在存储库挂钩中使用。 它允许访问未经修改的修订版,因此需要其他参数。 (这是’svnlook’命令的SharpSvn等价物。如果你需要一个’svn’等价物你应该看看SvnClient)。

外观源是:*存储库路径和事务名称*或存储库路径和修订号

例如,在预提交挂钩中,修订版尚未提交,因此您无法像通常那样通过公共URL访问它。

文档说(在pre-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 col; la.Start = 1234; la.End = 4567; cl.GetLog(new Uri("http://svn.collab.net/repos/svn"), la, out col)) } 

仅供参考,我根据Bert的回应制作了C#function。 谢谢伯特!

 public static string GetLogMessage(string uri, int revision) { string message = null; using (SvnClient cl = new SvnClient()) { SvnLogArgs la = new SvnLogArgs(); Collection 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; } 

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

我想你想要.Log(SvnClient),或类似的,传递你所追求的修订版。