Pergunta

Como obter mais recente número da revisão usando SharpSVN?

Foi útil?

Solução

A maneira menos onerosa para recuperar a revisão cabeça de um repositório é o comando 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));
}

Outras dicas

Estou verificando a versão mais recente da cópia de trabalho usando SvnWorkingCopyClient:

var workingCopyClient = new SvnWorkingCopyClient();

SvnWorkingCopyVersion version;

workingCopyClient.GetVersion(workingFolder, out version);

A última versão do repositório de trabalho local está então disponível através

long localRev = version.End;

Para um repositório remoto, uso

 var client = new SvnClient();

 SvnInfoEventArgs info;

 client.GetInfo(targetUri, out info);

 long remoteRev = info.Revision;

em seu lugar.

Este é semelhante a usar a ferramenta svnversion a partir da linha de comando. Espero que isso ajude.

Ok, eu descobri-lo por mim:

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

Eu pesquisei também muito, mas a única coisa que estava trabalhando para me a ficar realmente a última revisão foi:

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

as outras soluções são comentadas. Experimente por si mesmo e ver a diferença. . .

Bem, uma rápida pesquisa google me deu isso, e ele funciona (apenas pontos no / trunk / URI):

http://sharpsvn.open.collab.net /ds/viewMessage.do?dsForumId=728&dsMessageId=89318

Esta é uma questão muito antiga, e tem sido respondido bem nas duas primeiras respostas. Ainda assim, na esperança de que poderia ser de alguma ajuda para alguém que eu estou postando o seguinte método C # para ilustrar como não só obter os números de revisão, tanto do repositório e da cópia de trabalho, mas também como teste para situações típicas que podem ser considerado como problemas, por exemplo, num processo automatizado de construção.

  /// <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 não inclui um par de coisas específicas para o programa foi copiado de, mas que não deve fazer as peças SharpSvn difícil de entender.)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top