2009-09-04 110 views

回答

1

使用最近SharpSvn版本中,您可以使用

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

解析一个pre-commit钩子的参数,然后使用

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

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

    } 
} 

去日志消息,改文件等

5

之前就存在,我不知道SharpSVN,但是如果你创建了一个钩子脚本为你描述,你作为参数%回购%和%TXN%

有了这些数据可以查看给定存储库的事务(%txn%)。通常你通过使用

svnlook -t %txn% %repo% 

然后你会得到日志消息。

所以你应该在sharpSVN接口中寻找一个相当于svnlook的东西。

+0

是的,我已经做到了。我甚至问过关于该语法的问题,但回来:http://stackoverflow.com/questions/1258191/sharpsvn-svnlookclient 不幸的是使用SharpSVN的SVNLook没有工作。它没有得到日志消息(它怎么可能?它甚至存储在SVN中的txn = 486-1? 然而,我没有深入研究这个问题,并最终完成了它你说,将数据发送到一个文件: %svnlook的日志%-t%TXN%%REPOS%>%LOG_FILE% %〜dp0MyExeThatDoesOtherStuff.exe%LOG_FILE% – KevinDeus 2009-09-05 00:15:21

+2

最近SharpSvn版本具有复制功能的SvnLookClient .Net – 2009-09-08 19:57:32

1

我刚刚完成了自己构建挂钩应用程序的过程,并且SharpSVN不需要查看提交消息。假设你已经建立了自己已经是一个控制台应用程序,试试这个代码svnlook.exe直接调用:

string repos = args[0]; 
string txn = args[1]; 

var processStartInfo = new ProcessStartInfo 
{ 
    FileName = "svnlook.exe", 
    UseShellExecute = false, 
    CreateNoWindow = true, 
    RedirectStandardOutput = true, 
    RedirectStandardError = true, 
    Arguments = String.Format("log -t \"{0}\" \"{1}\"", txn, repos) 
}; 

Process process = Process.Start(processStartInfo); 
string message = process.StandardOutput.ReadToEnd(); 
process.WaitForExit(); 
return message; 

确保svnlook.exe的位置添加到您机器的PATH环境变量,因此,上述罐从任何位置执行。

2

前段时间我写了一个svnlook.exe的C#包装器。我使用这个发送提交消息给bug跟踪器(如果提供了ticket id)。在下面找到它,也许它对你有用。

/// <summary> 
/// Encapsulates the SVNLook command in all of it's flavours 
/// </summary> 
public static class SvnLookCommand 
{ 
    /// <summary> 
    /// The string &quot;&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string AUTHOR = "author"; 

    /// <summary> 
    /// The string &quot;cat&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string CAT = "cat"; 

    /// <summary> 
    /// The string &quot;changed&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string CHANGED = "changed"; 

    /// <summary> 
    /// The string &quot;date&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string DATE = "date"; 

    /// <summary> 
    /// The string &quot;diff&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string DIFF = "diff"; 

    /// <summary> 
    /// The string &quot;dirs-changed&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string DIRSCHANGED = "dirs-changed"; 

    /// <summary> 
    /// The string &quot;history&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string HISTORY = "history"; 

    /// <summary> 
    /// The string &quot;info&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string INFO = "info"; 

    /// <summary> 
    /// The string &quot;lock&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string LOCK = "lock"; 

    /// <summary> 
    /// The string &quot;log&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string LOG = "log"; 

    /// <summary> 
    /// The string &quot;tree&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string TREE = "tree"; 

    /// <summary> 
    /// The string &quot;uuid&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string UUID = "uuid"; 

    /// <summary> 
    /// The string &quot;youngest&quot; used as parameter for the svnlook.exe 
    /// </summary> 
    private static readonly string YOUNGEST = "youngest"; 

    /// <summary> 
    /// The full path of the svnlook.exe binary 
    /// </summary> 
    private static string commandPath = String.Empty; 

    /// <summary> 
    /// Initializes static members of the <see cref="SvnLookCommand"/> class. 
    /// </summary> 
    static SvnLookCommand() 
    { 
     commandPath = Settings.Default.SvnDirectoryPath; 

     if (!Path.IsPathRooted(commandPath)) 
     { 
      Assembly entryAssembly = Assembly.GetEntryAssembly(); 
      if (entryAssembly != null) 
      { 
       commandPath = new FileInfo(entryAssembly.Location).Directory.ToString() + Path.DirectorySeparatorChar + commandPath; 
      } 
     } 

     if (!commandPath.EndsWith(Path.DirectorySeparatorChar.ToString())) 
     { 
      commandPath = commandPath + Path.DirectorySeparatorChar; 
     } 

     commandPath += "svnlook.exe"; 
    } 

    /// <summary> 
    /// Gets the process info to start a svnlook.exe command with parameter &quot;author&quot; 
    /// </summary> 
    /// <param name="repository">The repository.</param> 
    /// <param name="revision">The revision.</param> 
    /// <returns>Gets the author of the revision in scope</returns> 
    public static ProcessStartInfo GetAuthor(string repository, string revision) 
    { 
     ProcessStartInfo svnLookProcessStartInfo = new ProcessStartInfo(commandPath); 
     svnLookProcessStartInfo.Arguments = String.Format("{0} {1} -r {2}", AUTHOR, repository, revision); 
     return svnLookProcessStartInfo; 
    } 

    /// <summary> 
    /// Gets the process info to start a svnlook.exe command with parameter &quot;log&quot; 
    /// </summary> 
    /// <param name="repository">The repository.</param> 
    /// <param name="revision">The revision.</param> 
    /// <returns>The svn log of the revision in scope</returns> 
    public static ProcessStartInfo GetLog(string repository, string revision) 
    { 
     ProcessStartInfo svnLookProcessStartInfo = new ProcessStartInfo(commandPath); 
     svnLookProcessStartInfo.Arguments = String.Format("{0} {1} -r {2}", LOG, repository, revision); 
     return svnLookProcessStartInfo; 
    } 

    /// <summary> 
    /// Gets the process info to start a svnlook.exe command with parameter &quot;changed&quot; 
    /// </summary> 
    /// <param name="repository">The repository.</param> 
    /// <param name="revision">The revision.</param> 
    /// <returns>The change log of the revision in scope</returns> 
    public static ProcessStartInfo GetChangeLog(string repository, string revision) 
    { 
     ProcessStartInfo svnLookProcessStartInfo = new ProcessStartInfo(commandPath); 
     svnLookProcessStartInfo.Arguments = String.Format("{0} {1} -r {2}", CHANGED, repository, revision); 
     return svnLookProcessStartInfo; 
    } 

    /// <summary> 
    /// Gets the process info to start a svnlook.exe command with parameter &quot;info&quot; 
    /// </summary> 
    /// <param name="repository">The repository.</param> 
    /// <param name="revision">The revision.</param> 
    /// <returns>The info of the revision in scope</returns> 
    public static ProcessStartInfo GetInfo(string repository, string revision) 
    { 
     ProcessStartInfo svnLookProcessStartInfo = new ProcessStartInfo(commandPath); 
     svnLookProcessStartInfo.Arguments = String.Format("{0} {1} -r {2}", INFO, repository, revision); 
     return svnLookProcessStartInfo; 
    } 
} 
+0

的svnlook命令用于共享代码和工作 – balexandre 2009-09-09 07:05:55