2011-07-01 53 views
0

我正試圖找到一種有效的方法來獲取文件的先前版本,以使用SharpSVN進行文本比較。SharpSVN - 如何獲得以前的修訂?

using (SvnClient c = new SvnClient()) 
{ 
    c.Authentication.DefaultCredentials = new NetworkCredential(
      ConfigurationManager.AppSettings.Get("SvnServiceUserName") 
     , ConfigurationManager.AppSettings.Get("SvnServicePassword") 
     , ConfigurationManager.AppSettings.Get("SvnServiceDomain") 
     ); 
    c.Authentication.SslServerTrustHandlers += new EventHandler<SvnSslServerTrustEventArgs>(Authentication_SslServerTrustHandlers); 

    Collection<SvnFileVersionEventArgs> fileVersionCollection = new Collection<SvnFileVersionEventArgs>(); 
    SvnRevisionRange range = new SvnRevisionRange(0, this.hooks.Revision); 
    SvnFileVersionsArgs args = new SvnFileVersionsArgs(); 
    args.RetrieveProperties = true; 
    args.Range = range; 

    foreach (SvnChangeItem item in log.ChangedPaths) 
    { 
     string path = this.repositoryPath + item.Path; 

     bool gotFileVersions = false; 

     try 
     { 
      if (item.NodeKind == SvnNodeKind.File) 
       gotFileVersions = c.GetFileVersions(SvnTarget.FromString(path), args, out fileVersionCollection); 

上面的代碼是執行我的請求的示例,但它效率極低。我的目標是能夠選擇一個修訂版本,以及之前的修訂版本。例如,如果我的存儲庫在r185,但我想在版本100中查看該文件,並查看同一個文件的先前版本(我不知道這是什麼),那麼這怎麼做呢?

我已經看過c.GetInfo(),但是這似乎只能得到最新的提交修訂。

謝謝!

回答

1

只試着找到你正在尋找的版本。我假設logSvnLoggingEventArgs的一個實例?

如果是這樣,使用方法:

args.Range = new SvnRevisionRange(log.Revision, log.Revision - 1); 

這樣,你就只能檢索該版本的變化,因爲log.Revision保證是變化的版本號,如果你減去一個,你有以前的版本。

0

您是否需要先前版本(上次提交之前的版本)或本地未修改版本。

Subversion工作拷貝庫具有以下「魔力」的版本

Working (SvnRevision.None)  - What you have in your working copy 
            (includes local modifications) 

Head  (SvnRevision.Head)  - The last committed version of a url in the 
            repository 

Base  (SvnRevision.Base)  - The version you last committed or updated to. 

Committed (SvnRevision.Comitted) - The last revision <= BASE in which the path was 
            modified 

Previous (SvnRevision.Previous) - The last revision before Committed. 
            (Literally Committed-1) 

要獲得這些版本可以使用SvnClient.Write()

using (SvnClient c = new SvnClient()) 
using (Stream to = File.Create(@"C:\temp\my.tmp")) 
{ 
    c.Write(new SvnPathTarget(@"F:\projects\file.cs", SvnRevision.Base), to); 
} 

的文件工作和基地之一在當地可用。對於其他版本,Subversion必須聯繫存儲庫。

相關問題