views:

351

answers:

3

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

    }
}
A: 

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.

Noon Silk
SvnLookClient is the library equivalent to the 'svnlook' application. This class was designed for using from repository hooks (just like svnlook).
Bert Huijben
+2  A: 

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 version). 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))
}
Bert Huijben
A: 

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;
}
KevinDeus