2009-03-26 14 views

Odpowiedz

36

Najtańszym sposobem pobrania wersji głównej z repozytorium jest polecenie 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

kod ten nie działa na mnie jak poniżej 'przy użyciu (klient SvnClient = nowy SvnClient()) {SvnInfoEventArgs info; Uri repos = new Uri ("svn: // india01/repository/branches/mybranch1"); client.GetInfo (repos, out info); lblMsg.Visible = true; lblMsg.Text = (string.Format ("Ostatnia wersja {0} to {1}", repo, info.Revision)); } ' za każdym razem, gdy uruchomię moją stronę, ciągle szukam .. dowolne rozwiązanie tego problemu. – picnic4u

+2

Jeśli chcesz najnowszą wersję dla danej ścieżki (nie całego repozytorium), możesz zamiast tego zwrócić 'info.LastChangeRevision'. – styfle

9

Ok, wyobraziłem go sobie:

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

google też dużo, ale jedyną rzeczą, która pracowała dla mnie, aby uzyskać naprawdę ostatni przegląd był:

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

inne rozwiązania są komentarzem. Spróbuj sam i zobacz różnicę. . .

+0

To polecenie pobiera wszystkie poprawki w celu uzyskania jednego numeru wersji ... To jest trochę przesady i na pewno nie jest to najszybszy sposób na uzyskanie informacji. –

15

ja sprawdzając najnowszą wersję kopii roboczej przy użyciu SvnWorkingCopyClient:

var workingCopyClient = new SvnWorkingCopyClient(); 

SvnWorkingCopyVersion version; 

workingCopyClient.GetVersion(workingFolder, out version); 

Najnowsza wersja lokalnym repozytorium roboczy jest wtedy dostępny poprzez

long localRev = version.End; 

Dla zdalnego repozytorium, należy

var client = new SvnClient(); 

SvnInfoEventArgs info; 

client.GetInfo(targetUri, out info); 

long remoteRev = info.Revision; 

zamiast tego.

Jest to podobne do używania narzędzia svnversion z wiersza poleceń. Mam nadzieję że to pomoże.

0

To bardzo stare pytanie, na które dobrze odpowiedziano w dwóch pierwszych odpowiedziach. Mimo to, w nadziei, że może to być pomocne dla kogoś, publikuję następującą metodę C#, aby zilustrować, jak nie tylko uzyskać numery wersji z repozytorium i kopii roboczej, ale także jak przetestować typowe sytuacje, które mogą uważane są za problemy, na przykład w zautomatyzowanym procesie budowania.

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

(Kod ten ma zawierać kilka rzeczy specyficznych dla programu, który został skopiowany z, ale to nie powinno stanowić części SharpSvn trudne do zrozumienia.)

Powiązane problemy