2009-09-04 10 views
1

я вижу, что все, что я могу установить на это% Repos% и% TXN%Как я могу получить доступ к сообщению pre-commit SVN с помощью SharpSVN?

как я могу использовать те, чтобы добраться до сообщения об изменениях (в моем случае, так что я могу разобрать номер билета, так что я могу видеть если он существует в базе данных ошибок, прежде чем совершать к ней)

ответ

1

Используя недавний SharpSvn релиз вы можете использовать

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

Я не знаю SharpSVN, однако, если вы создаете сценарий крючок, как вы описали, вы получите в качестве аргументов% РЕПО% и% TXN%

с этими данные можно просмотреть в транзакции (% txn%) данного репозитория. Обычно вы делаете это с помощью

svnlook -t %txn% %repo% 

Тогда вы получите сообщение-сообщение.

Итак, вы должны искать эквивалент svnlook в интерфейсе sharpSVN.

+0

Да, я уже это сделал. Я даже задал вопрос относительно этого синтаксиса некоторое время назад: http://stackoverflow.com/questions/1258191/sharpsvn-svnlookclient К сожалению, использование SVNLook от SharpSVN не помогло. Он не смог получить сообщение журнала (как он может быть? Он даже хранится в SVN в точке, где txn = 486-1? Однако я не копал это в глубине проблемы и не делал это точно так же, как вы сказали, отправляя данные в файл: % журнала SVNLOOK% -t% TXN%% REPOS%>% LOG_FILE% % ~ dp0MyExeThatDoesOtherStuff.exe% LOG_FILE% – KevinDeus

+2

Последние версии SharpSvn имеют SvnLookClient, который воспроизводит функциональность команды svnlook в .Net –

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 добавляется к пути переменной окружения вашей машины так выше, может выполняться из любого места.

2

Некоторое время назад я написал оболочку C# для svnlook.exe. Я использовал этот, чтобы отправлять сообщения фиксации в трекер ошибок (если был указан идентификатор билета). Найдите его ниже, может быть, это полезно для вас.

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