2009-03-26 31 views

Trả lời

36

Cách rẻ nhất để lấy bản sửa đổi đầu từ một kho lưu trữ là lệnh Info.

using(SvnClient client = new SvnClient()) 
{ 
    SvnInfoEventArgs info; 
    Uri repos = new Uri("http://my.server/svn/repos"); 

    client.GetInfo(repos, out info); 

    Console.WriteLine(string.Format("The last revision of {0} is {1}", repos, info.Revision)); 
} 
+0

mã này không làm việc cho tôi như bên dưới 'sử dụng (SvnClient client = new SvnClient()) {SvnInfoEventArgs thông tin; Uri repos = new Uri ("svn: // india01/repository/branch/mybranch1"); client.GetInfo (repos, out info); lblMsg.Visible = true; lblMsg.Text = (string.Format ("Bản sửa đổi cuối cùng của {0} là {1}", repos, info.Revision)); } ' bất cứ khi nào tôi chạy trang web của mình, nó chỉ tiếp tục tìm kiếm .. bất kỳ giải pháp nào cho việc này. – picnic4u

+2

Nếu bạn muốn sửa đổi mới nhất cho một đường dẫn nhất định (không phải toàn bộ repo), bạn có thể trả lại 'info.LastChangeRevision'. – styfle

9

Ok, tôi đã tìm nó bằng bản thân mình:

SvnInfoEventArgs statuses; 
client.GetInfo("svn://repo.address", out statuses); 
int LastRevision = statuses.LastChangeRevision; 
1

tôi cũng googled rất nhiều nhưng chỉ có một điều mà đang làm việc cho tôi để có được thực sự là phiên bản cuối cùng là:

public static long GetRevision(String target) 
    { 
     SvnClient client = new SvnClient(); 

     //SvnInfoEventArgs info; 
     //client.GetInfo(SvnTarget.FromString(target), out info); //Specify the repository root as Uri 
     //return info.Revision 
     //return info.LastChangeRevision 

     Collection<SvnLogEventArgs> info = new Collection<SvnLogEventArgs>(); 
     client.GetLog(target, out info); 
     return info[0].Revision; 
    } 

các giải pháp khác đã được chú thích. Hãy thử một mình và thấy sự khác biệt. . .

+0

Lệnh này lấy tất cả các sửa đổi để có được một số sửa đổi duy nhất ... Đó là một chút quá mức cần thiết và chắc chắn không phải là cách nhanh nhất để có được thông tin. –

15

tôi đang kiểm tra phiên bản mới nhất của các bản sao làm việc sử dụng SvnWorkingCopyClient:

var workingCopyClient = new SvnWorkingCopyClient(); 

SvnWorkingCopyVersion version; 

workingCopyClient.GetVersion(workingFolder, out version); 

Phiên bản mới nhất của kho làm việc tại địa phương là sau đó có sẵn thông qua

long localRev = version.End; 

Đối với một kho lưu trữ từ xa, sử dụng

var client = new SvnClient(); 

SvnInfoEventArgs info; 

client.GetInfo(targetUri, out info); 

long remoteRev = info.Revision; 

thay thế.

Điều này tương tự như sử dụng công cụ svnversion từ dòng lệnh. Hi vọng điêu nay co ich.

0

Đây là một câu hỏi rất cũ, và nó đã được trả lời tốt trong hai câu trả lời hàng đầu. Tuy nhiên, với hy vọng nó có thể giúp một người nào đó tôi đăng phương thức C# sau đây để minh họa cách không chỉ nhận được số sửa đổi từ cả kho lưu trữ và bản sao làm việc, mà còn làm thế nào để kiểm tra các tình huống điển hình được coi là vấn đề, ví dụ trong một quá trình xây dựng tự động.

/// <summary> 
    /// Method to get the Subversion revision number for the top folder of the build collection, 
    /// assuming these files were checked-out from Merlinia's Subversion repository. This also 
    /// checks that the working copy is up-to-date. (This does require that a connection to the 
    /// Subversion repository is possible, and that it is running.) 
    /// 
    /// One minor problem is that SharpSvn is available in 32-bit or 64-bit DLLs, so the program 
    /// needs to target one or the other platform, not "Any CPU". 
    /// 
    /// On error an exception is thrown; caller must be prepared to catch it. 
    /// </summary> 
    /// <returns>Subversion repository revision number</returns> 
    private int GetSvnRevisionNumber() 
    { 
    try 
    { 
     // Get the latest revision number from the Subversion repository 
     SvnInfoEventArgs svnInfoEventArgs; 
     using (SvnClient svnClient = new SvnClient()) 
     { 
      svnClient.GetInfo(new Uri("svn://99.99.99.99/Merlinia/Trunk"), out svnInfoEventArgs); 
     } 

     // Get the current revision numbers from the working copy that is the "build collection" 
     SvnWorkingCopyVersion svnWorkingCopyVersion; 
     using (SvnWorkingCopyClient svnWorkingCopyClient = new SvnWorkingCopyClient()) 
     { 
      svnWorkingCopyClient.GetVersion(_collectionFolder, out svnWorkingCopyVersion); 
     } 

     // Check the build collection has not been modified since last commit or update 
     if (svnWorkingCopyVersion.Modified) 
     { 
      throw new MerliniaException(0x3af34e1u, 
        "Build collection has been modified since last repository commit or update."); 
     } 

     // Check the build collection is up-to-date relative to the repository 
     if (svnInfoEventArgs.Revision != svnWorkingCopyVersion.Start) 
     { 
      throw new MerliniaException(0x3af502eu, 
      "Build collection not up-to-date, its revisions = {0}-{1}, repository = {2}.", 
      svnWorkingCopyVersion.Start, svnWorkingCopyVersion.End, svnInfoEventArgs.Revision); 
     } 

     return (int)svnInfoEventArgs.Revision; 
    } 
    catch (Exception e) 
    { 
     _fLog.Error(0x3af242au, e); 
     throw; 
    } 
    } 

(Mã này không bao gồm một vài điều cụ thể cho chương trình đó đã được sao chép từ, nhưng điều đó không nên thực hiện những phần SharpSvn khó hiểu.)

Các vấn đề liên quan