SharpSVN get post-commit-hook with 'SvnLookClient'

无人久伴 提交于 2019-12-07 16:16:57

问题


I'm trying to figure out how to get the commit message for a particular revision. It looks like SvnLookClient is probably what I need

I found some code here on SO that looks like what I need but I seem to be missing something..

Code I found (here on so):

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

     //******what is lookorigin? do I pass the revision here??
    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)
    {

    }
}

回答1:


The SvnLook client is specifically targetted for using in repository hooks. It allows access to uncommited revisions and therefore needs other arguments. (It's the SharpSvn equivalent of the 'svnlook' command. If you need a 'svn' equivalent you should look at SvnClient).

A look origin is either: * A repository path and a transaction name * or a repository path and a revision number

E.g. in a pre-commit hook the revision is not committed yet, so you can't access it over the public url, like you would normally do.

The documentation says (in pre-commit.tmpl):

# The pre-commit hook is invoked before a Subversion txn is
# committed.  Subversion runs this hook by invoking a program
# (script, executable, binary, etc.) named 'pre-commit' (for which
# this file is a template), with the following ordered arguments:
#
#   [1] REPOS-PATH   (the path to this repository)
#   [2] TXN-NAME     (the name of the txn about to be committed)

SharpSvn helps you by offering:

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

Which parses these arguments for you. (Which in this case is very simple, but there are more advanced hooks.. And hooks can receive new arguments in newer Subversion versions). The value you need is in the .LookOrigin property of ha.

If you just want to have the log message for a specific revision range (1234-4567) you should not look at the SvnLookClient.

using(SvnClient cl = new SvnClient())
{
  SvnLogArgs la = new SvnLogArgs();
  Collection<SvnLogEventArgs> col;
  la.Start = 1234;
  la.End = 4567;
  cl.GetLog(new Uri("http://svn.collab.net/repos/svn"), la, out col))
}



回答2:


FYI, I made a C# function based on Bert's response. Thanks Bert!

public static string GetLogMessage(string uri, int revision)
{
    string message = null;

    using (SvnClient cl = new SvnClient())
    {
        SvnLogArgs la = new SvnLogArgs();
        Collection<SvnLogEventArgs> col;
        la.Start = revision;
        la.End = revision;
        bool gotLog = cl.GetLog(new Uri(uri), la, out col);

        if (gotLog)
        {
            message = col[0].LogMessage;
        }
    }

    return message;
}



回答3:


Yeah no, I think I have the code for this, I'll post it later. SharpSVN has an arguably (IMHO) confusing API.

I think you want .Log (of SvnClient), or similar, passing in the revision you're after.



来源:https://stackoverflow.com/questions/1258191/sharpsvn-get-post-commit-hook-with-svnlookclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!