Saturday, October 2, 2010

Export changes from Subversion with SharpSvn

private static void ExportRevisionRange(
Uri repositoryUrl,
long fromRevision,
long toRevision,
string exportFolder)
{
var client = new SvnClient();
var from =
new SvnUriTarget(repositoryUrl, fromRevision);
var to =
new SvnUriTarget(repositoryUrl, toRevision);
Collection<SvnDiffSummaryEventArgs> list;
client.GetDiffSummary(from, to, out list);

foreach (SvnDiffSummaryEventArgs item in list)
{
if (item.DiffKind == SvnDiffKind.Deleted ||
item.NodeKind != SvnNodeKind.File)
continue;
var target = new SvnUriTarget(item.ToUri);
string exportPath =
Path.Combine(
exportFolder,
item.Path.Replace("/", "\\"));
var fi = new FileInfo(exportPath);
if (!fi.Directory.Exists)
fi.Directory.Create();
client.Export(
target,
exportPath,
new SvnExportArgs { Revision = toRevision });
}}

No comments: