2009-03-26 6 views

risposta

36

Il modo meno costoso per recuperare la revisione della testina da un repository è il comando Informazioni.

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

questo codice non funziona per me come sotto 'using (Client SvnClient = new SvnClient()) {Informazioni SvnInfoEventArgs; Uri repos = new Uri ("svn: // india01/repository/branches/mybranch1"); client.GetInfo (repos, out info); lblMsg.Visible = true; lblMsg.Text = (string.Format ("L'ultima revisione di {0} è {1}", repos, info.Revision)); } ' Ogni volta che si esegue la mia pagina Web è continua a cercare solo .. qualsiasi soluzione per questo. – picnic4u

+2

Se si desidera la revisione più recente per un determinato percorso (non l'intero repository), è possibile restituire 'info.LastChangeRevision'. – styfle

9

Ok, ho capito da solo:

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

Ho cercato su google anche molto, ma l'unica cosa che stava lavorando per me per ottenere davvero l'ultima revisione è stata:

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

le altre soluzioni sono commentate. Prova da solo e vedi la differenza. . .

+0

Questo comando recupera tutte le revisioni per ottenere un numero di revisione singolo ... Questo è un po 'eccessivo e certamente non il modo più veloce per ottenere le informazioni. –

15

sto controllando la versione più recente della copia di lavoro utilizzando SvnWorkingCopyClient:

var workingCopyClient = new SvnWorkingCopyClient(); 

SvnWorkingCopyVersion version; 

workingCopyClient.GetVersion(workingFolder, out version); 

L'ultima versione del repository di lavoro locale è quindi disponibile attraverso

long localRev = version.End; 

Per un archivio remoto, utilizzare

invece.

Questo è simile all'utilizzo dello strumento svnversion dalla riga di comando. Spero che questo ti aiuti.

0

Questa è una domanda molto vecchia, ed è stata fornita una buona risposta nelle prime due risposte. Tuttavia, nella speranza che possa essere di aiuto a qualcuno, sto postando il seguente metodo C# per illustrare come ottenere non solo i numeri di revisione dal repository e dalla copia di lavoro, ma anche come testare situazioni tipiche che potrebbero essere considerati come problemi, ad esempio in un processo di compilazione automatizzato.

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

(Questo codice include un paio di cose specifiche per il programma è stato copiato da, ma che non dovrebbe fare le parti SharpSvn difficile da capire.)

Problemi correlati