Search code examples
c#svnpost-commitsharpsvn

SharpSVN get post-commit-hook with 'SvnLookClient'


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

    }
}

Solution

  • 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))
    }