2009-03-26 88 views

答えて

36

レポジトリからヘッドリビジョンを取得するための最も安価な方法は、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

このコードのように私のために働いていません(SvnClientクライアント=新しいSvnClient()){SvnInfoEventArgs info; Uri repos =新しいUri( "svn:// india01/repository/branches/mybranch1"); client.GetInfo(repos、out情報); lblMsg.Visible = true; lblMsg.Text =(string.Format( "{0}の最後のリビジョンは{1}"、repos、info.Revision)); } ' いつでも私は自分のウェブページを走らせているだけでそれだけを検索しています。 これに対する解決策です。 – picnic4u

+2

リポジトリ全体ではなく、特定のパスの最新のリビジョンが必要な場合は、代わりに 'info.LastChangeRevision'を返すことができます。 – styfle

9

[OK]を、私は自分でそれを考え出し:

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

また、私は多くのことをグーグルが、私は本当に最後のリビジョンを取得するために働いていた唯一の事でした:

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

他の解決策がコメントアウトされています。自分で試してみて、違いを見てください。 。 。

+0

このコマンドは、すべてのリビジョンを取得して1つのリビジョン番号を取得します。これは少し残酷で、確かに情報を入手する最速の方法ではありません。 –

15

私はSvnWorkingCopyClient使用して作業コピーの最新バージョンをチェックしています:リモートリポジトリについて

long localRev = version.End; 

を通じて

var workingCopyClient = new SvnWorkingCopyClient(); 

SvnWorkingCopyVersion version; 

workingCopyClient.GetVersion(workingFolder, out version); 

ローカルの作業リポジトリの最新バージョンが利用可能であるが、

を使用します
var client = new SvnClient(); 

SvnInfoEventArgs info; 

client.GetInfo(targetUri, out info); 

long remoteRev = info.Revision; 

代わりに

これは、コマンドラインからsvnversionツールを使用するのと同じです。お役に立てれば。

0

これは非常に古い質問です。これは、上位2つの回答でうまく答えられています。それでも、私はリポジトリと作業コピーの両方からリビジョン番号を取得する方法を説明するために次のC#メソッドを投稿しています。たとえば、自動化されたビルド・プロセスでは、問題とみなされます。

/// <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; 
    } 
    } 

(このコードは、それがからコピーされたプログラムのための具体的な物事のカップルを含んでいますが、それは理解しにくいSharpSvnの部品を作るべきではありません。)

関連する問題