2009-03-26 13 views

Respuesta

36

La forma menos costosa de recuperar la revisión de encabezado de un repositorio es el comando Información.

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

este código no está funcionando para mí como debajo de 'using (Cliente de SvnClient = nuevo SvnClient()) {Información de SvnInfoEventArgs; Uri repos = new Uri ("svn: // india01/repository/branches/mybranch1"); client.GetInfo (repos, salida de información); lblMsg.Visible = verdadero; lblMsg.Text = (string.Format ("La última revisión de {0} es {1}", repos, info.Revision)); } ' cada vez que estoy ejecutando mi página web, sigue buscando solo .. cualquier solución para esto. – picnic4u

+2

Si desea la última revisión para una ruta determinada (no el repositorio completo) puede devolver 'info.LastChangeRevision' en su lugar. – styfle

9

Ok, pensé que por mí mismo:

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

Busqué en Google también mucho, pero la única cosa que fue uno trabajando para que consiga realmente la última revisión fue:

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

las otras soluciones están comentadas. Pruébelo usted mismo y vea la diferencia. . .

+0

Este comando recupera todas las revisiones para obtener un solo número de revisión ... Eso es un poco exagerado y ciertamente no es la forma más rápida de obtener la información. –

15

estoy comprobando la última versión de la copia de trabajo utilizando SvnWorkingCopyClient:

var workingCopyClient = new SvnWorkingCopyClient(); 

SvnWorkingCopyVersion version; 

workingCopyClient.GetVersion(workingFolder, out version); 

La última versión del repositorio de trabajo local es entonces disponible a través

long localRev = version.End; 

caso de un repositorio remoto, utilice

var client = new SvnClient(); 

SvnInfoEventArgs info; 

client.GetInfo(targetUri, out info); 

long remoteRev = info.Revision; 

en su lugar.

Esto es similar al uso de la herramienta svnversion desde la línea de comandos. Espero que esto ayude.

0

Esta es una pregunta muy antigua, y se ha respondido bien en las dos respuestas principales. Aún así, con la esperanza de que pueda ser de alguna ayuda para alguien, estoy publicando el siguiente método C# para ilustrar cómo obtener no solo los números de revisión tanto del repositorio como de la copia de trabajo, sino también cómo probar situaciones típicas que podrían ser considerado como un problema, por ejemplo, en un proceso de compilación automatizado.

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

(Este código incluye un par de cosas específicas para el programa fue copiado, pero eso no debe hacer que las partes SharpSvn difícil de entender.)

Cuestiones relacionadas