2009-09-04 85 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