以C#编程创建SVN补丁/差异文件

时间:2016-10-14 19:40:37

标签: c# svn tortoisesvn sharpsvn

使用SharpSVN我可以在C#中以编程方式轻松恢复SVN签出,但现在我需要在执行恢复之前创建补丁/差异文件。

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

如何在C#中以编程方式创建SVN补丁文件?

1 个答案:

答案 0 :(得分:0)

要从SVN创建补丁文件,您还可以创建一个"统一差异"跨修订的文件。以下代码基于相同。它将创建一个统一的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();

                }