用c#编程地创建SVN补丁/ diff文件

本文关键字:补丁 diff 文件 SVN 创建 编程 | 更新日期: 2023-09-27 18:13:04

使用SharpSVN,我可以很容易地在c#中以编程方式恢复SVN签出,但现在我需要在执行恢复之前创建一个补丁/diff文件。

SharpSVN有SvnClient。补丁API,但docs/intellisense表明这是用于将补丁应用到repo,而我需要等效的首先创建补丁文件。

如何用c#编程创建SVN补丁文件

用c#编程地创建SVN补丁/ diff文件

要从SVN创建补丁文件,还可以跨版本创建一个"Unified Diff"文件。下面的代码是基于相同的。它将在指定的版本中创建一个统一的Diff文件。

                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();
                }