Question

Comment obtenir le dernier numéro de révision en utilisant SharpSVN?

Était-ce utile?

La solution

La façon la moins coûteuse pour récupérer la révision de la tête d'un référentiel est la commande 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));
}

Autres conseils

Je vérifie la dernière version de la copie de travail en utilisant SvnWorkingCopyClient:

var workingCopyClient = new SvnWorkingCopyClient();

SvnWorkingCopyVersion version;

workingCopyClient.GetVersion(workingFolder, out version);

La dernière version du référentiel de travail local est alors disponible via

long localRev = version.End;

Pour un dépôt distant, utilisez

 var client = new SvnClient();

 SvnInfoEventArgs info;

 client.GetInfo(targetUri, out info);

 long remoteRev = info.Revision;

au lieu.

Ceci est similaire à l'aide de l'outil svnversion de la ligne de commande. Espérons que cela aide.

Ok, je pensais par moi-même:

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

i googlé aussi beaucoup, mais la seule chose qui fonctionnait pour moi de vraiment la dernière révision:

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

les autres solutions sont commentées. Essayez par vous-même et voir la différence. . .

Eh bien, une rapide recherche sur Google m'a donné que, et cela fonctionne (il suffit de pointer au / trunk / URI):

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

Ceci est une question très ancienne, et il a été bien répondu dans les deux premières réponses. Pourtant, dans l'espoir qu'il pourrait être d'une aide à quelqu'un que je poste la méthode C # suivant pour illustrer comment obtenir non seulement les numéros de révision à la fois le dépôt et la copie de travail, mais aussi la façon de tester des situations typiques qui pourraient être considérés comme des problèmes, par exemple dans un processus automatisé de construction.

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

(Ce code inclut deux choses spécifiques pour le programme il a été copié, mais cela ne devrait pas rendre les parties SharpSvn difficiles à comprendre.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top