12

How do I programmatically get the revision description and author from the SVN server in c#?

Jon B
  • 51,025
  • 31
  • 133
  • 161
Tom Smykowski
  • 25,487
  • 54
  • 159
  • 236
  • Do you actually want to query an SVN server or just get the revision number/description for the latest SVN commit in your project directory? – Noldorin Mar 25 '09 at 14:26

3 Answers3

18

Using SharpSvn:

using(SvnClient client = new SvnClient())
{
    Collection<SvnLogEventArgs> list;

    // When not using cached credentials
    // c.Authentication.DefaultCredentials = new NetworkCredential("user", "pass")l

    SvnLogArgs la = new SvnLogArgs { Start = 128, End = 132 };
    client.GetLog(new Uri("http://my/repository"), la, out list);

    foreach(SvnLogEventArgs a in list)
    {
       Console.WriteLine("=== r{0} : {1} ====", a.Revision, a.Author);
       Console.WriteLine(a.LogMessage);
    }
}
Chris
  • 2,009
  • 1
  • 16
  • 25
Bert Huijben
  • 19,525
  • 4
  • 57
  • 73
6

You will need to find a C# SVN API to use. A quick Google search found SharpSVN.

To get message and author for specific revision

SvnClient client = new SvnClient();
SvnUriTarget uri = new SvnUriTarget("url", REV_NUM);

string message, author;
client.GetRevisionProperty(uri, "svn:log", out message);
client.GetRevisionProperty(uri, "svn:author", out author);
Samuel
  • 37,778
  • 11
  • 85
  • 87
  • I know there are some libraries with SVN in its name, but what I would like to know how to do this from someone who did it before. – Tom Smykowski Mar 25 '09 at 14:59
3

I've done something similar to this a while back, we needed notification of certain repository commits.

I ended up using SubversionNotify to do this. You could take a look at the code there and see what you can use.

I do believe SubversionNotify is grabbing output from svnlook. Svnlook has quite a few arguments that can get what you're looking for.

If you know the revision number and repository:

svnlook info -r [rev#] /path/to/repo

Will net you the User, Timestamp, Log message length, and the log message itself:

bob
2009-03-25 11:10:49 -0600 (Wed, 25 Mar 2009)
19
Did stuff with things.
Slipfish
  • 330
  • 1
  • 8
  • 23