使用SharpSvn方便调用svn
需要调用svn去做一些操作时,有两种方式:调用svn.exe命令行和调用svn api接口。我不太喜欢调用命令行的方式,是因为它需要依赖一个外部的exe程序,同时,为了得到命令执行结果,还需要去捕捉命令行的输出控制台,然后去解析,使得不太可靠。因此,我选择了调用svn接口的方式,因为我使用的是c#,有一个现成的第三方包装的库SharpSvn可以调用。
SharpSvn主页:
http://sharpsvn.open.collab.net/
使用起来很简单,下面是一个例子:
static void Main(string[] args)
{
using (SvnClient client = new SvnClient())
{
SvnInfoEventArgs serverInfo;
SvnInfoEventArgs clientInfo;
SvnUriTarget repos = new SvnUriTarget("http://svn.test.com/demo");
SvnPathTarget local = new SvnPathTarget(@"d:\Work\Code\demo");
client.GetInfo(repos, out serverInfo);
client.GetInfo(local, out clientInfo);
string path = @"d:\Work\Code\Demo";
client.CleanUp(path);
client.Revert(path);
client.Update(path);
Console.WriteLine(string.Format("serverInfo revision of {0} is {1}", repos, serverInfo.Revision));
Console.WriteLine(string.Format("clientInfo revision of {0} is {1}", local, clientInfo.Revision));
}
{
using (SvnClient client = new SvnClient())
{
SvnInfoEventArgs serverInfo;
SvnInfoEventArgs clientInfo;
SvnUriTarget repos = new SvnUriTarget("http://svn.test.com/demo");
SvnPathTarget local = new SvnPathTarget(@"d:\Work\Code\demo");
client.GetInfo(repos, out serverInfo);
client.GetInfo(local, out clientInfo);
string path = @"d:\Work\Code\Demo";
client.CleanUp(path);
client.Revert(path);
client.Update(path);
Console.WriteLine(string.Format("serverInfo revision of {0} is {1}", repos, serverInfo.Revision));
Console.WriteLine(string.Format("clientInfo revision of {0} is {1}", local, clientInfo.Revision));
}
}