我如何使用 SharpSVN 访问 SVN 预提交消息?

发布于 2024-08-04 10:48:43 字数 101 浏览 12 评论 0原文

我看到我所能设置的就是 %repos% 和 %txn%

我如何使用它们来获取提交消息(在我的例子中,这样我可以解析出票号,以便我可以查看它是否存在于错误中提交之前的数据库)

i see that all I can set to is %repos% and %txn%

how can I use those to get to the commit message (in my case, so i can parse out the ticket number so i can see if it exists in the bug database before committing to it)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

岁月无声 2024-08-11 10:48:43

我不知道 SharpSVN,但是如果您按照您的描述创建一个钩子脚本,您将获得 %repos% 和 %txn% 作为参数。

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

svnlook -t %txn%  %repo%

然后您将收到日志消息来执行此操作。

所以你应该在 SharpSVN 界面中寻找与 svnlook 等效的东西。

I do not know SharpSVN, however if you create a hook script as you describe, you get as arguments %repos% and %txn%

With these data you can look into the transaction (%txn%) of the given repository. Usually you do this by using

svnlook -t %txn%  %repo%

Then you will get the log-message.

So you should look for an equivalent to svnlook in sharpSVN interface.

寒冷纷飞旳雪 2024-08-11 10:48:43

不久前,我为 svnlook.exe 编写了一个 C# 包装器。我使用这个将提交消息发送到错误跟踪器(如果提供了票证 ID)。下面找到它,也许对你有用。

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

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

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

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

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

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

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

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

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

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

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

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

    /// <summary>
    /// The string "youngest" 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 "author"
    /// </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 "log"
    /// </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 "changed"
    /// </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 "info"
    /// </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;
    }
}

Some time ago I've written a C# wrapper for the svnlook.exe. I used this one to send commit messages to a bug tracker (if a ticket id was provided). Find it below, maybe it is useful for you.

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

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

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

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

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

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

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

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

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

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

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

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

    /// <summary>
    /// The string "youngest" 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 "author"
    /// </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 "log"
    /// </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 "changed"
    /// </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 "info"
    /// </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;
    }
}
眸中客 2024-08-11 10:48:43

使用最近的 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)
    {

    }
}

它来获取日志消息、更改的文件等

Using a recent SharpSvn release you can use

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

to parse the arguments of a pre-commit hook and then use

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

    }
}

to get to the log message, changed files, etc.

讽刺将军 2024-08-11 10:48:43

我刚刚完成了自己构建 Hooks 应用程序的过程,并且不需要 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 的位置已添加到计算机的路径环境变量中,以便可以从任何位置执行上述内容。

I've just gone through the process of building a hooks app myself and SharpSVN isn't required for looking at commit messages. Assuming you've built yourself a console app already, try this code which calls svnlook.exe directly:

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;

Make sure the location of svnlook.exe is added to the path environment variable of your machine so the above can be executed from any location.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文