Using SharpSVN I can easily revert an SVN checkout programmatically in C#, but now I need to create a patch / diff file just prior to performing the revert.
SharpSVN has the SvnClient.Patch API but docs / intellisense indicate that this is for applying a patch to a repo, whereas I need the equivalent to create the patch file in the first place.
How can I programatically create an SVN patch file in C# ?
To Create a Patch file from SVN, you can also create a "Unified Diff" file across revisions. Following code is based on the same. It will create a unified Diff file of the changes done across specified revisions.
System.Uri uri = new System.Uri("your url path");
using (SvnClient client = new SvnClient())
{
SvnUriTarget from = new SvnUriTarget(uri);
// To Get the Latest Revision on the Required SVN Folder
SvnInfoEventArgs info;
client.GetInfo(uri, out info);
SvnRevisionRange range = new SvnRevisionRange(info.Revision - 10, info.Revision); // The given input revisions should be valid revisions on the selected Repo path
System.IO.MemoryStream stream = new System.IO.MemoryStream();
if (client.Diff(from, range, stream))
{
stream.Position = 0; //reset the stream position to zero, as the stream position returned from Diff method is at the end.
System.IO.File.AppendAllText(@"C:\diffFile.patch", new System.IO.StreamReader(stream).ReadToEnd());
}
stream.Close();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.