2009-09-04 4 views

답변

1

당신은 사전 커밋 후크의 인수를 구문 분석

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

을 사용하고 변경 로그 메시지에 도착

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

) 그것을 커밋하기 전에 버그 데이터베이스에 존재하는 경우 나는 당신이 설명하는대로 후크 스크립트를 만들 경우, 당신은 인수 %의 repos로 얻을 SharpSVN를 모르는 % 및 % TXN % 다음으로

데이터는 주어진 저장소의 트랜잭션 (% txn %)을 조사 할 수 있습니다. 일반적으로 다음을 사용하여이 작업을 수행하십시오.

svnlook -t %txn% %repo% 

그러면 로그 메시지가 나타납니다.

그래서 sharpSVN 인터페이스에서 svnlook과 동일한 기능을 찾아야합니다.

+0

예, 이미 했어요. 나는 그 문법에 관한 질문을 잠시 뒤로 물었다 : http://stackoverflow.com/questions/1258191/sharpsvn-svnlookclient 불행히도 SharpSVN의 SVNLook을 사용하면 작동하지 않았다. 로그 메시지를 얻지 못했습니다 (어떻게 될까요? txn = 486-1? 지점에 SVN에 저장되어 있습니까?) 그러나 나는 그 문제에 대해 깊이 파고 들지 않았습니다. 당신은 파일에 데이터를 전송 말했다 % SVNLOOK %의 로그 -t % TXN % % REPOS %> % LOG_FILE % % ~ dp0MyExeThatDoesOtherStuff.exe % LOG_FILE % – KevinDeus

+2

최근 SharpSvn 버전은 기능을 복제하는 SvnLookClient이 NET에서 svnlook 명령의 –

1

나는 스스로 훅 앱을 만드는 과정을 밟았으며 SharpSVN은 커밋 메시지를 보는 데 필요하지 않습니다.

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의 위치가 상기 할 수 있도록 컴퓨터의 경로 환경 변수에 추가되어 있는지 확인합니다 : 당신은 이미 자신에게 콘솔 응용 프로그램을 구축했습니다 가정하면, svnlook.exe 직접 호출이 코드를 시도 어느 위치에서나 실행될 수 있습니다.

2

얼마 전에 svnlook.exe에 대한 C# 래퍼를 작성했습니다. 이 코드를 사용하여 버그 추적기에 커밋 메시지를 보냈습니다 (티켓 ID가 제공된 경우). 아래에서 찾으십시오, 아마 당신에게 유용 할 것입니다. 최근 SharpSvn 릴리스를 사용

/// <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

+1 공유 코드 및 작업 – balexandre